Sign Transaction
To request signing of a PSBT, you can use the
signTransaction
function.The PSBT to be signed must be base64 encoded. You can use any Bitcoin library to construct this transaction. See examples using
@scure/btc-signer
here: Creating PSBTsimport { signTransaction } from 'sats-connect'
const signPsbtOptions = {
payload: {
network: {
type:'Mainnet'
},
message: 'Sign Transaction',
psbtBase64: `cHNidP8BAJwCAmO+JvQJxhVDDpm3tV5PmPfzvJOSL4GOdjEOpAAAAAAnrAAA==`,
broadcast: false,
inputsToSign: [{
address: "33TKH4kkiFPyTLDNmdNsLggyLeAYre57Qm",
signingIndexes: [1],
}],
},
onFinish: (response) => {
console.log(response.psbtBase64)
alert(response.psbtBase64)
},
onCancel: () => alert('Canceled'),
}
await signTransaction(signPsbtOptions);
You must specify the input index and the address to be signed in the request.
For example:
inputsToSign: [{
address: "bc1pr09enf3yc43cz8qh7xwaasuv3xzlgfttdr3wn0q2dy9frkhrpdtsk05jqq",
signingIndexes: [0]
}, {
address: "33TKH4kkiFPyTLDNmdNsLggyLeAYre57Qm",
signingIndexes: [1,2]
}]
The above parameters will ask the wallet to sign for address
bc1pr09enf3yc43cz8qh7xwaasuv3xzlgfttdr3wn0q2dy9frkhrpdtsk05jqq
at input index 0. And for address 33TKH4kkiFPyTLDNmdNsLggyLeAYre57Qm
at input indexes 1 and 2.You can also optionally specify a signature hash:
inputsToSign: [{
address: "bc1pr09enf3yc43cz8qh7xwaasuv3xzlgfttdr3wn0q2dy9frkhrpdtsk05jqq",
signingIndexes: [0],
sigHash: 131 // SIGHASH_SINGLE | ANYONECANPAY
}]
The user will see a transaction signing request prompt in the wallet. Xverse browser extension UI shown for example:

Depending on your use case, you can request that the PSBT be finalized and broadcasted after the user signs. Otherwise, the signed PSBT will be returned in the response without broadcasting.
If the transaction is broadcasted, you will receive a TXID in the response.
Last modified 1mo ago