Premiers pas avec TheRPC
Ethereum/Core API/eth_sendRawTransaction

eth_sendRawTransaction

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.

Use Cases

  • Sending ETH transfers to other addresses and wallets
  • Token transfers (ERC-20, ERC-721, ERC-1155) in applications
  • Smart contract deployments for developers
  • Contract function calls and state changes in dApps
  • Automated transactions via scripts or bots
  • Multi-signature wallet interactions requiring offline signing
  • Meta-transactions (gas-less transactions) for better UX
  • DeFi operations (swaps, liquidity provision, staking)
  • Governance voting through contract interactions
  • NFT minting operations in marketplaces

Method Details

This method submits a signed transaction to the network for processing.

Paramètres:

The signed transaction data (hex string)

Retours:

The transaction hash, or the zero hash if the transaction is not yet available

Transaction Signing Process

Before using eth_sendRawTransaction, you need to:

  1. Create an unsigned transaction (with nonce, gas parameters, recipient, value, data)
  2. Sign the transaction with a private key
  3. Serialize and hex-encode the signed transaction
  4. Submit the hex string to this method

Understanding Transaction Types

Ethereum supports different transaction types:

TypeDescriptionStructure
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}

Response Example

{
	"jsonrpc": "2.0",
	"id": 1,
	"result": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331"
}

Error Response Example

{
	"jsonrpc": "2.0",
	"id": 1,
	"error": {
		"code": 3,
		"message": "execution reverted: Dai/insufficient-balance",
		"data": "0x08c379a00000000000000000000000000000000000000000000000000000000000000..."
	}
}

Common Errors and Troubleshooting

ErrorDescriptionSolution
Nonce too lowThe transaction nonce has already been usedGet the latest nonce with eth_getTransactionCount
Nonce too highThe transaction nonce is higher than expectedUse the correct sequential nonce
Insufficient fundsNot enough ETH for gas + valueAdd more ETH to the sender address
Gas price too lowOffered gas price below minimumIncrease gas price or use EIP-1559 parameters
Underpriced replacementWhen replacing a tx, new gas price is too lowIncrease gas price by at least 10%
Already knownTransaction already in the mempoolWait for the existing transaction
Execution revertedContract execution failedCheck contract conditions and parameters

Monitoring Transaction Status

After broadcasting a transaction:

  1. Store the returned transaction hash
  2. Poll eth_getTransactionReceipt until it returns a non-null result
  3. Check the status field in the receipt:
    • 0x1 indicates success
    • 0x0 indicates failure (reverted)

Gas Estimation and Optimization

Before sending transactions, you can:

  1. Use eth_estimateGas to get the approximate gas needed
  2. For EIP-1559 transactions, check current network conditions with eth_feeHistory
  3. For time-sensitive transactions, set higher priority fees
  4. For non-urgent transactions, set lower fees to save costs

Important Notes

  • Transactions must be signed with the sender's private key before submission
  • The RPC endpoint never has access to your private keys
  • Use eth_getTransactionReceipt to check status after submission
  • For contract creation, the receipt contains the new contract address in the contractAddress field
  • Hex strings must be properly formatted with even length and '0x' prefix
  • Consider using hardware wallets or secure key management for high-value transactions
  • Nonce management is critical for proper transaction sequencing
  • Transaction replacement requires higher gas price than the original
  • Transaction fees are non-refundable even if the transaction fails
  • EIP-1559 transactions can be more cost-effective during volatile fee periods

See also

Aidez-nous à nous améliorer !
Partagez cette page et aidez-nous à créer un produit encore meilleur pour vous.