# Berachain RPC with Dwellir

## Berachain RPC plans and rate limits

- **Free plan:** 20 responses per second, up to 100,000 responses a day.
- **Plans:** $49/mo, $299/mo, $999/mo with 25M, 150M, and 500M included responses. Overages billed at $5/$3/$2 per million responses respectively.
- **Paid rate limits:** 100 to 5,000 responses per second (bursts from 500 to 10,000), no daily limit.
- **Billing:** 1 response = 1 API credit on every shared plan, over HTTPS or WebSocket (WSS) where Berachain supports it.

Details: [Pricing](https://www.dwellir.com/docs/getting-started/pricing) · [Rate limits](https://www.dwellir.com/docs/getting-started/rate-limits) · [Authentication](https://www.dwellir.com/docs/getting-started/authentication) · [Archive nodes](https://www.dwellir.com/docs/getting-started/archive-nodes)

## Why 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:

### Installation & Setup

cURL
Ethers.js v6
Viem
Python (web3.py)

```bash
# Check latest block
curl -s -X POST https://api-berachain-mainnet.n.dwellir.com/YOUR_API_KEY \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'

# Verify chain id
curl -s -X POST https://api-berachain-bepolia.n.dwellir.com/YOUR_API_KEY \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":1}'
```

```ts
import { JsonRpcProvider } from 'ethers';

// Mainnet
const mainnet = new JsonRpcProvider('https://api-berachain-mainnet.n.dwellir.com/YOUR_API_KEY');
console.log(await mainnet.getBlockNumber());
console.log((await mainnet.getNetwork()).chainId); // 80094

// Bepolia testnet
const bepolia = new JsonRpcProvider('https://api-berachain-bepolia.n.dwellir.com/YOUR_API_KEY');
console.log(await bepolia.getBlockNumber());
console.log((await bepolia.getNetwork()).chainId); // 80069
```

```ts
import { createPublicClient, http, parseEther } from 'viem';

const mainnet = createPublicClient({
  transport: http('https://api-berachain-mainnet.n.dwellir.com/YOUR_API_KEY'),
});

const blockNumber = await mainnet.getBlockNumber();
const balance = await mainnet.getBalance({ address: '0x0000000000000000000000000000000000000000' });
```

```py
from web3 import Web3

w3 = Web3(Web3.HTTPProvider('https://api-berachain-mainnet.n.dwellir.com/YOUR_API_KEY'))
assert w3.is_connected()
print(w3.eth.chain_id)      # 80094
print(w3.eth.block_number)
```

## 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](https://ethereum.org/developers/docs/apis/json-rpc/).

## Common Integration Patterns

### Transaction Monitoring

Monitor pending and confirmed transactions efficiently:

```javascript
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:

```javascript
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:

```javascript
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:

```javascript
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:

```ts
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:

```ts
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

```ts
// 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

- [Berachain Docs](https://docs.berachain.com/)
- [Dwellir Dashboard](https://dashboard.dwellir.com)
- [Dwellir Support](mailto:support@dwellir.com)

### Related Reading

- [Top 7 Berachain RPC Providers 2026](https://www.dwellir.com/blog/top-berachain-rpc-providers)

## Troubleshooting Common Issues

- Wrong chain: ensure `eth_chainId` returns `0x138de` (mainnet) or `0x138c5` (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_KEY` to all endpoints.
- WebSockets? Use HTTP endpoints above; WebSocket availability may vary.
- Explorers/faucets? N/A.

## Smoke Tests

- curl: `eth_blockNumber` to both endpoints returns `result: "0x..."`.
- ethers v6: `getBlockNumber()` resolves; `getNetwork().chainId` equals 80094 or 80069.
- web3.py: `is_connected()` is True; `chain_id` and `block_number` query succeed.

***

Start building on Berachain with Dwellir’s reliable RPC.
