Electrum for Bitcoin
Overview
The blockchain.transaction.broadcast
method allows clients to broadcast a raw transaction to the network. This function is essential for applications that need to send transactions directly.
Parameters
Name | Type | Required | Description |
---|---|---|---|
raw_tx | string | Yes | The raw transaction as a hexadecimal string. |
Returns
The method returns the transaction hash if the transaction is successfully broadcast to the network. In case of an error, the method returns a JSON RPC error in newer protocol versions or an error message directly in the result for protocol version 1.0.
Field | Description |
---|---|
txid | The transaction hash as a hexadecimal string, or an error message (protocol v1.0). |
Example Result
"a76242fce5753b4212f903ff33ac6fe66f2780f34bdb4b33b175a7815a11a98e"
Protocol version 1.0 error example:
"258: txn-mempool-conflict"
Request Example
curl --location 'https://api.tatum.io/v3/blockchain/node/bitcoin-mainnet-electrs/' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {API_KEY}' \
--data '{
"method": "blockchain.transaction.broadcast",
"params": ["0100000001abcdef..."],
"id": 1,
"jsonrpc": "2.0"
}'
// yarn add @tatumio/tatum
import { TatumSDK, BitcoinElectrs, Network } from '@tatumio/tatum'
const tatum = await TatumSDK.init<BitcoinElectrs>({ network: Network.BITCOIN_ELECTRS })
const transactionHash = await tatum.rpc.broadcastTransaction('0100000001abcdef...')
console.log('Transaction Hash:', transactionHash)
await tatum.destroy() // Destroy Tatum SDK - needed for stopping background jobs when done