DEV Community

OnFinality
OnFinality

Posted on Originally published at onfinality.io

BNB Smart Chain RPC URL: Mainnet & Testnet Endpoints

Quick Answer: BNB Smart Chain RPC URL

The public RPC URL for BNB Smart Chain (mainnet) is:

https://bnb.api.onfinality.io/public
Enter fullscreen mode Exit fullscreen mode

This endpoint is operated by OnFinality and allows you to send JSON-RPC requests to the BNB Smart Chain network without running your own node. It supports both HTTP and WebSocket transports.

For the BNB Smart Chain testnet, the public RPC URL is:

https://bnb-testnet.api.onfinality.io/public
Enter fullscreen mode Exit fullscreen mode

Use the testnet endpoint for development and testing before deploying to mainnet.

Chain Settings at a Glance

When configuring your wallet or dApp, you need the following network details for BNB Smart Chain mainnet:

Setting Value
Network Name BNB Smart Chain Mainnet
RPC URL https://bnb.api.onfinality.io/public
Chain ID 56
Currency Symbol BNB
Block Explorer https://bscscan.com

For the testnet, use:

Setting Value
Network Name BNB Smart Chain Testnet
RPC URL https://bnb-testnet.api.onfinality.io/public
Chain ID 97
Currency Symbol tBNB
Block Explorer https://testnet.bscscan.com

How to Connect to BNB Smart Chain

Using MetaMask

  1. Open MetaMask and click the network selector at the top.
  2. Click Add Network.
  3. Enter the mainnet settings from the table above.
  4. Save and switch to the new network.

Using ethers.js

const { ethers } = require("ethers");

const provider = new ethers.JsonRpcProvider("https://bnb.api.onfinality.io/public");

async function getBlockNumber() {
  const blockNumber = await provider.getBlockNumber();
  console.log("Current block number:", blockNumber);
}

getBlockNumber();
Enter fullscreen mode Exit fullscreen mode

Using viem

import { createPublicClient, http } from "viem";
import { bsc } from "viem/chains";

const client = createPublicClient({
  chain: bsc,
  transport: http("https://bnb.api.onfinality.io/public"),
});

const blockNumber = await client.getBlockNumber();
console.log("Current block number:", blockNumber);
Enter fullscreen mode Exit fullscreen mode

Public vs. Managed vs. Dedicated RPC

The public RPC URL is a shared endpoint that is free to use, but it has rate limits and is not suitable for production applications with high traffic. For production, you have two main options:

  • Managed RPC: OnFinality provides managed RPC endpoints with higher rate limits, archive data, and WebSocket support. You pay per request and can scale as needed.
  • Dedicated Node: A dedicated node gives you exclusive access to a BNB Smart Chain node, with clear rate limits and full control over the node configuration. This is ideal for high-throughput workloads.

Decision Guide: Which Option Should You Choose?

Workload Recommended Option
Quick prototyping, hackathons Public RPC
Production dApp with moderate traffic Managed RPC
High-frequency trading, indexing, analytics Dedicated Node
Need archive data or trace methods Managed RPC with archive support

If you are unsure, start with the public RPC for development, then move to a managed or dedicated solution as your traffic grows. OnFinality offers both managed RPC and dedicated nodes for BNB Smart Chain. See RPC pricing for details.

Common RPC Methods for BNB Smart Chain

BNB Smart Chain is Ethereum-compatible, so you can use standard Ethereum JSON-RPC methods. Here are a few common ones:

  • eth_blockNumber – get the latest block number
  • eth_getBalance – get the balance of an address
  • eth_call – execute a read-only contract call
  • eth_getLogs – fetch logs for a contract or topic
  • eth_sendRawTransaction – broadcast a signed transaction

Example using curl:

curl -X POST https://bnb.api.onfinality.io/public \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'
Enter fullscreen mode Exit fullscreen mode

Troubleshooting Connection Issues

If you cannot connect to the RPC URL, check the following:

  • Network configuration: Ensure the chain ID and RPC URL are correct.
  • Rate limits: Public endpoints have rate limits. If you get 429 Too Many Requests, wait and retry, or use a managed endpoint.
  • CORS: If you are calling from a browser, the endpoint must support CORS. OnFinality public endpoints do.
  • WebSocket: For real-time updates, use the WebSocket URL: wss://bnb.api.onfinality.io/public/ws (check the exact URL on the BNB Chain network page).

Key Takeaways

  • The public RPC URL for BNB Smart Chain mainnet is https://bnb.api.onfinality.io/public.
  • The testnet RPC URL is https://bnb-testnet.api.onfinality.io/public.
  • Use the correct chain ID: 56 for mainnet, 97 for testnet.
  • For production, consider managed RPC or dedicated nodes to avoid rate limits and get better performance.
  • OnFinality supports both HTTP and WebSocket for BNB Smart Chain.

Frequently Asked Questions

What is the RPC URL for Binance Smart Chain?

The public RPC URL is https://bnb.api.onfinality.io/public. For the testnet, use https://bnb-testnet.api.onfinality.io/public.

Can I use the public RPC for production?

The public RPC is rate-limited and not recommended for production. Use a managed RPC or dedicated node for reliable performance.

How do I add BNB Smart Chain to MetaMask?

Use the network settings from the table above: RPC URL, chain ID 56, symbol BNB, and explorer https://bscscan.com.

Does OnFinality support WebSocket for BNB Smart Chain?

Yes, OnFinality supports WebSocket for BNB Smart Chain. Check the network page for the exact WebSocket URL.

What is the difference between BNB Smart Chain and BNB Chain?

BNB Smart Chain is the EVM-compatible blockchain that runs in parallel with BNB Beacon Chain. The RPC URL in this article is for BNB Smart Chain mainnet.

For more information on supported networks, see supported RPC networks.

Related resources

Originally published at OnFinality.

Top comments (0)