The OKX Injected Providers API is based on a JavaScript model and is embedded by OKX into the websites users access. DApps projects can utilize this API to request user account information, retrieve data from the connected blockchain, and assist users in signing messages and transactions.
okxwallet.bitcoin.connect()
Description
Connect wallet
Parameters
None
Return value
Example
const result = await okxwallet.bitcoin.connect()
// example
{
address: 'bc1pwqye6x35g2n6xpwalywhpsvsu39k3l6086cvdgqazlw9mz2meansz9knaq',
publicKey: '4a627f388196639041ce226c0229560127ef9a5a39d4885123cd82dc82d8b497'
}
Description
okxwallet.bitcoin.requestAccounts()
Connect the current account
Parameters
None
Return value
Example
try {
let accounts = await okxwallet.bitcoin.requestAccounts();
console.log('connect success', accounts);
} catch (e) {
console.log('connect failed');
}
// example
['tb1qrn7tvhdf6wnh790384ahj56u0xaa0kqgautnnz'];
okxwallet.bitcoin.getAccounts()
Description
Get the address of current account
Parameters
None
Return value
Example
try {
let res = await okxwallet.bitcoin.getAccounts();
console.log(res);
} catch (e) {
console.log(e);
}
// example
['tb1qrn7tvhdf6wnh790384ahj56u0xaa0kqgautnnz'];
okxwallet.bitcoin.getNetwork()
Description
Get network
Parameters
None
Return value
Example
try {
let res = await okxwallet.bitcoin.getNetwork();
console.log(res);
} catch (e) {
console.log(e);
}
// example
livenet;
okxwallet.bitcoin.getPublicKey()
Description
Get the public key of current account
Parameters
None
Return value
Example
try {
let res = await okxwallet.bitcoin.getPublicKey();
console.log(res)
} catch (e) {
console.log(e);
}
// example
03cbaedc26f03fd3ba02fc936f338e980c9e2172c5e23128877ed46827e935296f
okxwallet.bitcoin.getBalance()
Description
Get BTC balance
Parameters
None
Return value
Example
try {
let res = await okxwallet.bitcoin.getBalance();
console.log(res)
} catch (e) {
console.log(e);
}
// example
{
"confirmed":0,
"unconfirmed":100000,
"total":100000
}
okxwallet.bitcoin.getInscriptions()
Description
List inscriptions of current account
Parameters
Return value
Example
try {
let res = await okxwallet.bitcoin.getInscriptions(0, 20);
console.log(res)
} catch (e) {
console.log(e);
}
// example
{
"total":10,
"list":[
{
inscriptionId: '6037b17df2f48cf87f6b6e6ff89af416f6f21dd3d3bc9f1832fb1ff560037531i0',
inscriptionNumber: 55878989,
address: 'bc1q8h8s4zd9y0lkrx334aqnj4ykqs220ss735a3gh',
outputValue: 546,
contentLength: 53,
contentType: 'text/plain',
timestamp: 1705406294,
location: '6037b17df2f48cf87f6b6e6ff89af416f6f21dd3d3bc9f1832fb1ff560037531:0:0',
output: '6037b17df2f48cf87f6b6e6ff89af416f6f21dd3d3bc9f1832fb1ff560037531:0',
offset: 0,
genesisTransaction: '02c9eae52923fdb21fe16ee9eb873c7d66fe412a61b75147451d8a47d089def4'
}
]
}
okxwallet.bitcoin.sendBitcoin(toAddress, satoshis, options)
Description
Send BTC
Parameters
Return value
Example
try {
let txid = await okxwallet.bitcoin.sendBitcoin(
'tb1qrn7tvhdf6wnh790384ahj56u0xaa0kqgautnnz',
1000
);
console.log(txid);
} catch (e) {
console.log(e);
}
okxwallet.bitcoin.send({ from, to, value, satBytes })
Description
Send BTC (supports memo parameter)
Parameters
Return value
Example
const result = await window.okxwallet.bitcoin.send({
from: 'bc1p4k9ghlrynzuum080a4zk6e2my8kjzfhptr5747afzrn7xmmdtj6sgrhd0m',
to: 'bc1plklsxq4wtv44dv8nm49fj0gh0zm9zxewm6ayzahrxc8yqtennc2s9udmcd',
value: '0.000012',
});
// example
{
txhash: 'd153136cd74512b69d24c68b2d2c715c3629e607540c3f6cd3acc1140ca9bf57';
}
okxwallet.bitcoin.sendInscription(address, inscriptionId, options)
Description
Send inscription
Parameters
address - string: the receiver address
inscriptionId - string: Inscriptions ID + protocol, default is Ordinals NFT if no transmission protocol, currently only support Ordinals and Atomicals Association
Protocol | Description |
---|---|
Ordinals | Ordinals Protocol |
Atomicals | Atomicals Protocol |
options - object: (optional)
Return value
Example
// send Ordinals NFT
try {
let txid = await okxwallet.bitcoin.sendInscription(
'tb1q8h8s4zd9y0lkrx334aqnj4ykqs220ss7mjxzny',
'e9b86a063d78cc8a1ed17d291703bcc95bcd521e087ab0c7f1621c9c607def1ai0',
{ feeRate: 15 }
);
console.log(
'send Ordinal NFT to tb1q8h8s4zd9y0lkrx334aqnj4ykqs220ss7mjxzny',
{ txid }
);
} catch (e) {
console.log(e);
}
// send Atomicals NFT
try {
let txid = await okxwallet.bitcoin.sendInscription(
'tb1q8h8s4zd9y0lkrx334aqnj4ykqs220ss7mjxzny',
'ab12349dca49643fcc55c8e6a685ad0481047139c5b1af5af85387973fc7ceafi0-Atomicals',
{ feeRate: 15 }
);
console.log(
'send Atomicals NFT to tb1q8h8s4zd9y0lkrx334aqnj4ykqs220ss7mjxzny',
{ txid }
);
} catch (e) {
console.log(e);
}
okxwallet.bitcoin.transferNft({ from, to, data })
Description
Send inscription
The transferNft
method supports batch transfers, while the sendInscription
method only supports individual transfers
Parameters
from - string: the BTC address of the currently connected wallet
to - string: addresses that accept NFTs or BRC-20 tokens
data-string | string[]: indicates the sent NFT tokenId + protocol. If the NFT is an array, multiple NFT are transferred in batches. If no transmission protocol is used, the default NFT is Ordinals NFT. Currently, only Ordinals and Atomicals are supported
Protocol | Description |
---|---|
Ordinals | Ordinals Protocol |
Atomicals | Atomicals Protocol |
Return value
Example
// send Ordinals NFT
try {
let res = await window.okxwallet.bitcoin.transferNft({
from: 'bc1p8qfrmxdlmynr076uu28vlszxavwujwe7dus0r8y9thrnp5lgfh6qu2ctrr',
to: 'bc1p8qfrmxdlmynr076uu28vlszxavwujwe7dus0r8y9thrnp5lgfh6qu2ctrr',
data: [
'2f285ba4c457c98c35dcb008114b96cee7c957f00a6993690efb231f91ccc2d9i0-Ordinals',
'2f2532f59d6e46931bc84e496cc6b45f87966b149b85ed3199265cb845550d58i0-Ordinals',
],
});
console.log(res);
} catch (e) {
console.log(e);
}
// example
{
txhash: 'df409c3ce3c4d7d840b681fab8a3a5b8e32b1600636cc5409d84d2c06365a5fc';
}
// send Atomicals NFT
try {
let res = await window.okxwallet.bitcoin.transferNft({
from: 'bc1p8qfrmxdlmynr076uu28vlszxavwujwe7dus0r8y9thrnp5lgfh6qu2ctrr',
to: 'bc1p8qfrmxdlmynr076uu28vlszxavwujwe7dus0r8y9thrnp5lgfh6qu2ctrr',
data: [
'ab12349dca49643fcc55c8e6a685ad0481047139c5b1af5af85387973fc7ceafi0-Atomicals',
],
});
console.log(res);
} catch (e) {
console.log(e);
}
// example
{
txhash: 'df409c3ce3c4d7d840b681fab8a3a5b8e32b1600636cc5409d84d2c06365a5fc';
}
okxwallet.bitcoin.signMessage(signStr[, type])
Description
Sign message
Parameters
Return value
Example
const signStr = 'need sign string';
const result = await window.okxwallet.bitcoin.signMessage(signStr, 'ecdsa')
// example
INg2ZeG8b6GsiYLiWeQQpvmfFHqCt3zC6ocdlN9ZRQLhSFZdGhgYWF8ipar1wqJtYufxzSYiZm5kdlAcnxgZWQU=
okxwallet.bitcoin.pushTx(rawTx)
Description
Push transaction
Parameters
Return value
Example
try {
let txid = await okxwallet.bitcoin.pushTx('0200000000010135bd7d...');
console.log(txid);
} catch (e) {
console.log(e);
}
okxwallet.bitcoin.splitUtxo({ from, amount })
Description
Spliting UTXO and initializing OKX Wallet
Splitting is required by the signature algorithm
Parameters
Return value
{utxos: array}
: UTXOs and signaturesExample
try {
let { utxos } = await window.okxwallet.bitcoin.splitUtxo({
from: 'bc1pkrym02ck30phct287l0rktjjjnapavkl2qhsy78aeeeuk3qaaulqh90v6s',
});
console.log(utxos);
} catch (e) {
console.log(e);
}
// example
{
utxos: [
{
txId: '1e0f92720ef34ab75eefc5d691b551fb2f783eac61503a69cdf63eb7305d2306',
vOut: 0,
amount: 546,
rawTransaction: 'xxxx',
},
{
txId: '1e0f92720ef34ab75eefc5d691b551fb2f783eac61503a69cdf63eb7305d2306',
vOut: 1,
amount: 546,
rawTransaction: 'xxxx',
},
];
}
okxwallet.bitcoin.inscribe({ type, from, tick, tid })
Description
Inscribe transferable BRC-20
Parameters
type - number: transaction types. Details are shown in the table below.
Type | Description |
---|---|
51 | Default value. Inscription of a BRC-20 transfer |
from - string: the BTC address of the currently connected wallet
tick - string: BRC-20 token name (from on-chain)
Return value
Example
try {
let txid = await okxwallet.bitcoin.inscribe({
from: 'bc1pkrym02ck30phct287l0rktjjjnapavkl2qhsy78aeeeuk3qaaulqh90v6s',
tick: 'ordi',
});
console.log(txid);
} catch (e) {
console.log(e);
}
okxwallet.bitcoin.mint({ type, from, inscriptions })
Description
Universal inscriptions that support the Ordinal protocol
This method supports batch inscribing
Parameters
type - number: the type of inscribed transaction to be sent. Please refer to the table below for details.
Type | Description |
---|---|
60 | BRC-20 deploy inscription |
50 | BRC-20 mint inscription |
51 | BRC-20 transfer inscription |
62 | Image inscription. The image needs to be converted into a hexadecimal string representation of the image byte stream. |
61 | Plain text |
from - string: the BTC address of the currently connected wallet
inscriptions - object[]: the array of inscriptions where each array item is an object type with its respective fields and meanings as shown in the table below:
Field | Type | Default | Description |
---|---|---|---|
contentType | string | "text/plain;charset=utf-8" | The type of content to be inscribed, represented by a MIME type value. As for the Ordinals protocol specifications, please refer to: https://docs.ordinals.com/inscriptions.html for details. |
body | string | No | The content being inscribed |
the contentType and body parameters passed in for different inscription types:
Inscription Type | Content Type | Body |
---|---|---|
image inscription | eg. "image/png", "image/jpeg" | The image needs to be converted into a hexadecimal string representation of the image byte stream |
BRC-20 | "text/plain;charset=utf-8" | Simply convert it to a string using JSON.stringify |
plain text | "text/plain;charset=utf-8" | Directly pass in plain text |
Return value
Example
okxwallet.bitcoin.mint({
type: 61,
from: 'bc1p4k9ghlrynzuum080a4zk6e2my8kjzfhptr5747afzrn7xmmdtj6sgrhd0m',
inscriptions: [{
contentType: 'text/plain;charset=utf-8',
body: 'hello'
}, {
contentType: 'text/plain;charset=utf-8',
body: 'world'
}]
})
// response
{
"commitAddrs": [
"bc1p9trqtf68gfeq3f3hlktaapp0eapufh02ly8dr6swfwffflvncncqwvtuen",
"bc1p5ttl7q2mpvfhjq3wqffka4c05sv5jcfphcl5qeuj0pmsx7evfhcqhm60rk"
],
"commitTx": "453e126346bbaaef0aaaa208acd3426cd14a39f825bd76cb8d9892957e2a5bda",
"revealTxs": [
"526ff04e4ba34617ee28826412bdc8e22484890635320f880c5ec50f10d6b189",
"0f65f79456a59b3e0cd4ef00e279d0d6da57582e114eafbada95b51759a845b2"
],
"commitTxFee": 1379,
"revealTxFees": [
973,
973
],
feeRate: 80,
size: 546,
}
okxwallet.bitcoin.signPsbt(psbtHex[, options])
Description
Signing psbt: this will traverse all inputs that match the current address to sign.
Parameters
When you generate the psbt (string) to be signed, you need to add a public key for every input of the psbt if the input uses a Taproot address.
Example: Refer to txInput and publicKey below.
const txInputs: utxoInput[] = [];
txInputs.push({
txId: "1e0f92720ef34ab75eefc5d691b551fb2f783eac61503a69cdf63eb7305d2306",
vOut: 2,
amount: 341474,
address: "tb1q8h8....mjxzny",
privateKey: "0s79......ldjejke",
publicKey: "tb1q8h8....mjxzny",
bip32Derivation: [
{
"masterFingerprint": "a22e8e32",
"pubkey": "tb1q8h8....mjxzny",
"path": "m/49'/0'/0'/0/0",
},
],
});
Return value
Example
try {
let res = await okxwallet.bitcoin.signPsbt('70736274ff01007d....', {
autoFinalized: false,
toSignInputs: [
{
index: 0,
address: 'tb1q8h8....mjxzny',
},
{
index: 1,
publicKey: 'tb1q8h8....mjxzny',
sighashTypes: [1],
},
{
index: 2,
publicKey: '02062...8779693f',
},
],
});
console.log(res);
} catch (e) {
console.log(e);
}
okxwallet.bitcoin.signPsbt('xxxxxxxx', {
toSignInputs: [{ index: 0, publicKey: 'xxxxxx', disableTweakSigner: true }],
autoFinalized: false,
});
okxwallet.bitcoin.signPsbts(psbtHexs[, options])
Description
Signing psbts: this will traverse all inputs that match the current address to sign.
Parameters
When you generate the psbt (string) to be signed, you need to add a public key for every input of the psbt if the input uses a Taproot address.
Example: Refer to txInput and publicKey below.
const txInputs: utxoInput[] = [];
txInputs.push({
txId: "1e0f92720ef34ab75eefc5d691b551fb2f783eac61503a69cdf63eb7305d2306",
vOut: 2,
amount: 341474,
address: "tb1q8h8....mjxzny",
privateKey: "0s79......ldjejke",
publicKey: "tb1q8h8....mjxzny",
bip32Derivation: [
{
"masterFingerprint": "a22e8e32",
"pubkey": "tb1q8h8....mjxzny",
"path": "m/49'/0'/0'/0/0",
},
],
});
Return value
Example
try {
let res = await okxwallet.bitcoin.signPsbts([
'70736274ff01007d...',
'70736274ff01007d...',
]);
console.log(res);
} catch (e) {
console.log(e);
}
okxwallet.bitcoin.pushPsbt(psbtHex)
Description
Push psbt transaction
Parameters
Return value
Example
try {
let res = await okxwallet.bitcoin.pushPsbt('70736274ff01007d....');
console.log(res);
} catch (e) {
console.log(e);
}
okxwallet.bitcoin.sendPsbt(txs, from)
Description
Push psbt transaction
sendPsbt
method supports batch on-chain transactions, while the pushPsbt
method only supports individual on-chain transactions.sendPsbt
method supports the inclusion of the type
parameter, providing more accurate representation of transaction history within the wallet. On the other hand, transactions pushed to the chain via the pushPsbt
method may have a simpler representation in the transaction history.Parameters
Type | Description |
---|---|
52 | Send BRC-20 |
20 | Send NFT |
Return value
Example
okxwallet.bitcoin.sendPsbt(
[
{
itemId: 'xxxxx0', //Batch unique identification, no duplicates within multiple transactions
signedTx: '70736274ff01007d....', // Signature string
type: 52, // BRC-20 52 or NFT 20
extJson: {
//Split utxo transactions, not transmitted
// NFTID
inscription:
'885441055c7bb5d1c54863e33f5c3a06e5a14cc4749cb61a9b3ff1dbe52a5bbbi0',
},
},
{
itemId: 'xxxxx1', //Batch unique identifier
signedTx: '70736274ff01007d....', // Signature string or PSBT to be linked
type: 52, // BRC-20 52 or NFT 20
dependItemId: ['xxxxx0 '], //The dependent transaction itemId. If there is no dependency, this field may not be passed
extJson: {
// NFTID
inscription:
'885441055c7bb5d1c54863e33f5c3a06e5a14cc4749cb61a9b3ff1dbe52a5bbbi0',
},
},
],
from
)[
// response
({ xxxxx0: 'txId1' }, { xxxxx1: 'txId2' }) //Failure txId returns null
];
Description
OKX Wallet allows you to seamlessly manage multiple accounts from a single extension or mobile application. Whenever you switch accounts, OKX Wallet will send an accountChanged
event.
If you switch accounts while still connected to the application, and if the new account has placed the application on the allowlist, you will remain connected and OKX Wallet will pass the public key of the new account:
Usage
window.okxwallet.bitcoin.on('accountChanged', (addressInfo) => {
console.log(addressInfo);
// example
{
"address": "bc1pwqye6x35g2n6xpwalywhpsvsu39k3l6086cvdgqazlw9mz2meansz9knaq",
"publicKey": "4a627f388196639041ce226c0229560127ef9a5a39d4885123cd82dc82d8b497",
"compressedPublicKey": "034a627f388196639041ce226c0229560127ef9a5a39d4885123cd82dc82d8b497"
}
});
Description
The accountsChanged will be emitted whenever the user's exposed account address changes.
Usage
window.okxwallet.bitcoin.on('accountsChanged', (accounts) => {
console.log(accounts)[
// example
'tb1qrn7tvhdf6wnh790384ahj56u0xaa0kqgautnnz'
];
});