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.

sendRawTransaction

Sends a raw Bitcoin transaction using the mempool.space API. This is useful when you have a fully constructed and signed raw transaction that you want to broadcast to the network.

Usage

import { sendRawTransaction, isBitcoinWalletAccount } from "@dynamic-labs-sdk/bitcoin";
import { getPrimaryWalletAccount } from "@dynamic-labs-sdk/client";

const walletAccount = getPrimaryWalletAccount();

if (walletAccount && isBitcoinWalletAccount(walletAccount)) {
  const { transactionId } = await sendRawTransaction({
    walletAccount,
    rawTransaction: "0100000001...", // Hex-encoded raw transaction
  });

  console.log("Transaction broadcast:", transactionId);
}

Parameters

ParameterTypeDescription
rawTransactionstringThe raw transaction in hexadecimal format
walletAccountBitcoinWalletAccountThe wallet account (used to determine network)
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
SendBitcoinRawTransactionErrorThrown if the transaction broadcast fails

React

import { sendRawTransaction, isBitcoinWalletAccount } from '@dynamic-labs-sdk/bitcoin';
import { useWalletAccounts } from '@dynamic-labs-sdk/react-hooks';
import { useState } from 'react';

function BroadcastButton({ rawTransaction }) {
  const walletAccounts = useWalletAccounts();
  const walletAccount = walletAccounts.find(isBitcoinWalletAccount);
  const [txId, setTxId] = useState('');

  const handleBroadcast = async () => {
    if (!walletAccount) return;
    const { transactionId } = await sendRawTransaction({ walletAccount, rawTransaction });
    setTxId(transactionId);
  };

  return (
    <div>
      <button onClick={handleBroadcast} disabled={!walletAccount}>Broadcast</button>
      {txId && <p>Transaction ID: {txId}</p>}
    </div>
  );
}