Skip to main content

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

ParameterTypeDescription
transaction.recipientAddressstringThe recipient’s Bitcoin address
transaction.amountbigintThe amount to send in satoshis
walletAccountBitcoinWalletAccountThe wallet account to send from
clientDynamicClient (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

ErrorDescription
NotBitcoinProviderErrorThrown if the wallet account’s provider is not a Bitcoin provider
MethodNotImplementedErrorThrown if the wallet provider does not implement the sendBitcoin method