eth_sendRawTransaction
Submits a pre-signed transaction to the network for execution.
When to Use This Method
Use eth_sendRawTransaction
to:
- Send ZETA Transfers - Transfer native ZETA tokens
- Execute Smart Contracts - Call contract functions
- Deploy Contracts - Deploy new smart contracts
- Cross-Chain Operations - Initiate omnichain transactions
- Batch Transactions - Send multiple pre-signed transactions
Parameters
- Signed Transaction Data -
DATA
- The signed transaction data as hexadecimal
{
"jsonrpc": "2.0",
"method": "eth_sendRawTransaction",
"params": [
"0xf86c0185046110c9e382520894d46e8dd67c5d32be8058bb8eb970870f072445678..."
],
"id": 1
}
Returns
DATA
, 32 Bytes - The transaction hash, or error if transaction invalid.
Implementation Examples
- cURL
- JavaScript
- Python
curl -X POST https://api-zetachain-mainnet.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_sendRawTransaction",
"params": [
"0xf86c0185046110c9e382520894d46e8dd67c5d32be8058bb8eb970870f072445678..."
],
"id": 1
}'
import { ethers } from 'ethers';
const provider = new ethers.JsonRpcProvider('https://api-zetachain-mainnet.n.dwellir.com/YOUR_API_KEY');
const wallet = new ethers.Wallet('YOUR_PRIVATE_KEY', provider);
// Send ZETA transfer
async function sendZETA(to, amount) {
const tx = {
to: to,
value: ethers.parseEther(amount),
gasLimit: 21000,
gasPrice: await provider.getGasPrice(),
nonce: await provider.getTransactionCount(wallet.address),
chainId: 7000 // ZetaChain mainnet
};
// Sign transaction
const signedTx = await wallet.signTransaction(tx);
// Send raw transaction
const txHash = await provider.send('eth_sendRawTransaction', [signedTx]);
console.log('Transaction sent:', txHash);
// Wait for confirmation
const receipt = await provider.waitForTransaction(txHash);
return receipt;
}
// Send cross-chain transaction
async function sendCrossChainTx(destChainId, recipient, amount, message) {
const connectorContract = new ethers.Contract(
'0x239e96c8f17C85c30100AC26F635Ea15f23E9c67',
['function send(uint256 destChainId, bytes recipient, uint256 amount, bytes message) payable'],
wallet
);
const tx = await connectorContract.send(
destChainId,
recipient,
ethers.parseEther(amount),
ethers.toUtf8Bytes(message),
{ value: ethers.parseEther('0.01') } // Protocol fee
);
console.log('Cross-chain tx:', tx.hash);
return tx;
}
// Batch transaction sender
class BatchTransactionSender {
constructor(wallet) {
this.wallet = wallet;
this.nonce = null;
}
async sendBatch(transactions) {
if (!this.nonce) {
this.nonce = await this.wallet.provider.getTransactionCount(this.wallet.address);
}
const results = [];
for (const tx of transactions) {
tx.nonce = this.nonce++;
tx.chainId = 7000;
const signedTx = await this.wallet.signTransaction(tx);
const txHash = await this.wallet.provider.send('eth_sendRawTransaction', [signedTx]);
results.push({
hash: txHash,
nonce: tx.nonce,
to: tx.to,
value: tx.value
});
}
return results;
}
}
from web3 import Web3
from eth_account import Account
w3 = Web3(Web3.HTTPProvider('https://api-zetachain-mainnet.n.dwellir.com/YOUR_API_KEY'))
# Create account from private key
account = Account.from_key('YOUR_PRIVATE_KEY')
# Build transaction
transaction = {
'to': '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb8',
'value': w3.to_wei(1, 'ether'),
'gas': 21000,
'gasPrice': w3.eth.gas_price,
'nonce': w3.eth.get_transaction_count(account.address),
'chainId': 7000 # ZetaChain mainnet
}
# Sign transaction
signed_tx = account.sign_transaction(transaction)
# Send raw transaction
tx_hash = w3.eth.send_raw_transaction(signed_tx.rawTransaction)
print(f'Transaction sent: {tx_hash.hex()}')
# Wait for receipt
receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
print(f'Transaction confirmed in block {receipt["blockNumber"]}')
Example Response
{
"jsonrpc": "2.0",
"id": 1,
"result": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331"
}
Transaction Building Guide
Standard ZETA Transfer
const tx = {
to: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb8',
value: ethers.parseEther('1.0'),
gasLimit: 21000,
gasPrice: await provider.getGasPrice(),
nonce: await provider.getTransactionCount(from),
chainId: 7000
};
Smart Contract Interaction
const tx = {
to: contractAddress,
data: contractInterface.encodeFunctionData('transfer', [recipient, amount]),
gasLimit: await provider.estimateGas(tx),
gasPrice: await provider.getGasPrice(),
nonce: await provider.getTransactionCount(from),
chainId: 7000
};
Contract Deployment
const tx = {
data: bytecode + constructorArgs,
gasLimit: 3000000,
gasPrice: await provider.getGasPrice(),
nonce: await provider.getTransactionCount(from),
chainId: 7000
};
Error Handling
Common Errors
Error | Cause | Solution |
---|---|---|
nonce too low | Nonce already used | Get current nonce |
insufficient funds | Not enough ZETA | Add funds to account |
gas too low | Insufficient gas limit | Increase gas limit |
invalid signature | Wrong chain ID or key | Check chain ID (7000) |
transaction underpriced | Gas price too low | Increase gas price |
Error Handling Example
async function safeSendTransaction(signedTx) {
try {
const txHash = await provider.send('eth_sendRawTransaction', [signedTx]);
return { success: true, hash: txHash };
} catch (error) {
if (error.message.includes('nonce too low')) {
return { success: false, error: 'Transaction already sent' };
}
if (error.message.includes('insufficient funds')) {
return { success: false, error: 'Insufficient ZETA balance' };
}
throw error;
}
}
Best Practices
- Always estimate gas before sending
- Implement nonce management for batch transactions
- Add gas price buffer for network congestion
- Wait for confirmations for important transactions
- Implement retry logic with exponential backoff
- Validate transaction parameters before signing
Security Considerations
- Never expose private keys in code
- Use hardware wallets for production
- Validate recipient addresses
- Implement transaction limits
- Monitor for transaction success
Related Methods
- eth_getTransactionReceipt - Get receipt
- eth_getTransactionByHash - Track transaction
- eth_estimateGas - Estimate gas
- eth_gasPrice - Get gas price
- eth_getTransactionCount - Get nonce