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 :(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.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 :(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 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(options)
You can use this API to broadcast a fully signed transaction. Please note that rawtx and PSBT are completely different formats.
Parameters
options - Object:
rawtx - string: rawtx to pushReturns
Promise - string: txidExample
try {
let txid = await window.unisat.pushTx({
rawtx: "0200000000010135bd7d...",
});
console.log(txid);
} catch (e) {
console.log(e);
}
Additional Note