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

Binance Chain API: How to Connect to BNB Smart Chain RPC Endpoints

Summary

Learn how to connect to BNB Smart Chain (Binance Chain) using RPC APIs. This guide covers chain settings, public endpoints, and how to choose between public, managed, and dedicated node infrastructure for your dApps.

Quick Decision: Which BNB Chain API Setup Fits Your Project?

Before you write any code, decide how you will access the BNB Smart Chain. The right choice depends on your workload, your tolerance for rate limits, and whether you need historical data.

  • Prototyping or light usage: Use a public RPC endpoint like https://bnb.api.onfinality.io/public. It is free and fine for development, but it is shared and may have rate limits.
  • Production dApp or backend: Use a managed RPC service with higher throughput and reliability. OnFinality offers managed endpoints with access to archive data and WebSocket support.
  • High-throughput or data-heavy workloads: Consider a dedicated node. If you need to run many eth_getLogs queries, process large batches, or require consistent performance, dedicated infrastructure gives you isolated resources.

If you are unsure, start with a managed service and scale to a dedicated node when you hit limits. For more details on evaluating providers, see our guide on choosing an RPC provider.

What Is the Binance Chain API?

The Binance Chain API typically refers to the RPC interface for BNB Smart Chain (BSC), the EVM-compatible blockchain that runs alongside the original Binance Chain. Developers use this API to read and write data to the chain: sending transactions, querying balances, fetching logs, and more.

BNB Smart Chain uses the Ethereum JSON-RPC standard, so any Ethereum tooling—ethers.js, viem, web3.js—works with BSC. The chain ID is 56 for mainnet and 97 for testnet.

Chain Settings at a Glance

Here are the key parameters you need to configure your wallet or dApp for BNB Smart Chain:

ParameterMainnetTestnet
Chain ID5697
Network NameBNB Smart Chain MainnetBNB Smart Chain Testnet
Native CurrencyBNBtBNB
Block Explorerbscscan.comtestnet.bscscan.com
Public RPC URLhttps://bnb.api.onfinality.io/publichttps://bnb-testnet.api.onfinality.io/public

These settings are essential for connecting wallets, deploying contracts, and running scripts.

How to Connect to BNB Smart Chain with ethers.js

Here is a simple example using ethers.js to connect to BNB Smart Chain and read the latest block number:

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

getBlockNumber();

For WebSocket support, you can use a WebSocket URL if your provider offers one. OnFinality supports WebSocket on BNB Smart Chain; check the network page for details.

Public vs. Managed vs. Dedicated: What Developers Should Compare

When you search for a Binance Chain API, you will find public endpoints, managed services, and dedicated node offerings. Here is how to compare them:

FactorPublic EndpointManaged RPC ServiceDedicated Node
CostFreeUsage-based or subscriptionHigher, predictable
Rate LimitsStrictHigher, configurableNone (within node capacity)
ReliabilityBest-effortSLA-backedIsolated resources
Archive DataUsually notOften availableOptional
WebSocketRarelyYesYes
Best ForDevelopmentProduction dAppsHigh-throughput workloads

Public endpoints are convenient but can throttle your requests. Managed services like OnFinality offer a balance of performance and ease. Dedicated nodes give you full control and are ideal for applications that need consistent, high-volume access.

Using the BNB Chain API for Common Tasks

Here are some common JSON-RPC calls you might make with the BNB Chain API:

Get BNB Balance

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

Get Transaction Receipt

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

Subscribe to New Blocks (WebSocket)

If you have a WebSocket endpoint, you can subscribe to new block headers:

const { WebSocket } = require("ws");

const ws = new WebSocket("wss://your-websocket-endpoint");

ws.on("open", () => {
  ws.send(JSON.stringify({
    jsonrpc: "2.0",
    method: "eth_subscribe",
    params: ["newHeads"],
    id: 1
  }));
});

ws.on("message", (data) => {
  console.log("New block:", JSON.parse(data));
});

Common Pitfalls and How to Avoid Them

  • Using the wrong chain ID: Always double-check that you are using 56 for mainnet and 97 for testnet. Mixing them up can cause transactions to fail or be sent to the wrong network.
  • Rate limiting: Public endpoints often limit requests. If you see 429 errors, consider upgrading to a managed service or dedicated node.
  • Missing archive data: Some methods like eth_getLogs with old block ranges require archive nodes. If you need historical data, ensure your provider offers archive access.
  • WebSocket not supported: Not all endpoints support WebSocket. If you need real-time updates, verify that your provider supports it.

Testing on BNB Chain Testnet

Before deploying to mainnet, test your application on the BNB Chain testnet. Use the testnet RPC endpoint https://bnb-testnet.api.onfinality.io/public and get test BNB from a faucet. The chain ID is 97.

Here is how to configure a wallet for the testnet:

{
  "chainId": "97",
  "chainName": "BNB Smart Chain Testnet",
  "nativeCurrency": {
    "name": "BNB Chain Native Token",
    "symbol": "tBNB",
    "decimals": 18
  },
  "rpcUrls": ["https://bnb-testnet.api.onfinality.io/public"],
  "blockExplorerUrls": ["https://testnet.bscscan.com"]
}

Key Takeaways

  • The Binance Chain API is the RPC interface for BNB Smart Chain, an EVM-compatible network.
  • Use chain ID 56 for mainnet and 97 for testnet.
  • Public endpoints are fine for development, but production apps should consider managed or dedicated infrastructure.
  • OnFinality provides public, managed, and dedicated options for BNB Smart Chain. See RPC pricing and supported networks for more.
  • Always test on the testnet before deploying to mainnet.

Frequently Asked Questions

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

Binance Chain is the original chain used for fast trading, while BNB Smart Chain is an EVM-compatible chain that supports smart contracts. The Binance Chain API usually refers to BNB Smart Chain's RPC.

Can I use Ethereum tools with BNB Smart Chain?

Yes, because BNB Smart Chain is EVM-compatible, you can use ethers.js, viem, web3.js, and other Ethereum libraries.

How do I get test BNB for the testnet?

You can get test BNB from a faucet. Search for "BNB testnet faucet" or check the BNB Chain testnet page for resources.

What is an archive node?

An archive node stores the full historical state of the blockchain, allowing queries like eth_getLogs for old blocks. Managed services often offer archive endpoints for a fee.

Does OnFinality support WebSocket on BNB Smart Chain?

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

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