> For the complete documentation index, see [llms.txt](https://docs.stacks.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.stacks.co/reference/stacks.js/stacks-connect/methods/signpsbt.md).

# signPsbt

Requests the connected wallet to sign a Partially Signed Bitcoin Transaction (PSBT).

***

### Usage

```ts
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);
```

```ts
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);
```

```ts
import { request } from '@stacks/connect';

// With sighash options
const result = await request('signPsbt', {
  psbt: 'cHNidP8BAH0...base64-encoded-psbt',
  signInputs: [
    {
      index: 0,
      address: 'bc1q...address',
      allowedSighash: ['ALL'],
    },
  ],
  allowedSighash: ['ALL', 'ANYONECANPAY'],
});
```

#### Notes

* The `psbt` must be a **base64-encoded** PSBT string.
* The `signInputs` parameter supports two formats: an array of input indices (`number[]`), or an array of `SignInputsByAddress` objects for more granular control.
* Provider overrides automatically transform the `signInputs` format and PSBT encoding to match each wallet's expected schema (e.g. Xverse uses a record-based format, Leather uses hex encoding).
* When `broadcast` is `true`, the wallet broadcasts the transaction after signing and returns the `txid`.

[**Reference Link**](https://github.com/stx-labs/connect/blob/main/packages/connect/src/methods.ts#L196)

***

### Signature

```ts
function request(
  'signPsbt',
  params: SignPsbtParams
): Promise<SignPsbtResult>
```

***

### Returns

`SignPsbtResult`

```ts
interface SignPsbtResult {
  txid?: string;
  psbt: string;
}
```

| Property | Type                | Description                                      |
| -------- | ------------------- | ------------------------------------------------ |
| `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 `SignInputsByAddress` objects for more control:

```ts
interface SignInputsByAddress {
  index: number;
  address: string;
  publicKey?: string;
  allowedSighash?: Sighash[];
}
```

| Property         | Type                   | Description                                  |
| ---------------- | ---------------------- | -------------------------------------------- |
| `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[]`

```ts
type Sighash = 'ALL' | 'NONE' | 'SINGLE' | 'ANYONECANPAY';
```

Global allowed signature hash types. This may be renamed in the future as wallets adopt SIPs/WBIPs.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.stacks.co/reference/stacks.js/stacks-connect/methods/signpsbt.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
