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

Usage

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

ParameterTypeDescription
request.unsignedPsbtBase64stringThe unsigned PSBT encoded in Base64
request.allowedSighashnumber[]Array of allowed signature hash types
request.signatureArray (optional)Array of signature configuration objects
request.signature[].addressstringThe address to sign with
request.signature[].signingIndexesnumber[]The input indexes to sign
request.signature[].disableAddressValidationboolean (optional)Disable address validation
walletAccountBitcoinWalletAccountThe wallet account to sign with
clientDynamicClient (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

ErrorDescription
NotBitcoinProviderErrorThrown if the wallet account’s provider is not a Bitcoin provider