Logo
RPC Assistant

What is the BNB Smart Chain API and how do you use it?

Summary

The BNB Smart Chain API is a JSON-RPC interface that lets you interact with the BNB Smart Chain (BSC) network—reading balances, sending transactions, and querying blocks and logs. Because BSC is EVM-compatible, you can use familiar Ethereum methods and tools like ethers and viem. This guide covers the essential endpoints, chain settings, and how to choose a reliable RPC provider for production apps.

Quick Answer: What Is the BNB Smart Chain API?

The BNB Smart Chain API is a set of JSON-RPC endpoints that let applications read and write data on BNB Smart Chain (BSC). It follows the Ethereum JSON-RPC standard, so if you've used eth_getBalance or eth_sendRawTransaction on Ethereum, you already know how to use BSC. The API is the bridge between your dApp and the chain—whether you're fetching a token balance, submitting a swap, or listening for new blocks.

Decision Guide: Choosing the Right BNB Smart Chain API Access

Before you start coding, decide how your app will connect to BSC. The choice affects latency, reliability, and cost. Here's a quick framework:

  • Prototyping or hackathon: Use a public RPC endpoint. It's free and fine for light testing, but it may rate-limit or become unreliable under load.
  • Production dApp with moderate traffic: Use a managed RPC provider. You get stable endpoints, higher throughput, and support. OnFinality offers BNB Smart Chain RPC endpoints with predictable pricing and a list of supported networks.
  • High-throughput or data-heavy workloads: Consider a dedicated node. You get exclusive access, no noisy neighbors, and the ability to run archive or trace queries without impacting other users.
  • Need WebSocket for real-time updates: Ensure your provider supports WSS endpoints. Most managed providers do, but public endpoints often don't.

Chain Settings at a Glance

When configuring your wallet or dApp, you'll need these BSC network parameters:

ParameterMainnetTestnet
Chain ID5697
CurrencyBNBtBNB
RPC URLhttps://bsc-dataseed.binance.org/ (public)https://data-seed-prebsc-1-s1.binance.org:8545/ (public)
Block explorerhttps://bscscan.comhttps://testnet.bscscan.com

For production, replace the public URL with a managed endpoint from a provider like OnFinality. You can find the official BSC endpoints in the BNB Chain docs.

Essential JSON-RPC Methods for BSC

Because BSC is EVM-compatible, the core methods are identical to Ethereum. Here are the ones you'll use most:

  • eth_blockNumber – get the latest block number
  • eth_getBalance – get the balance of an address
  • eth_call – execute a read-only contract call
  • eth_sendRawTransaction – broadcast a signed transaction
  • eth_getTransactionReceipt – get the receipt of a transaction
  • eth_getLogs – fetch event logs
  • eth_estimateGas – estimate gas for a transaction

BSC also has some BEP-specific methods, like eth_getFinalizedBlock for fast finality (BEP-126). Check the official API list for the full reference.

Making Your First Request with cURL

You can test any RPC endpoint with a simple cURL command. Replace YOUR_RPC_URL with your endpoint.

curl -X POST YOUR_RPC_URL \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "eth_blockNumber",
    "params": [],
    "id": 1
  }'

Expected response:

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

The result is a hex-encoded block number. Convert it to decimal to get the human-readable number.

Using the API with ethers.js or viem

If you're building a JavaScript dApp, use a library like ethers or viem. Here's an example with viem:

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

const client = createPublicClient({
  chain: bsc,
  transport: http('YOUR_RPC_URL'),
});

const blockNumber = await client.getBlockNumber();
console.log('Current block number:', blockNumber);

const balance = await client.getBalance({
  address: '0x...',
});
console.log('Balance (BNB):', Number(balance) / 1e18);

With ethers v6:

import { ethers } from 'ethers';

const provider = new ethers.JsonRpcProvider('YOUR_RPC_URL');
const blockNumber = await provider.getBlockNumber();
console.log('Current block number:', blockNumber);

WebSocket Subscriptions for Real-Time Data

For live updates—like new blocks or pending transactions—use WebSocket. Most managed providers offer WSS endpoints.

import { createPublicClient, webSocket } from 'viem';
import { bsc } from 'viem/chains';

const client = createPublicClient({
  chain: bsc,
  transport: webSocket('wss://YOUR_WSS_URL'),
});

const unwatch = client.watchBlockNumber({
  onBlockNumber: (blockNumber) => {
    console.log('New block:', blockNumber);
  },
});

Common Pitfalls and How to Avoid Them

  • Rate limiting: Public endpoints often throttle requests. If you hit 429 errors, switch to a managed provider or implement retry logic.
  • Chain ID mismatch: Ensure your app uses chain ID 56 for mainnet and 97 for testnet. A wrong chain ID will cause transaction failures.
  • Gas estimation: BSC gas prices can spike during congestion. Use eth_estimateGas and set a reasonable gas limit to avoid failed transactions.
  • Finality: BSC has fast finality (BEP-126), but not all nodes support the new finality methods. If you rely on finality, check your provider's support.
  • WebSocket disconnects: Implement reconnection logic to handle dropped connections.

Production Readiness Checklist

Before you ship, verify these points:

  • Use a managed RPC provider with a reliable SLA, not a public endpoint.
  • Set up monitoring for RPC errors and latency.
  • Implement fallback to a secondary provider in case of outage.
  • Use WebSocket for real-time features, but with reconnection handling.
  • Test on BNB testnet first.
  • Review RPC pricing to choose the right plan for your traffic.

Key Takeaways

  • The BNB Smart Chain API is EVM-compatible, so you can reuse Ethereum tooling.
  • Choose your access method based on your workload: public for testing, managed for production, dedicated for high throughput.
  • Use the correct chain ID and testnet endpoints during development.
  • Monitor your RPC usage and plan for rate limits.

Frequently Asked Questions

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

BNB Smart Chain is an EVM-compatible blockchain for smart contracts and dApps, while BNB Beacon Chain handles staking and governance. The API for BSC is what you'll use for most development.

Can I use Ethereum libraries with BSC?

Yes, because BSC is EVM-compatible, you can use ethers, viem, web3.js, and other Ethereum libraries with the BSC API.

What is the BSC testnet API?

It's the same JSON-RPC API but on the testnet network (chain ID 97). Use it to test your dApp without real funds. OnFinality provides BNB testnet RPC endpoints.

How do I get a BNB Smart Chain API key?

You don't need a key for public endpoints, but for production, you'll want a managed provider. OnFinality offers API keys through its API service.

What is the cost of using the BNB Smart Chain API?

Public endpoints are free but unreliable. Managed providers charge based on usage. Check RPC pricing for details.

How do I choose between a shared and dedicated node?

Shared nodes are cost-effective for most apps. Dedicated nodes are better for high traffic, data-intensive workloads, or when you need archive data. See dedicated node options.

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