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.
sendBitcoin
Sends a Bitcoin transaction to a recipient address.
Usage
import { sendBitcoin, isBitcoinWalletAccount } from "@dynamic-labs-sdk/bitcoin";
import { getPrimaryWalletAccount } from "@dynamic-labs-sdk/client";
const walletAccount = getPrimaryWalletAccount();
if (walletAccount && isBitcoinWalletAccount(walletAccount)) {
const { transactionId } = await sendBitcoin({
walletAccount,
transaction: {
recipientAddress: "RECIPIENT_BTC_ADDRESS",
amount: 10000n, // Amount in satoshis
},
});
console.log("Transaction sent:", transactionId);
}
React
import { sendBitcoin, isBitcoinWalletAccount } from '@dynamic-labs-sdk/bitcoin';
import { useWalletAccounts } from '@dynamic-labs-sdk/react-hooks';
import { useState } from 'react';
function SendBitcoinButton({ recipientAddress, amountSatoshis }) {
const walletAccounts = useWalletAccounts();
const walletAccount = walletAccounts.find(isBitcoinWalletAccount);
const [txId, setTxId] = useState('');
const handleSend = async () => {
if (!walletAccount) return;
const { transactionId } = await sendBitcoin({
walletAccount,
transaction: { recipientAddress, amount: BigInt(amountSatoshis) },
});
setTxId(transactionId);
};
return (
<div>
<button onClick={handleSend} disabled={!walletAccount}>Send Bitcoin</button>
{txId && <p>Transaction ID: {txId}</p>}
</div>
);
}
Parameters
| Parameter | Type | Description |
|---|
transaction.recipientAddress | string | The recipient’s Bitcoin address |
transaction.amount | bigint | The amount to send in satoshis |
walletAccount | BitcoinWalletAccount | The wallet account to send from |
client | DynamicClient (optional) | The Dynamic client instance. Only required when using multiple clients. |
Returns
Promise<{ transactionId: string }> - A promise that resolves to an object containing the transaction ID.
Errors
| Error | Description |
|---|
NotBitcoinProviderError | Thrown if the wallet account’s provider is not a Bitcoin provider |
MethodNotImplementedError | Thrown if the wallet provider does not implement the sendBitcoin method |