Recommended: JavaScript SDK with React Hooks
For new React apps, we recommend the JavaScript SDK with React Hooks (
@dynamic-labs-sdk/react-hooks) instead of the legacy React SDK documented here. The JS SDK comes with many benefits such as a much smaller bundle size and other optimizations. Use the React quickstart (JavaScript SDK) to get started.Signing PSBTs (Partially Signed Bitcoin Transactions) for Bitcoin Embedded Wallets
This guide explains how to use thesignPsbt method to sign Partially Signed Bitcoin Transactions (PSBTs) for Bitcoin embedded wallets. The method signs only the inputs related to the user’s wallet and returns a signed (but not finalized) PSBT for review and finalization.
Overview
PSBTs allow multiple parties to collaboratively build and sign Bitcoin transactions. ThesignPsbt method:
- Signs only inputs that belong to the user’s wallet address
- Does NOT finalize the PSBT - it remains partially signed for review
- Returns a signed PSBT that can be reviewed, combined with other signatures, and finalized by the user
Method Signature
Type Definitions
For Embedded Wallets
- Only require
unsignedPsbtBase64- no other parameters needed - Always use SIGHASH_ALL (0x01) - not configurable for now
- Automatically sign all inputs that belong to the wallet address
- Do not support the
signatureparameter for now
Important Notes
PSBT is NOT Finalized
ThesignPsbt method does NOT finalize the PSBT. It only signs the inputs that belong to the user’s wallet. The returned PSBT:
- Contains signatures for the user’s inputs
- Remains in PSBT format (not a finalized transaction)
- Can be reviewed by the user before finalization
- Can be combined with signatures from other parties
- Must be finalized before broadcasting
Signing Only User-Related Inputs
The method automatically signs all inputs that belong to the user’s wallet address. You cannot specify which inputs to sign - it signs all of them automatically.🔍 User Review and Finalization
After signing, the PSBT should be:- Reviewed by the user to verify transaction details
- Combined with other signatures if it’s a multi-party transaction
- Finalized using a Bitcoin library (e.g.,
bitcoinjs-lib) - Broadcast to the Bitcoin network
Usage Examples
Basic PSBT Signing for Embedded Wallets
This example signs all inputs that belong to the user’s embedded wallet:Complete Example with Review and Finalization
This example shows the complete flow: signing, reviewing, and finalizing a PSBT:Signature Hash Types
Embedded wallets always use SIGHASH_ALL (0x01) - this is not configurable. You don’t need to (and cannot) specifyallowedSighash for embedded wallets.
Embedded Wallet Specific Notes
For embedded wallets:-
Simplified Interface: Only
unsignedPsbtBase64is required - no other parameters needed: - Automatic Signing: The method automatically signs all inputs that belong to the wallet address. You cannot specify which inputs to sign.
- Fixed SIGHASH: Embedded wallets always use SIGHASH_ALL (0x01) - this is not configurable.
-
No Signature Parameter: The
signatureparameter is not supported (TypeScript will prevent you from using it). - MFA Support: The signing process may require MFA authentication if enabled.
Error Handling
Common errors and how to handle them:Invalid PSBT Format
Best Practices
- Always Review Before Finalization: Parse and display the PSBT details to the user before finalization
- Validate PSBT Format: Check that the PSBT is valid before attempting to sign
- Handle Errors Gracefully: Wrap
signPsbtcalls in try-catch blocks - Use Simplified Interface: Only provide
unsignedPsbtBase64- no need forallowedSighashorsignature - Don’t Finalize Automatically: Let the user review and finalize the PSBT manually
- Store Signed PSBTs Securely: Signed PSBTs contain sensitive information - handle them securely
PSBT Workflow
The typical PSBT workflow is:- Build PSBT: Create an unsigned PSBT with transaction details
- Sign PSBT: Use
signPsbtto sign inputs belonging to the user - Review PSBT: Parse and display transaction details for user review
- Combine Signatures: If multi-party, combine with other signatures
- Finalize PSBT: Convert the PSBT to a finalized transaction
- Broadcast Transaction: Send the finalized transaction to the Bitcoin network
Additional Resources
- Dynamic Labs Documentation
- BIP 174 - Partially Signed Bitcoin Transaction Format
- bitcoinjs-lib PSBT Documentation
- Create a PSBT guide for testing
- Sign a PSBT (External Wallets) for external wallet flows