> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dynamic.xyz/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# signPsbt

# signPsbt

Signs a Partially Signed Bitcoin Transaction (PSBT). PSBTs are used for more complex Bitcoin transactions that may require multiple signatures or advanced scripting.

## Usage

```javascript theme={"system"}
import { signPsbt, isBitcoinWalletAccount } from "@dynamic-labs-sdk/bitcoin";
import { getPrimaryWalletAccount } from "@dynamic-labs-sdk/client";

const walletAccount = getPrimaryWalletAccount();

if (walletAccount && isBitcoinWalletAccount(walletAccount)) {
  const { signedPsbt } = await signPsbt({
    walletAccount,
    request: {
      unsignedPsbtBase64: "cHNidP8BAH...", // Base64-encoded PSBT
      allowedSighash: [1], // SIGHASH_ALL
      signature: [
        {
          address: walletAccount.address,
          signingIndexes: [0],
        },
      ],
    },
  });

  console.log("Signed PSBT:", signedPsbt);
}
```

## Parameters

| Parameter                                      | Type                       | Description                                                             |
| ---------------------------------------------- | -------------------------- | ----------------------------------------------------------------------- |
| `request.unsignedPsbtBase64`                   | `string`                   | The unsigned PSBT encoded in Base64                                     |
| `request.allowedSighash`                       | `number[]`                 | Array of allowed signature hash types                                   |
| `request.signature`                            | `Array` (optional)         | Array of signature configuration objects                                |
| `request.signature[].address`                  | `string`                   | The address to sign with                                                |
| `request.signature[].signingIndexes`           | `number[]`                 | The input indexes to sign                                               |
| `request.signature[].disableAddressValidation` | `boolean` (optional)       | Disable address validation                                              |
| `walletAccount`                                | `BitcoinWalletAccount`     | The wallet account to sign with                                         |
| `client`                                       | `DynamicClient` (optional) | The Dynamic client instance. Only required when using multiple clients. |

## Returns

`Promise<{ signedPsbt: string }>` - A promise that resolves to an object containing the signed PSBT in Base64 format.

## Errors

| Error                     | Description                                                       |
| ------------------------- | ----------------------------------------------------------------- |
| `NotBitcoinProviderError` | Thrown if the wallet account's provider is not a Bitcoin provider |

## React

```tsx theme={"system"}
import { signPsbt, isBitcoinWalletAccount } from '@dynamic-labs-sdk/bitcoin';
import { useGetWalletAccounts } from '@dynamic-labs-sdk/react-hooks';
import { useState } from 'react';

function SignPsbtButton({ unsignedPsbtBase64 }) {
  const { data: walletAccounts = [] } = useGetWalletAccounts();
  const walletAccount = walletAccounts.find(isBitcoinWalletAccount);
  const [signedPsbt, setSignedPsbt] = useState('');

  const handleSign = async () => {
    if (!walletAccount) return;
    const result = await signPsbt({
      walletAccount,
      request: {
        unsignedPsbtBase64,
        allowedSighash: [1],
        signature: [{ address: walletAccount.address, signingIndexes: [0] }],
      },
    });
    setSignedPsbt(result.signedPsbt);
  };

  return (
    <div>
      <button onClick={handleSign} disabled={!walletAccount}>Sign PSBT</button>
      {signedPsbt && <p>Signed: {signedPsbt.slice(0, 20)}...</p>}
    </div>
  );
}
```

## Related functions

* [signPsbts](/javascript/reference/bitcoin/sign-psbts) - Sign multiple PSBTs
* [sendBitcoin](/javascript/reference/bitcoin/send-bitcoin) - Send a simple Bitcoin transaction
