Overview
This guide shows you how to sign Bitcoin transactions using Dynamic’s Node SDK. Bitcoin uses PSBTs (Partially Signed Bitcoin Transactions) for signing. You create a PSBT, pass it tosignTransaction() as a base64 string, and receive the signed PSBT back.
Prerequisites
Step 1: Install Dependencies
These examples use
bitcoinjs-lib v7, where satoshi amounts are bigint values (for example 50_000n), not numbers.Step 2: Create and Sign a PSBT
The approach for signing transactions depends on how you created your wallet:With Automatic Backup (Recommended)
If you created your wallet withbackUpToDynamic: true, you can sign directly without retrieving key shares. walletMetadata is the object returned by createWalletAccount (or importPrivateKey), and password is the one you set at creation:
Signing on Testnet
For testnet, usebitcoin.networks.testnet for the PSBT and BitcoinNetwork.TESTNET for network. Build the PSBT with the wallet’s testnet address (tb1q...), which you get from deriveAccountAddress with network: BitcoinNetwork.TESTNET, and keep passing the walletMetadata from createWalletAccount unchanged:
network can make signing fail with No inputs found that belong to the account address. See Working with testnet.
With Manual Backup
If you created your wallet withbackUpToDynamic: false, you must retrieve and provide external key shares:
- If your wallet was created without a password, omit the
passwordparameter - If your wallet was created with a password, you must provide it for all operations
- Wallets created with
backUpToDynamic: truealways have a password, because one is required at creation