The OKX injected provider API is a JavaScript API that OKX injects into websites visited by our users. Your DApp can use this API to request users' accounts, read data from blockchains users are connected to, and help users sign messages and transactions.
window.okxwallet.stacks.connect()
Description
Connect to OKX Wallet by calling window.okxwallet.stacks.connect()
When window.okxwallet.stacks.connect()
has been successfully called, the OKX Wallet connection page will be displayed. You decide whether to connect to the current DApp or not. If you agree to connect, the address
and publicKey
key will be returned.
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)
Parameters
contract_call
Return value
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);
}
Parameters
token_transfer
Return value
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)
Parameters
Return value
try {
const data = {
message: '1234'
};
const {publicKey, signature} = await window.okxwallet.stacks.signMessage(data);
console.location({publicKey, signature});
} catch (error) {
console.log(error);
}