UniSat Wallet provides functionality for signing individual PSBTs, batch signing multiple PSBTs, and broadcasting transactions.
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 signautoFinalized - boolean: whether finalize psbt after signing, default is truetoSignInputs - array:
index - number: which input to signaddress - string: (at least specify either an address or a publicKey) Which corresponding private key to use for signingpublicKey - string: (at least specify either an address or a publicKey) Which corresponding private key to use for signingsighashTypes - number[]: (optionals) sighashTypesdisableTweakSigner - boolean: (optional, deprecated) Default false. Setting true uses the original private key for taproot inputs. Use useTweakedSigner instead.useTweakedSigner - boolean: (optional) Explicitly control whether to use the tweaked signer. Takes priority over disableTweakSigner.tapLeafHashToSign - string: (optional) Hex-encoded tapleaf hash. When specified, only the input with this tapleaf hash will be signed (used for script-path spending).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
unisat.signPsbts(psbtHexs[, options])
Sign Multiple PSBTs at once
This method will traverse all inputs that match the current address to sign.
Parameters
psbtHexs - string[]: the hex strings of psbt to signoptions - object[]: the options of signing psbt
autoFinalized - boolean: whether finalize psbt after signing, default is truetoSignInputs - array:
index - number: which input to signaddress - string: (at least specify either an address or a publicKey) Which corresponding private key to use for signingpublicKey - string: (at least specify either an address or a publicKey) Which corresponding private key to use for signingsighashTypes - number[]: (optionals) sighashTypesuseTweakedSigner - boolean: (optional) Explicitly control whether to use the tweaked signer. Takes priority over disableTweakSigner.tapLeafHashToSign - string: (optional) Hex-encoded tapleaf hash for script-path spending.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
unisat.pushPsbt(psbtHex)
You can use this API to broadcast a fully signed PSBT.
Parameters
psbtHex - string: the hex string of psbt to pushReturns
Promise - string: txidExample
try {
let res = await window.unisat.pushPsbt("70736274ff01007d....");
console.log(res);
} catch (e) {
console.log(e);
}
unisat.pushTx(rawtx)
You can use this API to broadcast a fully signed transaction. Please note that rawtx and PSBT are completely different formats.
Parameters
rawtx - string: the raw transaction hex to broadcastReturns
Promise - string: txidExample
try {
let txid = await window.unisat.pushTx("0200000000010135bd7d...");
console.log(txid);
} catch (e) {
console.log(e);
}
Additional Note