Optimism RPC Documentation
Optimism RPC
With Dwellir, you get access to our global Optimism network which always routes your API requests to the nearest available location, ensuring low latency and the fastest speeds.
Network Overview
Optimism is a Layer 2 scaling solution for Ethereum that uses optimistic rollups to achieve faster transactions and lower fees while maintaining Ethereum's security. As one of the leading L2 solutions, Optimism provides an EVM-equivalent environment that makes it easy for developers to deploy existing Ethereum applications.
Key Features
🚀 High Performance
- Fast Transactions: Sub-second block times with instant transaction confirmation
- Low Costs: Up to 100x lower gas fees compared to Ethereum mainnet
- High Throughput: Process thousands of transactions per second
🔒 Security & Reliability
- Ethereum Security: Inherits security from Ethereum mainnet
- Fraud Proofs: Optimistic rollup design with challenge period for security
- 99.99% Uptime: Enterprise-grade infrastructure with global redundancy
🛠️ Developer Experience
- EVM Equivalence: Deploy existing Solidity contracts without modification
- Full JSON-RPC: Complete Ethereum JSON-RPC API compatibility
- Archive Data: Access to full historical blockchain data
- Debug & Trace APIs: Advanced debugging capabilities for developers
Quick Start
🔗 RPC Endpoints
https://api-optimism-mainnet-archive.n.dwellir.com/YOUR_API_KEY
Quick Connect:
curl -X POST https://api-optimism-mainnet-archive.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'
Network Information
Mainnet Configuration
- Network Name: Optimism Mainnet
- Chain ID: 10 (0xa)
- Currency Symbol: ETH
- Block Explorer: https://optimistic.etherscan.io
Testnet Configuration
- Network Name: Optimism Sepolia
- Chain ID: 11155420 (0xaa37dc)
- Currency Symbol: ETH
- Block Explorer: https://sepolia-optimism.etherscan.io
Supported APIs
Our Optimism endpoints support the complete Ethereum JSON-RPC specification plus Optimism-specific methods:
Core APIs
- ✅ Standard Ethereum JSON-RPC: All eth_* methods
- ✅ Web3 Methods: web3_clientVersion, web3_sha3
- ✅ Net Methods: net_version, net_listening, net_peerCount
- ✅ Debug API: Transaction and block tracing
- ✅ Filter API: Event and log filtering
- ✅ Subscription API: Real-time updates via WebSocket
Optimism L2 Specific
- ✅ Gas Estimation: L1 and L2 gas cost estimation
- ✅ Rollup Info: Access rollup-specific information
- ✅ L1 Data Fee: Calculate L1 data submission costs
- ✅ Sequencer Status: Monitor sequencer health
Use Cases
DeFi Applications
Build decentralized exchanges, lending protocols, and yield optimizers with low transaction costs and fast confirmation times.
NFT Marketplaces
Deploy NFT collections and marketplaces with affordable minting and trading, perfect for high-volume applications.
Gaming & Metaverse
Create blockchain games and virtual worlds where users can perform frequent transactions without high gas costs.
DAO Infrastructure
Implement governance systems with affordable voting and proposal execution, enabling more democratic participation.
Integration Examples
Web3.js
const Web3 = require('web3');
const web3 = new Web3('https://api-optimism-mainnet-archive.n.dwellir.com/YOUR_API_KEY');
// Get latest block
const block = await web3.eth.getBlock('latest');
console.log('Latest block:', block.number);
// Check balance
const balance = await web3.eth.getBalance('0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb0');
console.log('Balance:', web3.utils.fromWei(balance, 'ether'), 'ETH');
Ethers.js
const { ethers } = require('ethers');
const provider = new ethers.JsonRpcProvider('https://api-optimism-mainnet-archive.n.dwellir.com/YOUR_API_KEY');
// Get network info
const network = await provider.getNetwork();
console.log('Connected to:', network.name, 'Chain ID:', network.chainId);
// Estimate L2 gas
const gasPrice = await provider.getFeeData();
console.log('Gas price:', ethers.formatUnits(gasPrice.gasPrice, 'gwei'), 'gwei');
viem
import { createPublicClient, http } from 'viem';
import { optimism } from 'viem/chains';
const client = createPublicClient({
chain: optimism,
transport: http('https://api-optimism-mainnet-archive.n.dwellir.com/YOUR_API_KEY'),
});
// Get chain ID
const chainId = await client.getChainId();
console.log('Chain ID:', chainId);
// Read contract
const balance = await client.getBalance({
address: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb0',
});
console.log('Balance:', balance);
Migration Guide
From Other Providers
Migrating to Dwellir is simple:
- Sign up for an API key at https://dashboard.dwellir.com
- Replace your current RPC URL with Dwellir's Optimism endpoint
- No code changes required - we support the full Ethereum JSON-RPC spec
From Ethereum Mainnet
Deploying from Ethereum to Optimism:
- Your Solidity contracts work without modification
- Use the same deployment tools (Hardhat, Truffle, Foundry)
- Update your provider URL to our Optimism endpoint
- Benefit from 100x lower gas costs
Best Practices
Optimize for L2
- Batch Operations: Group multiple operations to save on L1 data costs
- Event Monitoring: Use filters and subscriptions for efficient event tracking
- Gas Estimation: Always estimate both L1 and L2 costs before transactions
Error Handling
try {
const result = await provider.send('eth_call', [tx, 'latest']);
return result;
} catch (error) {
if (error.code === -32603) {
// Internal error, retry with exponential backoff
await delay(1000);
return retry();
}
throw error;
}
Troubleshooting
Common Issues
Connection Timeouts
- Check your API key is valid
- Ensure you're using the correct network endpoint
- Verify your firewall allows HTTPS connections
Nonce Too Low
- Optimism processes transactions quickly
- Always fetch the latest nonce before sending transactions
- Consider using pending nonce for successive transactions
L1 Data Fee Estimation
- Use
eth_estimateGas
for L2 execution cost - Calculate L1 data fee separately using rollup gas oracle
- Total cost = L2 execution cost + L1 data cost
Additional Resources
Support
Need help with your Optimism integration?
- 📧 Email: support@dwellir.com
- 📖 Documentation: Full API Reference
- 🎯 Dashboard: dashboard.dwellir.com
Start building on Optimism with Dwellir's reliable RPC infrastructure. Get your free API key and join thousands of developers scaling Ethereum applications.