欧易 Injected providers API 是一个 JavaScript API,欧易将其注入用户访问的网站。您的 DApp 可以使用此 API 请求用户帐户,从用户连接的区块链读取数据,帮助用户签署消息和交易。
window.okxwallet.stacks.connect()
描述
通过调用 window.okxwallet.stacks.connect()
连接欧易 Web3 钱包。
当成功调用 window.okxwallet.stacks.connect()
,将会唤起欧易 Web3 钱包连接钱包页面,用户可以决定是否连接当前 DApp,如果用户同意将会返回地址 (address
) 和公钥 (public key
)。
try {
const response = await window.okxwallet.stacks.connect();
console.log(response);
// { address: string, publicKey: string }
} catch (error) {
console.log(error);
// { code: 4001, message: "User rejected the request."}
}
window.okxwallet.stacks.signTransaction(transaction)
参数
contract_call
返回值
try {
const transaction = {
"stxAddress": "",
"txType": "contract_call",
"contractName": "amm-swap-pool-v1-1",
"contractAddress": "SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9",
"functionName": "swap-helper",
"functionArgs": [
"0616e685b016b3b6cd9ebf35f38e5ae29392e2acd51d0a746f6b656e2d77737478",
"0616e685b016b3b6cd9ebf35f38e5ae29392e2acd51d176167653030302d676f7665726e616e63652d746f6b656e",
"0100000000000000000000000005f5e100",
"01000000000000000000000000000f4240",
"0a010000000000000000000000000078b854"
],
"postConditionMode": 2,
"postConditions": [
"000216c03b5520cf3a0bd270d8e41e5e19a464aef6294c010000000000002710",
"010316e685b016b3b6cd9ebf35f38e5ae29392e2acd51d0f616c65782d7661756c742d76312d3116e685b016b3b6cd9ebf35f38e5ae29392e2acd51d176167653030302d676f7665726e616e63652d746f6b656e04616c657803000000000078b854"
],
"anchorMode": 3,
};
const {txHash, signature} = await window.okxwallet.stacks.signTransaction(transaction);
console.location({txHash, signature});
} catch (error) {
console.log(error);
}
window.okxwallet.stacks.signTransaction(transaction)
参数
token_transfer
返回值
try {
const transaction = {
stxAddress: '',
txType: 'token_transfer',
recipient: '',
amount: '10000',
memo: 'test'
};
const {txHash, signature} = await window.okxwallet.stacks.signTransaction(transaction);
console.location({txHash, signature});
} catch (error) {
console.log(error);
}
window.okxwallet.stacks.signMessage(data)
参数
返回值
try {
const data = {
message: '1234'
};
const {publicKey, signature} = await window.okxwallet.stacks.signMessage(data);
console.location({publicKey, signature});
} catch (error) {
console.log(error);
}