Berachain RPC with Dwellir
Berachain RPC endpoints for Mainnet and Bepolia testnet; EVM JSON-RPC quickstarts for curl, ethers.js, viem, and web3.py
Berachain RPC
With Dwellir, you get access to our global Berachain 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 Berachain?
High‑Performance EVM
- Built on a modular EVM (Polaris) for efficient execution and developer‑friendly precompiles
- Fast finality via CometBFT (BFT consensus), ideal for low‑latency reads and responsive UX
- EVM compatibility out of the box. Keep using Solidity, Hardhat, Foundry, viem, and ethers.js
Proof‑of‑Liquidity Alignment
- Separation of gas and governance unlocks healthier incentive design
- Liquidity provision powers governance emissions (BGT) to align validators, protocols, and users
- Ecosystem‑driven rewards encourage deep liquidity for DeFi building blocks
Interoperability & Modularity
- Cosmos SDK foundation with IBC‑friendly architecture for cross‑chain connectivity
- Polaris EVM’s modular design enables stateful precompiles and chain‑specific extensions without breaking EVM apps
- Drop‑in migration: reuse your contracts, tooling, and workflows
Quick Start with Berachain
Connect to Berachain in seconds with Dwellir's optimized endpoints:
curl -sS -X POST https://api-berachain-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-berachain-mainnet.n.dwellir.com/<API_Keys_Are_Not_Made_for_Bots>');const latest = await provider.getBlockNumber();console.log('block', latest);import requestsurl = 'https://api-berachain-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-berachain-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
Network Information
| Parameter | Value | Details |
|---|---|---|
| Mainnet Chain ID | 80094 (0x138de) | Berachain Mainnet |
| Testnet Chain ID | 80069 (0x138c5) | Bepolia Testnet |
| RPC Standard | Ethereum JSON-RPC 2.0 | EVM-compatible |
API Reference
Berachain supports the full Ethereum JSON-RPC API.
Common Integration Patterns
Transaction Monitoring
Monitor pending and confirmed transactions efficiently:
async function waitForConfirmations(provider, txHash, confirmations = 1) {
const receipt = await provider.waitForTransaction(txHash, confirmations);
return receipt;
}Gas Optimization
Use EIP‑1559 dynamic fees and estimate execution gas:
const feeData = await provider.getFeeData();
const tx = {
to: recipient,
value: amount,
maxFeePerGas: feeData.maxFeePerGas,
maxPriorityFeePerGas: feeData.maxPriorityFeePerGas,
gasLimit: await provider.estimateGas({ to: recipient, value: amount }),
};Event Filtering
Query events in bounded ranges to avoid overfetching:
async function getEvents(contract, filter, fromBlock, toBlock, batchSize = 2000) {
const events = [];
for (let i = fromBlock; i <= toBlock; i += batchSize) {
const batch = await contract.queryFilter(filter, i, Math.min(i + batchSize - 1, toBlock));
events.push(...batch);
}
return events;
}Performance Best Practices
1. Batch Requests
Combine independent calls in a single POST to reduce round‑trips:
const batch = [
{ jsonrpc: '2.0', method: 'eth_blockNumber', params: [], id: 1 },
{ jsonrpc: '2.0', method: 'eth_gasPrice', params: [], id: 2 },
{ jsonrpc: '2.0', method: 'eth_chainId', params: [], id: 3 }
];
const res = await fetch('https://api-berachain-mainnet.n.dwellir.com/YOUR_API_KEY', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(batch)
});
const results = await res.json();2. Connection Pooling
Reuse provider/clients instead of recreating per call:
import { JsonRpcProvider } from 'ethers';
class BeraProvider {
static instance: JsonRpcProvider | null = null;
static get() {
if (!this.instance) {
this.instance = new JsonRpcProvider('https://api-berachain-mainnet.n.dwellir.com/YOUR_API_KEY');
}
return this.instance;
}
}3. Smart Caching
Cache immutable data (e.g., past blocks, ABIs) and debounce hot paths:
const cache = new Map<string, unknown>();
async function getBlockCached(n: number) {
const k = `block_${n}`;
if (!cache.has(k)) {
cache.set(k, await BeraProvider.get().getBlock(n));
}
return cache.get(k);
}Migration Guide
Moving from Ethereum or another EVM chain typically requires:
- Update RPC URL to the Berachain mainnet endpoint:
https://api-berachain-mainnet.n.dwellir.com/YOUR_API_KEY - Verify chain ID via
eth_chainId(0x138de mainnet) before sending transactions - Re-check gas settings (EIP‑1559) and any hard‑coded addresses
// Before
const provider = new JsonRpcProvider('https://eth.example');
// After (Berachain mainnet)
const provider = new JsonRpcProvider('https://api-berachain-mainnet.n.dwellir.com/YOUR_API_KEY');Resources & Tools
Related Reading
Troubleshooting Common Issues
- Wrong chain: ensure
eth_chainIdreturns0x138de(mainnet) or0x138c5(Bepolia). - Hex quantities: send and parse
0x-prefixed hex strings (no leading zeros). - Timeouts/rate limits: implement retries with exponential backoff on HTTP 429 or -32005.
FAQs
- Do I need an API key? Yes, append
/YOUR_API_KEYto all endpoints. - WebSockets? Use HTTP endpoints above; WebSocket availability may vary.
- Explorers/faucets? N/A.
Smoke Tests
- curl:
eth_blockNumberto both endpoints returnsresult: "0x...". - ethers v6:
getBlockNumber()resolves;getNetwork().chainIdequals 80094 or 80069. - web3.py:
is_connected()is True;chain_idandblock_numberquery succeed.
Start building on Berachain with Dwellir’s reliable RPC.

