The eth_sendRawTransaction
method broadcasts a pre-signed transaction to the Ethereum network. This method is used to submit all types of transactions after they have been signed offline, making it the primary method for any state-changing operations on the blockchain.
This method submits a signed transaction to the network for processing.
The signed transaction data (hex string)
The transaction hash, or the zero hash if the transaction is not yet available
Before using eth_sendRawTransaction
, you need to:
Ethereum supports different transaction types:
Type | Description | Structure |
---|---|---|
Legacy (Type 0) | Pre-EIP-1559 transactions with gasPrice | {nonce, gasPrice, gasLimit, to, value, data, v, r, s} |
EIP-2930 (Type 1) | Transactions with access lists | {chainId, nonce, gasPrice, gasLimit, to, value, data, accessList, v, r, s} |
EIP-1559 (Type 2) | Transactions with priority fee | {chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data, accessList, v, r, s} |
{
"jsonrpc": "2.0",
"id": 1,
"result": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331"
}
{
"jsonrpc": "2.0",
"id": 1,
"error": {
"code": 3,
"message": "execution reverted: Dai/insufficient-balance",
"data": "0x08c379a00000000000000000000000000000000000000000000000000000000000000..."
}
}
Error | Description | Solution |
---|---|---|
Nonce too low | The transaction nonce has already been used | Get the latest nonce with eth_getTransactionCount |
Nonce too high | The transaction nonce is higher than expected | Use the correct sequential nonce |
Insufficient funds | Not enough ETH for gas + value | Add more ETH to the sender address |
Gas price too low | Offered gas price below minimum | Increase gas price or use EIP-1559 parameters |
Underpriced replacement | When replacing a tx, new gas price is too low | Increase gas price by at least 10% |
Already known | Transaction already in the mempool | Wait for the existing transaction |
Execution reverted | Contract execution failed | Check contract conditions and parameters |
After broadcasting a transaction:
eth_getTransactionReceipt
until it returns a non-null resultstatus
field in the receipt:
0x1
indicates success0x0
indicates failure (reverted)Before sending transactions, you can:
eth_estimateGas
to get the approximate gas neededeth_feeHistory