Send Transaction
How to submit transactions on MegaETH — deploy contracts, estimate gas, and debug failures.
Estimate gas correctly
# Estimate with MegaETH RPC (correct)
cast estimate 0xContract 'myFunction(uint256)' 42 \
--rpc-url https://mainnet.megaeth.com/rpccurl -s https://mainnet.megaeth.com/rpc \
-X POST -H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_estimateGas",
"params": [{"from":"0xYou","to":"0xContract","data":"0xCalldata"}],
"id": 1
}'Submit transaction
# forge create calls eth_estimateGas on the RPC — no local simulation
forge create src/MyContract.sol:MyContract \
--rpc-url https://mainnet.megaeth.com/rpc \
--private-key $PRIVATE_KEY# forge script runs local EVM simulation by default, which underestimates gas.
# Use --skip-simulation to bypass local estimation and let the RPC handle it.
forge script script/Deploy.s.sol \
--rpc-url https://mainnet.megaeth.com/rpc \
--private-key $PRIVATE_KEY \
--skip-simulation \
--broadcast# Send a simple ETH transfer
cast send 0xRecipient --value 0.1ether \
--rpc-url https://mainnet.megaeth.com/rpc \
--private-key $PRIVATE_KEY# 1. Sign the transaction offline (e.g., with cast)
SIGNED_TX=$(cast mktx 0xRecipient --value 0.1ether \
--rpc-url https://mainnet.megaeth.com/rpc \
--private-key $PRIVATE_KEY)
# 2. Submit via eth_sendRawTransaction
curl -s https://mainnet.megaeth.com/rpc \
-X POST -H "Content-Type: application/json" \
-d "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"eth_sendRawTransaction\",\"params\":[\"$SIGNED_TX\"]}"Debug a failed transaction
Symptom
Likely cause
Fix
Understand execution semantics
Last updated