Sign and broadcast Transaction

BitPocket Wallet provides functionality for signing individual PSBTs, batch signing multiple PSBTs, and broadcasting transactions.

Method

signPsbt

window.bitpocket.unisat.signPsbt(psbtHex[, options])

Sign PSBT

This method will traverse all inputs that match the current address to sign.

Parameters

  • psbtHex - string: the hex string of psbt to sign
  • options
    • autoFinalized - boolean: whether finalize psbt after signing, default is true
    • toSignInputs - array:
      • index - number: which input to sign
      • address - string: (at least specify either an address or a publicKey) Which corresponding private key to use for signing
      • publicKey - string: (at least specify either an address or a publicKey) Which corresponding private key to use for signing
      • sighashTypes - number[]: (optionals) sighashTypes
      • disableTweakSigner - boolean :(optionals) Default value is false. Setting it true allows the use of the original private key when signing taproot inputs. (deprecated)
      • useTweakedSigner - boolean :(optionals) . By setting useTweakedSigner, you can forcibly decide whether or not to use tweakedSigner. It has a higher priority than disableTweakSigner.

Returns

Promise - string: the hex string of signed psbt

Example

try {
  let res = await window.bitpocket.unisat.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);
}

window.bitpocket.unisat.signPsbt("xxxxxxxx", {
  toSignInputs: [{ index: 0, publicKey: "xxxxxx", disableTweakSigner: true }],
  autoFinalized: false,
});

Additional Note


pushPsbt

window.bitpocket.unisat.pushPsbt(psbtHex)

You can use this API to broadcast a fully signed PSBT.

Parameters

  • psbtHex - string: the hex string of psbt to push

Returns

  • Promise - string: txid

Example

try {
  let res = await window.bitpocket.unisat.pushPsbt("70736274ff01007d....");
  console.log(res);
} catch (e) {
  console.log(e);
}

results matching ""

    No results matching ""