unisat-dev-docs

Sign and broadcast Transaction

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

Method

signPsbt

unisat.signPsbt(psbtHex[, options])

Sign PSBT

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

Parameters

Returns

Promise - string: the hex string of signed psbt

Example

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

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

Additional Note


signPsbts

unisat.signPsbts(psbtHexs[, options])

Sign Multiple PSBTs at once

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

Parameters

Returns

Promise - string[]: the hex strings of signed psbt

Example

try {
  let res = await window.unisat.signPsbts([
    "70736274ff01007d...",
    "70736274ff01007d...",
  ]);
  console.log(res);
} catch (e) {
  console.log(e);
}

Additional Note

pushPsbt

unisat.pushPsbt(psbtHex)

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

Parameters

Returns

Example

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

pushTx

unisat.pushTx(options)

You can use this API to broadcast a fully signed transaction. Please note that rawtx and PSBT are completely different formats.

Parameters

Returns

Example

try {
  let txid = await window.unisat.pushTx({
    rawtx: "0200000000010135bd7d...",
  });
  console.log(txid);
} catch (e) {
  console.log(e);
}

Additional Note