🟠signPsbt

You can use the signPsbt method to request the signature of a Partially Signed Bitcoin Transaction (PSBT) from your user's Bitcoin wallet addresses.

The PSBT to be signed must be base64-encoded. You can use any Bitcoin library to construct this transaction. See examples using @scure/btc-signerhere: Creating Bitcoin PSBTs

Request parametersDescription

psbt

a string representing the psbt to sign, encoded in base64

signInputs

an array of objects with <string, number[]> properties describing:

  • string: the address to use to sign the input(s)

  • number[]: the index of the inputs to sign

allowedSignHash

a number representing the sigHash type to use for signing.

will default to the sighash type of the input if not provided.

broadcast

a boolean flag that specifies whether to broadcast the signed transaction after signature

import {
  Wallet,
  BitcoinNetworkType,
  RpcErrorCode,
} from "sats-connect";
    
try {
  const response = await Wallet.request('signPsbt', {
    psbt: psbtBase64,
    allowedSignHash: btc.SigHash.SINGLE | btc.SigHash.DEFAULT_ANYONECANPAY,
    signInputs: {
      [paymentAddress]: [0],
      [ordinalsAddress]: [1,2],
    },
  });
  if (response.status === "success") {
    // handle success response
  } else {
    if (response.error.code === RpcErrorCode.USER_REJECTION) {
      // handle user request cancelation
    } else {
      // handle error 
    }
  }
} catch (err) {
  console.log(err);
}

The above request parameters will ask the wallet to:

  • sign with the payment address at input index 0

  • sign with the ordinal address at input indexes 1 and 2

  • using the SIGHASH_SINGLE | ANYONECANPAY flag

Depending on your use case, you can request that the PSBT be finalized and broadcasted after the user signs, by setting the broadcast flag to true. Otherwise, the signed PSBT will be returned in the response without broadcasting.

The signPsbt method returns a Promise that resolves to the SignPsbtResult object:

PropertyDescription

psbt

The base64 encoded signed PSBT

txid

The transaction id as a hex-encoded string.

This is only returned if the transaction was broadcasted.

Last updated