signPsbt
Requests the connected wallet to sign a Partially Signed Bitcoin Transaction (PSBT).
Usage
import { request } from '@stacks/connect';
const result = await request('signPsbt', {
psbt: 'cHNidP8BAH0...base64-encoded-psbt',
signInputs: [
{
index: 0,
address: 'bc1q...address',
},
],
broadcast: true,
network: 'mainnet',
});
console.log('Signed PSBT:', result.psbt);
console.log('Transaction ID:', result.txid);import { request } from '@stacks/connect';
// Sign specific inputs by index only
const result = await request('signPsbt', {
psbt: 'cHNidP8BAH0...base64-encoded-psbt',
signInputs: [0, 2],
broadcast: false,
});
console.log('Signed PSBT (base64):', result.psbt);Notes
The
psbtmust be a base64-encoded PSBT string.The
signInputsparameter supports two formats: an array of input indices (number[]), or an array ofSignInputsByAddressobjects for more granular control.Provider overrides automatically transform the
signInputsformat and PSBT encoding to match each wallet's expected schema (e.g. Xverse uses a record-based format, Leather uses hex encoding).When
broadcastistrue, the wallet broadcasts the transaction after signing and returns thetxid.
Signature
Returns
SignPsbtResult
txid
string (optional)
The transaction ID, if the PSBT was broadcasted.
psbt
string
The signed PSBT (base64-encoded).
Parameters
psbt (required)
Type:
string
The base64-encoded PSBT to be signed.
signInputs (optional)
Type:
number[] | SignInputsByAddress[]
Specifies which inputs to sign. Can be:
An array of input indices (
number[]): signs the inputs at those positions.An array of
SignInputsByAddressobjects for more control:
index
number
The input index to sign.
address
string
The address that owns this input.
publicKey
string (optional)
The public key for signing.
allowedSighash
Sighash[] (optional)
Allowed signature hash types for this input.
broadcast (optional)
Type:
boolean
Whether the wallet should broadcast the transaction after signing.
network (optional)
Type:
NetworkString
The network to use (e.g. 'mainnet', 'testnet').
allowedSighash (optional, experimental)
Type:
Sighash[]
Global allowed signature hash types. This may be renamed in the future as wallets adopt SIPs/WBIPs.
Last updated
Was this helpful?