Connect to Extension 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.
Note

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",
          },
      ],
  });
  • 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
Note

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: 341475,
      address: "tb1q8h8....mjxzny",
      privateKey: "0s79......ldjejke",
      publicKey: "tb1q8h8....mjxzny",
      bip32Derivation: [
          {
              "masterFingerprint": "a22e8e32",
              "pubkey": "tb1q8h8....mjxzny",
              "path": "m/49'/0'/0'/0/0",
          },
      ],
  });
  • 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 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

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);
}