MegaETH - The First Real-Time Blockchain
Complete guide to MegaETH integration with Dwellir RPC. Learn how to build on the first real-time blockchain with sub-millisecond latency and 100,000+ TPS.
MegaETH RPC
With Dwellir, you get access to our global MegaETH network which always routes your API requests to the nearest available location, ensuring low latency and the fastest speeds.
Get your API keyWhy Build on MegaETH?
MegaETH is the world's first real-time blockchain, delivering unprecedented performance while maintaining full EVM compatibility:
Real-Time Performance
- Sub-millisecond latency - Transaction streaming in real-time, not batches
- 100,000+ TPS sustained - Orders of magnitude faster than traditional L2s
- 0.01 second block time - Near-instant transaction finality
Battle-Tested Security
- Ethereum-secured - Inherits Ethereum's L1 security guarantees
- Backed by Vitalik Buterin - Co-founded by Ethereum's creator
- Full EVM compatibility - All existing Ethereum tools work seamlessly
Ideal for High-Frequency Applications
- High-frequency DeFi - Enable latency-sensitive trading strategies
- Gaming & Real-Time Apps - Build truly responsive onchain experiences
- Instant UX - Deliver web2-like responsiveness with web3 security
Quick Start with MegaETH
Connect to MegaETH in seconds with Dwellir's optimized endpoints:
curl -sS -X POST https://api-megaeth-mainnet.n.dwellir.com/<API_Keys_Are_Not_Made_for_Bots> \ -H 'Content-Type: application/json' \ -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'import { JsonRpcProvider } from 'ethers';const provider = new JsonRpcProvider( 'https://api-megaeth-mainnet.n.dwellir.com/<API_Keys_Are_Not_Made_for_Bots>');const latest = await provider.getBlockNumber();console.log('block', latest);import requestsurl = 'https://api-megaeth-mainnet.n.dwellir.com/<API_Keys_Are_Not_Made_for_Bots>'payload = { 'jsonrpc': '2.0', 'id': 1, 'method': 'eth_blockNumber', 'params': []}resp = requests.post(url, json=payload)print(resp.json())package mainimport ( "bytes" "fmt" "io" "net/http")func main() { url := "https://api-megaeth-mainnet.n.dwellir.com/<API_Keys_Are_Not_Made_for_Bots>" payload := []byte(`{"jsonrpc":"2.0","id":1,"method":"eth_blockNumber","params":[]}`) resp, err := http.Post(url, "application/json", bytes.NewBuffer(payload)) if err != nil { panic(err) } defer resp.Body.Close() body, _ := io.ReadAll(resp.Body) fmt.Println(string(body))}Installation & Setup
import { JsonRpcProvider } from 'ethers';
// Connect to MegaETH mainnet
const provider = new JsonRpcProvider(
'https://api-megaeth-mainnet.n.dwellir.com/YOUR_API_KEY'
);
// Get the latest block
const block = await provider.getBlock('latest');
console.log('Latest block:', block.number);
// Query account balance
const balance = await provider.getBalance('0x...');
console.log('Balance:', balance.toString());const Web3 = require('web3');
// Connect to MegaETH mainnet
const web3 = new Web3(
'https://api-megaeth-mainnet.n.dwellir.com/YOUR_API_KEY'
);
// Get chain ID to verify connection
const chainId = await web3.eth.getChainId();
console.log('Connected to MegaETH:', chainId === 4326);
// Get gas price for optimal transaction pricing
const gasPrice = await web3.eth.getGasPrice();
console.log('Current gas price:', gasPrice);import { createPublicClient, http } from 'viem';
import { defineChain } from 'viem';
// Define MegaETH chain
const megaeth = defineChain({
id: 4326,
name: 'MegaETH',
nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },
rpcUrls: {
default: { http: ['https://api-megaeth-mainnet.n.dwellir.com/YOUR_API_KEY'] },
},
blockExplorers: {
default: { name: 'Blockscout', url: 'https://megaeth.blockscout.com' },
},
});
// Create MegaETH client
const client = createPublicClient({
chain: megaeth,
transport: http('https://api-megaeth-mainnet.n.dwellir.com/YOUR_API_KEY'),
});
// Read contract data
const data = await client.readContract({
address: '0x...',
abi: contractAbi,
functionName: 'balanceOf',
args: ['0x...'],
});Network Information
| Parameter | Value | Details |
|---|---|---|
| Chain ID | 4326 | Mainnet |
| Block Time | 0.01 seconds | Real-time |
| Gas Token | ETH | Native token |
| RPC Standard | Ethereum | JSON-RPC 2.0 |
API Reference
MegaETH supports a subset of the Ethereum JSON-RPC API specification optimized for real-time performance.
Method Availability
MegaETH implements core Ethereum JSON-RPC methods with some modifications for performance:
- Debug methods are not available (debug_, trace_)
- Full block queries are disabled for
eth_getBlockByHashandeth_getBlockByNumber - Gas limits apply to certain methods (10,000,000 gas for
eth_call,eth_createAccessList,eth_estimateGas) - Block range limits apply to
eth_feeHistory(maximum 10,000 blocks)
Common Integration Patterns
Real-Time Transaction Streaming
Leverage MegaETH's real-time capabilities for instant transaction updates:
// Subscribe to pending transactions via WebSocket
const wsProvider = new ethers.WebSocketProvider(
'wss://api-megaeth-mainnet.n.dwellir.com/YOUR_API_KEY'
);
// Watch for new blocks in real-time (every 0.01s)
wsProvider.on('block', async (blockNumber) => {
console.log('New block:', blockNumber);
const block = await wsProvider.getBlock(blockNumber);
console.log('Block timestamp:', block.timestamp);
});
// Watch for specific transaction confirmations
async function streamTransaction(txHash) {
const receipt = await wsProvider.waitForTransaction(txHash, 1);
console.log('Transaction confirmed in:', receipt.blockNumber);
return receipt;
}Gas Optimization
Optimize gas costs on MegaETH:
// Get current fee data
const feeData = await provider.getFeeData();
// Estimate gas for transaction
const gasEstimate = await provider.estimateGas(tx);
// Calculate total cost
const totalCost = gasEstimate * feeData.gasPrice;
console.log('Estimated cost:', totalCost);Event Filtering
Efficiently query contract events with MegaETH's fast block times:
// Query recent events (fast with 0.01s blocks)
async function getRecentEvents(contract, eventName, blocksBack = 1000) {
const latestBlock = await provider.getBlockNumber();
const fromBlock = latestBlock - blocksBack;
const filter = contract.filters[eventName]();
const events = await contract.queryFilter(filter, fromBlock, latestBlock);
return events;
}Performance Best Practices
1. WebSocket for Real-Time Updates
Use WebSockets to leverage MegaETH's real-time streaming capabilities:
const wsProvider = new ethers.WebSocketProvider(
'wss://api-megaeth-mainnet.n.dwellir.com/YOUR_API_KEY'
);
// Subscribe to new blocks (every 0.01s)
wsProvider.on('block', (blockNumber) => {
console.log('New block:', blockNumber);
});
// Handle reconnection
wsProvider.on('error', () => {
console.log('WebSocket error, reconnecting...');
});2. Connection Pooling
Reuse provider instances to minimize connection overhead:
// Singleton pattern for provider
class MegaETHProvider {
static instance = null;
static getInstance() {
if (!this.instance) {
this.instance = new JsonRpcProvider(
'https://api-megaeth-mainnet.n.dwellir.com/YOUR_API_KEY'
);
}
return this.instance;
}
}3. Respect Gas Limits
MegaETH enforces a 10,000,000 gas limit for certain methods:
// When calling contracts, stay within gas limits
const result = await provider.call({
to: contractAddress,
data: calldata,
// MegaETH enforces 10M gas limit
gasLimit: 10000000
});Troubleshooting Common Issues
Error: "Gas limit exceeded"
MegaETH limits certain methods to 10,000,000 gas:
// Split large queries into smaller batches
async function batchCall(contract, method, args, batchSize = 100) {
const results = [];
for (let i = 0; i < args.length; i += batchSize) {
const batch = args.slice(i, i + batchSize);
const result = await contract[method](batch);
results.push(...result);
}
return results;
}Error: "Full block queries disabled"
Use the standard block query format without transaction details:
// Don't request full transaction objects
const block = await provider.getBlock(blockNumber, false);
// If you need transaction details, fetch them separately
for (const txHash of block.transactions) {
const tx = await provider.getTransaction(txHash);
console.log('Transaction:', tx);
}Error: "Block range too large"
For eth_feeHistory, limit your range to 10,000 blocks:
// Query fee history in 10k block batches
async function getFeeHistory(blockCount, newestBlock) {
const maxRange = 10000;
if (blockCount > maxRange) {
// Split into multiple requests
const batches = Math.ceil(blockCount / maxRange);
const results = [];
for (let i = 0; i < batches; i++) {
const batchSize = Math.min(maxRange, blockCount - (i * maxRange));
const batchResult = await provider.send('eth_feeHistory', [
batchSize,
newestBlock - (i * maxRange),
[]
]);
results.push(batchResult);
}
return results;
}
return provider.send('eth_feeHistory', [blockCount, newestBlock, []]);
}Smoke Tests
Test Connection with cURL
# Test MegaETH mainnet
curl -X POST https://api-megaeth-mainnet.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'Test with Ethers.js
// Test mainnet connection
const mainnetProvider = new JsonRpcProvider(
'https://api-megaeth-mainnet.n.dwellir.com/YOUR_API_KEY'
);
const blockNumber = await mainnetProvider.getBlockNumber();
const network = await mainnetProvider.getNetwork();
console.log('Block number:', blockNumber);
console.log('Chain ID:', network.chainId); // Should be 4326nTest with Web3.py
from web3 import Web3
# Test connection
web3 = Web3(Web3.HTTPProvider(
'https://api-megaeth-mainnet.n.dwellir.com/YOUR_API_KEY'
))
print('Connected:', web3.is_connected())
print('Chain ID:', web3.eth.chain_id) # Should be 4326
print('Block number:', web3.eth.block_number)Migration Guide
From Other EVM Chains
MegaETH is fully EVM-compatible, making migration straightforward:
// Before (Ethereum/other L2)
const provider = new JsonRpcProvider('https://eth-rpc.example.com');
// After (MegaETH)
const provider = new JsonRpcProvider(
'https://api-megaeth-mainnet.n.dwellir.com/YOUR_API_KEY'
);
// Smart contracts work identically
// Same tooling and libraries
// Note: Different chain ID (4326)
// Note: Some debug methods unavailable
// Note: Gas limits apply (10M for call/estimateGas)
// Note: Full block queries disabledResources & Tools
Official Resources
Developer Tools
Need Help?
- Email: support@dwellir.com
- Docs: You're here!
- Dashboard: dashboard.dwellir.com
Start building on MegaETH with Dwellir's enterprise-grade RPC infrastructure. Get your API key
rollup_getInfo - Get modular L2 rollup config...
Get modular L2 rollup configuration on Mantle Network. Essential for understanding the optimistic rollup parameters and settings.
eth_blockNumber
Get the current block height on MegaETH. Essential for syncing dApps, monitoring transaction confirmations, and blockchain state tracking.

