Sats Connect - Wallet API for Bitcoin & Stacks
  • Introduction
  • Wallet Providers
    • getInfo
    • getProviders & getProviderById
  • Connecting to the wallet
    • Connect to Xverse Wallet
    • Disconnect from Xverse Wallet
    • Connect to other wallets
      • Manage a user's default wallet
    • [Legacy ⚠️] getAccounts
  • Wallet Methods
    • request methods
    • wallet_getAccount
    • wallet_getNetwork
    • wallet_changeNetwork
    • Xverse Custom Methods
  • Xverse Wallet Permissions
  • Xverse Wallet events
  • BITCOIN METHODS
    • 🟠getAddresses
    • 🟠signMessage
    • 🟠signPsbt
    • 🟠sendTransfer
    • 🟠signMultipleTransactions
    • 🟠getBalance
    • 🎨createInscription
    • 🎨createRepeatInscriptions
    • 🎨ord_getInscriptions
    • 🎨ord_sendInscriptions
    • 🔲runes_getBalance
    • 🔲runes_transfer
    • 🔲Mint Runes
      • runes_estimateMint
      • runes_mint
    • 🔲Etch Runes
      • runes_estimateEtch
      • runes_etch
    • 🔲runes_getOrder
    • 🔲Speed up a Rune Mint or Etch order
      • 🔲runes_estimateRbfOrder
      • 🔲runes_rbfOrder
  • STACKS METHODS
    • 🔴stx_getAccounts
    • 🔴stx_signMessage
    • 🔴stx_signStructuredMessage
    • 🔴stx_transferStx
    • 🔴stx_signTransaction
    • 🔴stx_callContract
    • 🔴stx_deployContract
  • GUIDES
    • Verify Bitcoin message signatures
    • Creating Bitcoin PSBTs
    • 📱Mobile Integration
    • Next.js support
  • RESOURCES
    • App Template
    • Demo App
    • Changelog
    • Github Issues
    • Developer forum
    • BIP322
Powered by GitBook
On this page
  1. BITCOIN METHODS

signPsbt

PrevioussignMessageNextsendTransfer

Last updated 5 months ago

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:

Request parameters
Description

psbt

a string representing the psbt to sign, encoded in base64

signInputs

A Record<string, number[]> where,

  • the keys are the addresses to use for signing

  • the values are the indexes of the inputs to sign with each address.

broadcast

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

import {
  request,
  BitcoinNetworkType,
  RpcErrorCode,
} from "sats-connect";
    
try {
  const response = await request('signPsbt', {
    psbt: psbtBase64,
    signInputs: {
      "1ef9...Jn1r": [0],
      "bc1p...ra4w": [1,2],
    },
  });
  
  // if the transaction is ready to broadcast and you want to broadcast
  // it yourself at this point, then remember to finalize the inputs in
  // the returned PSBT before broadcasting
  
  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_ALL 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:

Property
Description

psbt

The base64 encoded signed PSBT

txid

The transaction id as a hex-encoded string.

This is only returned if the transaction was broadcasted.

The user will see a Bitcoin transaction signing request prompt in the wallet. Xverse browser extension UI shown as example:

🟠
Creating Bitcoin PSBTs