Skip to content

btc.sendTransaction

Send BTC chain transactions via the btc object.

Usage

Transfer BTC

ts
const result = await Turing.btc.sendTransaction({
  toAddress: "bc1qxyz...",
  amount: "100000", // 100000 satoshis
  broadcastEnabled: true,
});

if (result.txid) {
  console.log("Transaction hash:", result.txid);
}

Without Broadcasting

ts
const result = await Turing.btc.sendTransaction({
  toAddress: "bc1qxyz...",
  amount: "100000",
  broadcastEnabled: false,
});

if (result.txraw) {
  console.log("Raw transaction data:", result.txraw);
}

Parameters

ts
interface BtcSendTransaction {
  toAddress: string;           // Recipient address
  amount: string;              // Transfer amount in satoshis
  broadcastEnabled?: boolean;  // Whether to broadcast, defaults to true
}
FieldTypeDescription
toAddressstringRecipient BTC address
amountstringTransfer amount in satoshis
broadcastEnabledboolean(Optional) Whether to broadcast the transaction. Defaults to true

Returns

ts
interface BtcSendTransactionResponse {
  txid?: string;  // Transaction hash (returned on successful broadcast)
  txraw?: string; // Raw transaction data (returned when broadcastEnabled is false)
  error?: string; // Error message
}
FieldTypeDescription
txidstringTransaction hash on successful broadcast
txrawstringRaw transaction data when broadcastEnabled is false
errorstringError message if the transaction fails

Error Handling

ts
const result = await Turing.btc.sendTransaction({
  toAddress: "bc1qxyz...",
  amount: "100000",
});

if (result.error) {
  console.error("Transaction failed:", result.error);
  return;
}

console.log("Success! txid:", result.txid);