⚠️Blast API (blastapi.io) ends Oct 31. Migrate to Dwellir and skip Alchemy's expensive compute units.
Switch Today →
Skip to main content

eth_sendRawTransaction

Submits a pre-signed transaction to the network for broadcast and execution. Returns the transaction hash if successful.

When to Use This Method

eth_sendRawTransaction is required for:

  • Sending BERA - Transfer value between accounts
  • Token Transfers - Execute ERC20/NFT transfers
  • Contract Interactions - Call state-changing functions
  • Contract Deployment - Deploy new smart contracts

Parameters

  1. Signed Transaction Data - DATA
    • The signed transaction data in RLP-encoded format
    • Must be prefixed with 0x
{
"jsonrpc": "2.0",
"method": "eth_sendRawTransaction",
"params": [
"0xf86c0185046110...signed_transaction_data...90a0cf5e"
],
"id": 1
}

Returns

DATA - 32 Bytes - The transaction hash, or error if transaction invalid.

Implementation Examples

# Send pre-signed transaction
curl -X POST https://api-berachain-mainnet.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_sendRawTransaction",
"params": [
"0xf86c018504a817c800825208947d1afa7b718fb893db30a3abc0cfc608aacfebb0880de0b6b3a7640000802ca0326436..."
],
"id": 1
}'

# Send with higher gas for faster confirmation
curl -X POST https://api-berachain-mainnet.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_sendRawTransaction",
"params": [
"0xf86c028504a817c800825208947d1afa7b718fb893db30a3abc0cfc608aacfebb0880de0b6b3a7640000802ca0326436..."
],
"id": 1
}'

Common Use Cases

1. Safe Transaction Broadcasting

// Broadcast with safety checks
async function safeBroadcast(wallet, transaction) {
// Pre-flight checks
const balance = await wallet.provider.getBalance(wallet.address);
const estimatedCost = transaction.gasLimit * transaction.maxFeePerGas;

if (balance < estimatedCost + transaction.value) {
throw new Error('Insufficient balance for transaction');
}

// Check nonce
const expectedNonce = await wallet.provider.getTransactionCount(wallet.address);
if (transaction.nonce && transaction.nonce !== expectedNonce) {
console.warn(`Nonce mismatch: expected ${expectedNonce}, got ${transaction.nonce}`);
}

// Sign transaction
const signedTx = await wallet.signTransaction(transaction);

// Broadcast with retry
let attempts = 0;
while (attempts < 3) {
try {
const txHash = await wallet.provider.send('eth_sendRawTransaction', [signedTx]);
return txHash;
} catch (error) {
if (error.message.includes('already known')) {
// Transaction already sent
return ethers.Transaction.from(signedTx).hash;
}
attempts++;
if (attempts === 3) throw error;
await new Promise(r => setTimeout(r, 1000 * attempts));
}
}
}

2. Optimized Gas Strategy

// Dynamic gas price management
async function optimizedSend(wallet, to, value) {
const provider = wallet.provider;

// Get network conditions
const [block, feeData, gasPrice] = await Promise.all([
provider.getBlock('latest'),
provider.getFeeData(),
provider.getGasPrice()
]);

// Calculate optimal fees
const baseFee = block.baseFeePerGas;
const priorityFee = feeData.maxPriorityFeePerGas;

// Adjust based on network congestion
const congestionFactor = Number(baseFee) / Number(parseUnits('10', 'gwei'));
const adjustedPriorityFee = priorityFee * BigInt(Math.ceil(congestionFactor));

const transaction = {
to: to,
value: parseEther(value),
type: 2,
chainId: 80094,
maxFeePerGas: baseFee * 2n + adjustedPriorityFee,
maxPriorityFeePerGas: adjustedPriorityFee,
gasLimit: 21000n
};

const signedTx = await wallet.signTransaction(transaction);
return await provider.send('eth_sendRawTransaction', [signedTx]);
}

3. Transaction Queue Management

// Manage transaction queue
class TransactionQueue {
constructor(wallet) {
this.wallet = wallet;
this.queue = [];
this.processing = false;
}

async add(transaction) {
this.queue.push(transaction);
if (!this.processing) {
this.process();
}
}

async process() {
this.processing = true;

while (this.queue.length > 0) {
const tx = this.queue.shift();

try {
// Add nonce
tx.nonce = await this.wallet.provider.getTransactionCount(this.wallet.address);

// Sign and send
const signedTx = await this.wallet.signTransaction(tx);
const hash = await this.wallet.provider.send('eth_sendRawTransaction', [signedTx]);

console.log(`Transaction sent: ${hash}`);

// Wait for confirmation before next
await this.wallet.provider.waitForTransaction(hash);
} catch (error) {
console.error('Transaction failed:', error);
// Optionally re-queue or handle error
}
}

this.processing = false;
}
}

Error Handling

Error CodeDescriptionSolution
-32000Invalid transactionCheck parameters and signature
-32001Insufficient fundsEnsure account has enough BERA
-32002Nonce too lowTransaction already processed
-32003Transaction underpricedIncrease gas price
async function handleSendError(error) {
const message = error.message || error.toString();

if (message.includes('insufficient funds')) {
return { error: 'Insufficient balance', recoverable: false };
}

if (message.includes('nonce too low')) {
return { error: 'Transaction already processed', recoverable: false };
}

if (message.includes('replacement transaction underpriced')) {
return { error: 'Gas price too low for replacement', recoverable: true };
}

if (message.includes('transaction already known')) {
return { error: 'Transaction already in mempool', recoverable: false };
}

return { error: message, recoverable: false };
}

Need help? Contact our support team or check the Berachain documentation.