Docs

opBNB RPC with Dwellir

opBNB RPC endpoints for Mainnet and Testnet; EVM JSON-RPC quickstarts for curl, ethers.js, viem, and web3.py

opBNB RPC

With Dwellir, you get access to our global opBNB network which always routes your API requests to the nearest available location, ensuring low latency and the fastest speeds.

Get your API key

Why Build on opBNB?

opBNB is BNB Chain's Layer 2 solution, designed to offer ultra-low fees and lightning-fast transaction processing. Built on Optimism's OP Stack, opBNB delivers:

Ultra-High Performance

  • Sub-second block times - Experience instant transaction confirmations
  • 100x lower fees than BNB Smart Chain mainnet
  • 150M gas limit - Massive throughput for complex applications

Enterprise-Grade Security

  • Backed by BNB Chain - Leverages proven Layer 1 infrastructure
  • Optimistic rollup technology - Inherits Ethereum-level security guarantees
  • Battle-tested architecture - Built on proven OP Stack foundation

Thriving Ecosystem

  • Native BNB token - No new tokens to manage
  • EVM compatibility - Deploy existing contracts seamlessly
  • Growing DeFi ecosystem - Access to expanding financial infrastructure

Quick Start with opBNB

Connect to opBNB in seconds with Dwellir's optimized endpoints:

opBNB RPC Endpoints
HTTPS
curl -sS -X POST https://api-opbnb-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-opbnb-mainnet.n.dwellir.com/<API_Keys_Are_Not_Made_for_Bots>');const latest = await provider.getBlockNumber();console.log('block', latest);
import requestsurl = 'https://api-opbnb-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-opbnb-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

ParameterValueDetails
Chain ID204Mainnet
Gas Limit150MPer block
Gas TokenBNBNative token
RPC StandardEthereumJSON-RPC 2.0

API Reference

opBNB supports the full Ethereum JSON-RPC API specification. Access all standard methods plus Layer 2 optimizations.

Common Integration Patterns

Transaction Monitoring

Monitor pending and confirmed transactions efficiently:

JavaScript
// Watch for transaction confirmation
async function waitForTransaction(txHash) {
  const receipt = await provider.waitForTransaction(txHash, 1);

  // Check transaction status
  if (receipt.status === 1) {
    console.log('Transaction confirmed:', receipt.transactionHash);
  }

  return receipt;
}

Gas Optimization

Optimize gas costs on opBNB Layer 2:

JavaScript
// Get current fee data
const feeData = await provider.getFeeData();

// Estimate gas for transaction
const gasEstimate = await provider.estimateGas({
  to: recipient,
  value: amount,
  data: '0x'
});

// Calculate total cost
const totalCost = gasEstimate * feeData.gasPrice;
console.log(`Transaction cost: ${totalCost} wei`);

Event Filtering

Efficiently query contract events with pagination:

JavaScript
// Query events with automatic retry and pagination
async function getEvents(contract, eventName, fromBlock = 0) {
  const filter = contract.filters[eventName]();
  const events = [];
  const batchSize = 5000; // opBNB recommended batch size

  const currentBlock = await provider.getBlockNumber();

  for (let i = fromBlock; i <= currentBlock; i += batchSize) {
    const batch = await contract.queryFilter(
      filter,
      i,
      Math.min(i + batchSize - 1, currentBlock)
    );
    events.push(...batch);
  }

  return events;
}

Performance Best Practices

1. Batch Requests

Combine multiple RPC calls for optimal performance:

JavaScript
const batch = [
  { method: 'eth_blockNumber', params: [] },
  { method: 'eth_gasPrice', params: [] },
  { method: 'eth_getBalance', params: [address, 'latest'] }
];

const results = await provider.send(batch);

2. Connection Pooling

Reuse provider instances to minimize connection overhead:

JavaScript
// Singleton pattern for provider
class OpBNBProvider {
  static instance = null;

  static getInstance() {
    if (!this.instance) {
      this.instance = new JsonRpcProvider(
        'https://api-opbnb-mainnet.n.dwellir.com/YOUR_API_KEY'
      );
    }
    return this.instance;
  }
}

3. Smart Caching

Cache immutable data to reduce API calls:

JavaScript
const cache = new Map();

async function getCachedBlockData(blockNumber) {
  const key = `block_${blockNumber}`;

  if (!cache.has(key)) {
    const block = await provider.getBlock(blockNumber);
    cache.set(key, block);
  }

  return cache.get(key);
}

Troubleshooting Common Issues

Wrong Chain ID Error

opBNB uses specific chain IDs for mainnet and testnet:

JavaScript
// Always verify chain ID matches expected network
const chainId = await provider.send('eth_chainId', []);

if (chainId === '0xcc') {
  console.log('Connected to opBNB Mainnet (204)');
} else if (chainId === '0x15eb') {
  console.log('Connected to opBNB Testnet (5611)');
} else {
  throw new Error(`Unexpected chain ID: ${chainId}`);
}

Transaction Underpriced Error

opBNB uses dynamic gas pricing:

JavaScript
// Get current fee data
const feeData = await provider.getFeeData();

const tx = {
  to: recipient,
  value: amount,
  maxFeePerGas: feeData.maxFeePerGas,
  maxPriorityFeePerGas: feeData.maxPriorityFeePerGas,
  gasLimit: 21000n
};

Rate Limit Exceeded

Implement exponential backoff for resilient applications:

JavaScript
async function callWithRetry(fn, maxRetries = 3) {
  for (let i = 0; i < maxRetries; i++) {
    try {
      return await fn();
    } catch (error) {
      if (error.code === 429 && i < maxRetries - 1) {
        await new Promise(r => setTimeout(r, 2 ** i * 1000));
      } else {
        throw error;
      }
    }
  }
}

FAQs

Q: What's the difference between opBNB and BNB Smart Chain? A: opBNB is a Layer 2 scaling solution built on top of BNB Smart Chain, offering much lower fees and faster transactions while maintaining full EVM compatibility.

Q: Can I use the same wallet for opBNB and BSC? A: Yes, any Ethereum-compatible wallet works with opBNB. Simply add the opBNB network configuration to your wallet.

Q: How do I bridge assets to opBNB? A: Use the official opBNB Bridge to transfer assets between BNB Smart Chain and opBNB.

Smoke Tests

Quick Connection Tests

Mainnet Connection:

Bash
curl -X POST https://api-opbnb-mainnet.n.dwellir.com/YOUR_API_KEY \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'

Testnet Connection:

Bash
curl -X POST https://api-opbnb-testnet.n.dwellir.com/YOUR_API_KEY \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'

Ethers.js Verification:

JavaScript
import { JsonRpcProvider } from 'ethers';

const provider = new JsonRpcProvider('https://api-opbnb-mainnet.n.dwellir.com/YOUR_API_KEY');

// Test connection
const blockNumber = await provider.getBlockNumber();
const network = await provider.getNetwork();

console.log(`Block: ${blockNumber}, Chain ID: ${network.chainId}`);

Web3.py Verification:

Python
from web3 import Web3

w3 = Web3(Web3.HTTPProvider('https://api-opbnb-mainnet.n.dwellir.com/YOUR_API_KEY'))

print(f"Connected: {w3.is_connected()}")
print(f"Chain ID: {w3.eth.chain_id}")
print(f"Block Number: {w3.eth.block_number}")

Migration Guide

From BNB Smart Chain to opBNB

Migrating from BSC to opBNB requires minimal code changes:

JavaScript
// Before (BSC)
const provider = new JsonRpcProvider('https://bsc-dataseed.bnbchain.org');

// After (opBNB)
const provider = new JsonRpcProvider(
  'https://api-opbnb-mainnet.n.dwellir.com/YOUR_API_KEY'
);

// Smart contracts work identically
// Same tooling and libraries
// Note: Different chain ID (204 vs 56)
// Note: Separate block numbers
// Note: Much lower gas fees

Resources & Tools

Official Resources

Developer Tools

Need Help?


Start building on opBNB with Dwellir's enterprise-grade RPC infrastructure. Get your API key