Skip to main content

Overview

The BitcoinModule provides native Bitcoin operations including message signing, PSBT signing, sending Bitcoin, and balance queries. Access it via DynamicSDK.instance.bitcoin.

Prerequisites

Get a Bitcoin Wallet

There are two paths to a Bitcoin wallet: filter the user’s existing wallets, or create a new one explicitly.

Filter existing wallets

If Bitcoin is enabled and the user has a Bitcoin wallet (created automatically at signup), find it via userWallets:
final sdk = DynamicSDK.instance;

final btcWallet = sdk.wallets.userWallets.firstWhere(
  (w) => w.chain == 'BTC',
  orElse: () => throw StateError('No Bitcoin wallet found'),
);

print('Bitcoin address: ${btcWallet.address}');

Create a new Bitcoin wallet

Call createWallet with EmbeddedWalletChain.btc:
final wallet = await sdk.wallets.embedded.createWallet(
  chain: EmbeddedWalletChain.btc,
);

print('Created: ${wallet.address}');
Bitcoin wallets are derived as Native SegWit (bc1q…) by default. Mainnet is the only network supported today.

What is a satoshi?

A satoshi is the smallest unit of Bitcoin — 1 BTC = 100,000,000 satoshis. All amount fields in the Bitcoin module (sendBitcoin, buildPsbt, getBalance) are expressed in satoshis, not BTC.

What is a PSBT?

A Partially Signed Bitcoin Transaction (PSBT) is a standard for transactions that have not yet been fully signed. It allows different participants with different keys to sign a transaction without sharing private keys, enabling safer multi-step or multi-sig flows.

Get Balance

Query the Bitcoin balance (in satoshis) for a wallet:
final sdk = DynamicSDK.instance;
final wallet = sdk.wallets.userWallets.firstWhere(
  (w) => w.chain == 'BTC',
);

final balance = await sdk.bitcoin.getBalance(
  walletId: wallet.id,
);
print('Balance: $balance satoshis');
getBalance returns a Future<String> — satoshis as a string to preserve precision.

Operations

Detailed guides for each Bitcoin operation:

API Reference

MethodReturnsDescription
getBalanceFuture<String>Get wallet balance in satoshis
signMessageFuture<String>Sign a message
sendBitcoinFuture<String>Send BTC, returns transaction ID
buildPsbtFuture<String>Build unsigned PSBT (base64)
signPsbtFuture<String>Sign a single PSBT
signPsbtsFuture<List<String>>Sign multiple PSBTs
sendRawTransactionFuture<String>Broadcast raw transaction hex

Next Steps