> ## 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.

> [!NOTE]
>
> With an embedded wallet, `signature[].address` must be your wallet's own address for the active network, and `disableAddressValidation` has no effect. To co-sign a P2WSH multisig input, pass its witness script in `allowedWitnessScripts`. See [Embedded Wallet Differences](https://docs.dynamic.xyz/docs/javascript/reference/bitcoin/embedded-wallet-differences.md).

## 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.allowedWitnessScripts` | `string[]` (optional) | Embedded wallets only. Hex-encoded witness scripts of P2WSH multisig inputs the wallet may co-sign. Ignored by external wallets. |
| `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](https://docs.dynamic.xyz/docs/javascript/reference/bitcoin/sign-psbts.md) - Sign multiple PSBTs
* [sendBitcoin](https://docs.dynamic.xyz/docs/javascript/reference/bitcoin/send-bitcoin.md) - Send a simple Bitcoin transaction
* [Embedded Wallet Differences](https://docs.dynamic.xyz/docs/javascript/reference/bitcoin/embedded-wallet-differences.md) - How these options behave with embedded wallets


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.