Logo
New RPC users get 35% off their first monthView the offer
RPC Assistant

What is the BNB Smart Chain RPC URL and how do I use it?

Summary

The BNB Smart Chain (BSC) RPC URL is the endpoint your dApp, wallet, or script uses to send JSON-RPC requests to the BSC network. The official OnFinality public endpoint is https://bnb.api.onfinality.io/public. This article explains how to configure it, what to check when choosing an RPC provider, and how to debug common issues.

Quick answer: the BNB Smart Chain RPC URL

The BNB Smart Chain (BSC) RPC URL is the endpoint your application uses to communicate with the BSC network via JSON-RPC. The official OnFinality public endpoint is:

https://bnb.api.onfinality.io/public

This URL works for both HTTP and WebSocket connections. You can use it in MetaMask, Hardhat, ethers.js, viem, or any other Web3 tool that supports custom RPC endpoints.

Chain settings at a glance

Before you connect, make sure your configuration matches the BSC mainnet parameters:

SettingValue
Network nameBNB Smart Chain Mainnet
Chain ID56
Native currencyBNB (18 decimals)
Block explorerhttps://bscscan.com
RPC URL (OnFinality)https://bnb.api.onfinality.io/public
WebSocket URLwss://bnb.api.onfinality.io/public/ws

For testnet development, use the BNB Chain Testnet with chain ID 97 and the endpoint https://bnb-testnet.api.onfinality.io/public.

How to configure the RPC URL in a wallet

If you want to add BSC to MetaMask or another wallet, use the chain settings above. Here is an example for MetaMask:

  1. Open MetaMask and click the network dropdown.
  2. Click Add Network.
  3. Fill in the details:
  4. Click Save.

Now your wallet can interact with BSC.

Using the RPC URL in code

Here is how to use the endpoint with ethers.js and viem.

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:", blockNumber);
}

getBlockNumber();

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:', blockNumber);

Public vs. managed RPC: which should you use?

Public RPC endpoints like the one above are great for development, testing, and low-traffic applications. However, they are shared across many users, which can lead to rate limiting and slower responses during peak times.

For production applications, you should consider a managed RPC provider. OnFinality offers RPC pricing and supported RPC networks that include BSC. Managed endpoints provide higher reliability, better performance, and dedicated options.

How to choose an RPC provider for BSC

When evaluating RPC providers for BSC, consider these factors:

CriterionWhat to checkWhy it matters
Uptime and reliabilityHistorical uptime, SLAsDowntime means your dApp is unavailable
Throughput and rate limitsRequests per second, burst capacityHigh-traffic apps need headroom
Archive dataDoes the provider offer archive nodes?Needed for historical queries and analytics
WebSocket supportDoes it support wss://?Required for real-time subscriptions
Dedicated optionsCan you get a dedicated node?Isolates your traffic from noisy neighbors
Pricing modelPay-as-you-go vs. subscriptionPredictable costs for your budget

OnFinality offers both shared and dedicated BSC nodes. For high-throughput workloads, a dedicated node gives you more consistent performance. See our BNB Chain RPC provider comparison for more details.

Common RPC errors and how to debug them

Here are some common issues you might encounter when using a BSC RPC URL:

ErrorLikely causeFix
connection refusedWrong URL or network issueCheck the URL and your internet connection
rate limit exceededToo many requests on a shared endpointUse a managed provider or add retry logic
invalid chain idWrong chain ID in your configSet chain ID to 56 for mainnet
method not foundUsing an unsupported JSON-RPC methodCheck the provider's method support
timeoutSlow network or overloaded providerIncrease timeout or use a dedicated node

Debugging with curl

You can test your RPC endpoint with a simple curl command:

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

A successful response looks like:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "0x1a2b3c"
}

WebSocket subscriptions

For real-time data, use the WebSocket endpoint. Here is an example with ethers.js:

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

const provider = new ethers.WebSocketProvider("wss://bnb.api.onfinality.io/public/ws");

provider.on("block", (blockNumber) => {
  console.log("New block:", blockNumber);
});

Key Takeaways

  • The BNB Smart Chain RPC URL is the gateway to BSC for your dApp or wallet.
  • The OnFinality public endpoint is https://bnb.api.onfinality.io/public.
  • Always verify chain ID (56) and other settings when configuring your environment.
  • For production, consider a managed RPC provider for better reliability and performance.
  • Use the debugging tips above to resolve common RPC issues quickly.

Frequently Asked Questions

What is the BNB Smart Chain RPC URL?

The official OnFinality public RPC URL is https://bnb.api.onfinality.io/public. It supports HTTP and WebSocket.

Can I use the BSC RPC URL for free?

Yes, the public endpoint is free for development and light usage. For production, check RPC pricing for managed options.

What is the BSC testnet RPC URL?

The BNB Chain Testnet RPC URL is https://bnb-testnet.api.onfinality.io/public with chain ID 97.

How do I add BSC to MetaMask?

Use the chain settings provided in this article to add BSC as a custom network.

What should I do if I get rate limited?

Switch to a managed RPC provider or implement retry logic with exponential backoff. OnFinality offers scalable options for production workloads.

RPC Knowledge Base

Related RPC details

Never Worry about Infrastructure Again

OnFinality takes away the heavy lifting of DevOps so you can build smarter and faster.

Get Started