Connect DApp to OKX Wallet
Provider API (Testnet)

Provider API (Testnet)#

What is injected provider API (Testnet) ?#

The OKX Injected Providers API (Testnet) is based on a JavaScript model embedded by OKX into user-accessed websites. DApp projects can use this API to request your account information, read data from the blockchain to which you are connected, and help you in signing messages and transactions.

connect#

okxwallet.bitcoinTestnet.connect()

Description

Connect wallet

Parameters

none

Return value

  • Promise - object
    • address - string: address of current account
    • publicKey - string: public key of current account

Example

const result = await okxwallet.bitcoinTestnet.connect()
// example
{
  address: 'bc1pwqye6x35g2n6xpwalywhpsvsu39k3l6086cvdgqazlw9mz2meansz9knaq',
  publicKey: '4a627f388196639041ce226c0229560127ef9a5a39d4885123cd82dc82d8b497'
}

signMessage#

okxwallet.bitcoinTestnet.signMessage(signStr[, type])

Description

Sign message

Parameters

  • signStr - string: requires signed data
  • type - string: (optional) “ecdsa” | “bip322-simple”. The default value is “ecdsa”

Return value

  • Promise - string: the signing result

Example

const signStr = 'need sign string';
const result = await window.okxwallet.bitcoinTestnet.signMessage(signStr, 'ecdsa')
// example
INg2ZeG8b6GsiYLiWeQQpvmfFHqCt3zC6ocdlN9ZRQLhSFZdGhgYWF8ipar1wqJtYufxzSYiZm5kdlAcnxgZWQU=

signPsbt#

okxwallet.bitcoinTestnet.signPsbt(psbtHex[, options])

Description

Signing psbt: this will traverse all inputs that match the current address to sign.

Parameters

  • psbtHex - string: hexadecimal string representation of the partially signed bitcoin transaction (PSBT) that needs to be signed.
  • options
    • autoFinalized - boolean: whether to finalize psbt after signing — the default is true
    • toSignInputs - array:
      • index - number: which input to sign
      • address - string: (at least specify either an address or a public key) which corresponding private key to use for signing
      • publicKey - string: (at least specify either an address or a public key) which corresponding private key to use for signing
      • sighashTypes - number[]: (optional) sighashTypes
      • disableTweakSigner - boolean :(optional) when signing and unlocking Taproot addresses, the tweakSigner is used by default for signature generation. Enabling this allows for signing with the original private key.

Return value

  • Promise - string: the hex string of the signed psbt

Example

try {
  let res = await okxwallet.bitcoinTestnet.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.bitcoinTestnet.signPsbt('xxxxxxxx', {
  toSignInputs: [{ index: 0, publicKey: 'xxxxxx', disableTweakSigner: true }],
  autoFinalized: false,
});

signPsbts#

okxwallet.bitcoinTestnet.signPsbts(psbtHexs[, options])

Description

Signing psbts: this will traverse all inputs that match the current address to sign.

Parameters

  • psbtHexs - string[]: the hex strings of psbts to sign
  • options - object[]: the options of signing psbts
    • autoFinalized - boolean: whether to finalize psbts after signing — the default is true
    • toSignInputs - array:
      • index - number: which input to sign
      • address - string: (at least specify either an address or a private key) which corresponding private key to use for signing
      • publicKey - string: (at least specify either an address or a private key) which corresponding private key to use for signing
      • sighashTypes - number[]: (optional) sighashTypes

Return value

  • Promise - string[]: the hex strings of the signed psbts

Example

try {
  let res = await okxwallet.bitcoinTestnet.signPsbts([
    '70736274ff01007d...',
    '70736274ff01007d...',
  ]);
  console.log(res);
} catch (e) {
  console.log(e);
}