Request the signature and broadcast of a Partially Signed Bitcoin Transaction (PSBT)
Method name
signPsbt
Parameters
Parameter
Description
Required
Type
hex
Hex of PSBT payload for signing
string
allowedSighash
Sighash types allowed for signing and finalizing inputs (defaults to type ALL)
SignatureHash[]
signAtIndex
Input index(es) that should be signed (defaults to sign all inputs)
number | number[]
network
Network for signing: mainnet, testnet, signet, sbtcDevenv or devnet
string
account
Index of account for signing (defaults to active account)
uint
broadcast
Whether to broadcast upon signing (default false)
Example request
Sign PSBT
interfaceSignPsbtRequestParams { hex:string; allowedSighash?:SignatureHash[]; signAtIndex?:number|number[]; network?:NetworkModes; // default is user's current network account?:number; // default is user's current account broadcast?:boolean; // default is false - finalize/broadcast tx}constrequestParams:SignPsbtRequestParams= { ...params };constresponse=awaitwindow.LeatherProvider.request('signPsbt', requestParams);
Broadcast PSBT
Our API returns a PSBT back to the app, with the newly applied signatures. If your use-case is to spend the transaction immediately, you'll first need to finalize it, then broadcast it to the network.
See this example below how to extract a signed transaction from the PSBT
Helper functions for Native SegWit PsbtRequestOptions
// Example request options for Native SegWitfunctionbuildNativeSegwitPsbtRequest(pubKey:Uint8Array):PsbtRequestOptions {// SegWit pubKey used here is provided through auth responseconstp2wpkh=btc.p2wpkh(pubKey, bitcoinTestnet);consttx=newbtc.Transaction();// Example inputs with included witnesstx.addInput({ index:0, txid:'15f34b3bd2aab555a003cd1c6959ac09b36239c6af1cb16ff8198cef64f8db9c', witnessUtxo: { amount:BigInt(1000), script:p2wpkh.script, }, });tx.addInput({ index:1, txid:'dca5179afaa63eae112d8a97794de2d30dd823315bcabe6d8b8a6b98e3567705', witnessUtxo: { amount:BigInt(2000), script:p2wpkh.script, }, });// Add outputs and/or other psbt data...constpsbt=tx.toPSBT();// This example is choosing to sign all inputs bc no index(es) are providedreturn { hex:bytesToHex(psbt) };}
Helper functions for Taproot PsbtRequestOptions
// Similar example request options for TaprootfunctionbuildTaprootPsbtRequest(pubKey:Uint8Array):PsbtRequestOptions {// Taproot pubKey used here is provided through auth responseconstpayment=getTaprootPayment(pubKey);consttx=newbtc.Transaction();tx.addInput({ index:0, tapInternalKey:payment.tapInternalKey, txid:'15f34b3bd2aab555a003cd1c6959ac09b36239c6af1cb16ff8198cef64f8db9c', witnessUtxo: { amount:BigInt(1000), script:payment.script, }, });tx.addInput({ index:1, tapInternalKey:payment.tapInternalKey, txid:'dca5179afaa63eae112d8a97794de2d30dd823315bcabe6d8b8a6b98e3567705', witnessUtxo: { amount:BigInt(2000), script:payment.script, }, });// Add outputs and/or other psbt data...constpsbt=tx.toPSBT();return { hex:bytesToHex(psbt) };}
Custom scripts
For more complex PSBTs, such as those using custom Bitcoin scripts, we recommend you read the supporting documentation of the @scure/btc-signer library.