# 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. <i class="fa-bitcoin">:bitcoin:</i>

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 Bitcoin PSBTs](/sats-connect/guides/creating-bitcoin-psbts.md)

<table><thead><tr><th width="200">Request parameters</th><th>Description</th></tr></thead><tbody><tr><td><code>psbt</code></td><td>a string representing the <code>psbt</code> to sign, encoded in <code>base64</code></td></tr><tr><td><code>signInputs</code></td><td><p>A <code>Record&#x3C;string, number[]></code> where,</p><ul><li>the keys are the addresses to use for signing</li><li>the values are the indexes of the inputs to sign with each address.</li></ul></td></tr><tr><td><code>broadcast</code></td><td>a boolean flag that specifies whether to broadcast the signed transaction after signature</td></tr></tbody></table>

```typescript
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

The user will see a Bitcoin transaction signing request prompt in the wallet. Xverse browser extension UI shown as example:\
\
![](/files/e0HLqqZ6VPgzlBjUvEvg)

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:

<table><thead><tr><th width="162">Property</th><th>Description</th></tr></thead><tbody><tr><td><code>psbt</code> </td><td>The base64 encoded signed PSBT </td></tr><tr><td><code>txid</code></td><td><p></p><p>The transaction id as a hex-encoded string.</p><p>This is only returned if the transaction was broadcasted.</p></td></tr></tbody></table>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.xverse.app/sats-connect/bitcoin-methods/signpsbt.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
