Skip to main content

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