Summary
The BNB API refers to the JSON-RPC interface for BNB Smart Chain (BSC), an EVM-compatible network. This article explains the core methods, chain settings, and how to connect using providers like OnFinality, plus how to choose between public and dedicated endpoints.
Quick decision guide: which BNB API endpoint should you use?
Before you write any code, decide which type of BNB API endpoint fits your workload. The right choice depends on how much traffic you expect, whether you need historical data, and how much operational overhead you want to take on.
| Workload | Recommended endpoint type | Why |
|---|---|---|
| Prototyping or low traffic | Public RPC | Free, but rate limits and reliability vary |
| Production dApp with moderate traffic | Shared RPC provider | Better reliability and support, still cost-effective |
| High throughput or data-heavy app | Dedicated node | Isolated resources, no noisy neighbors, custom limits |
| Historical analysis or indexing | Archive node | Full state history, required for deep queries |
If you are building a production app, a managed RPC provider like OnFinality can save you time and reduce risk. You get reliable endpoints, multiple network options, and support without running your own infrastructure. Check RPC pricing and supported networks to see what fits your budget and needs.
What is the BNB API?
The BNB API is the set of JSON-RPC methods used to interact with BNB Smart Chain (BSC). BSC is an EVM-compatible blockchain, so the API follows the same standards as Ethereum's JSON-RPC. This means you can use familiar tools like ethers.js, viem, or direct HTTP requests to read and write data on BSC.
The API lets you:
- Query block and transaction data
- Read contract state
- Send transactions
- Subscribe to events via WebSocket
Because BSC is EVM-compatible, most Ethereum development patterns work with minimal changes. However, BSC has its own chain ID, network parameters, and some BSC-specific methods for finality and blob data.
BNB API chain settings
To connect to BNB Smart Chain, you need the correct network parameters. Here are the essential settings for both mainnet and testnet:
| Parameter | BNB Smart Chain Mainnet | BNB Smart Chain Testnet |
|---|---|---|
| Chain ID | 56 | 97 |
| Network name | BNB Smart Chain | BNB Smart Chain Testnet |
| Currency symbol | BNB | tBNB |
| Block explorer | BscScan | BscScan Testnet |
| Public RPC URL | https://bsc-dataseed.bnbchain.org | https://data-seed-prebsc-1-s1.bnbchain.org |
| WebSocket URL | wss://bsc-ws-node.nariber.org | wss://bsc-testnet-ws.nariber.org |
For production, you should not rely on public RPC URLs. They are rate-limited and can be unreliable. Instead, use a managed provider like OnFinality. You can find the latest endpoint details on the BNB Chain network page and the BNB testnet page.
Core BNB API methods
The BNB API supports standard Ethereum JSON-RPC methods. Here are the most commonly used ones:
eth_blockNumber– get the latest block numbereth_getBalance– get the balance of an addresseth_call– execute a read-only contract calleth_sendRawTransaction– broadcast a signed transactioneth_getTransactionReceipt– get the receipt of a transactioneth_getLogs– query event logseth_subscribe– subscribe to events (WebSocket only)
BSC also has some network-specific methods, such as eth_getFinalizedBlock and eth_getBlobSidecarByTxHash, which are documented in the official BNB Chain docs.
Connecting to the BNB API with curl
You can test the BNB API with a simple curl request. Here's an example that gets the latest block number:
curl -X POST https://bnb-mainnet.g.alchemy.com/v2/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'
Replace the URL with your provider's endpoint. If you're using OnFinality, you'll get a dedicated URL from your dashboard.
Using the BNB API with viem
If you're building a JavaScript dApp, viem is a popular library. Here's how to set up a client for BNB Smart Chain:
import { createPublicClient, http } from 'viem';
import { bsc } from 'viem/chains';
const client = createPublicClient({
chain: bsc,
transport: http('https://bnb-mainnet.g.alchemy.com/v2/YOUR_API_KEY'),
});
const blockNumber = await client.getBlockNumber();
console.log('Current block number:', blockNumber);
For testnet, use the bscTestnet chain from viem and a testnet endpoint.
BNB API vs. Binance exchange API
It's easy to confuse the BNB API with the Binance exchange API. The Binance API is for trading on the Binance exchange – placing orders, checking balances, and accessing market data. The BNB API is for interacting with the BNB Smart Chain blockchain itself – reading and writing on-chain data.
If you're building a dApp, you need the BNB API. If you're building a trading bot, you need the Binance API. They are separate systems with different authentication and rate limits.
Common pitfalls and troubleshooting
Even with the right endpoint, you may run into issues. Here are some common problems and how to fix them:
- Rate limiting: Public RPCs often limit requests per second. If you hit limits, switch to a paid provider or implement caching.
- Incorrect chain ID: Make sure you use chain ID 56 for mainnet and 97 for testnet. A wrong chain ID will cause transaction failures.
- WebSocket disconnects: WebSocket connections can drop. Implement reconnection logic in your client.
- Missing archive data: If you need historical state, you need an archive node. Standard nodes only keep recent state.
- Transaction not found: If a transaction isn't found, it may not have been mined yet. Wait a few seconds and retry.
How to choose a BNB API provider
When evaluating a BNB API provider, consider these factors:
- Reliability: Look for providers with a track record of uptime, but avoid absolute claims. Check their status page.
- Throughput: What are the rate limits? Do they offer dedicated nodes for high traffic?
- Archive data: Do they provide archive nodes? This is crucial for analytics and indexing.
- WebSocket support: Do they support WebSocket subscriptions? Needed for real-time dApps.
- Pricing: Compare costs. OnFinality offers transparent RPC pricing and a free tier.
- Support: Is there documentation and responsive support?
OnFinality provides managed BNB Chain RPC endpoints with both shared and dedicated options. You can get started quickly and scale as your project grows.
Key Takeaways
- The BNB API is the JSON-RPC interface for BNB Smart Chain, compatible with Ethereum tooling.
- Use the correct chain ID (56 for mainnet, 97 for testnet) and network parameters.
- Public RPCs are fine for testing, but production apps should use a reliable provider.
- Choose between shared and dedicated nodes based on your traffic and data needs.
- OnFinality offers BNB Chain RPC endpoints with flexible pricing and support.
Frequently Asked Questions
What is the BNB API?
The BNB API is the JSON-RPC interface for BNB Smart Chain, allowing developers to interact with the blockchain using standard Ethereum methods.
Is the BNB API the same as the Binance exchange API?
No. The Binance exchange API is for trading on the exchange, while the BNB API is for interacting with the BNB Smart Chain blockchain.
What chain ID does BNB Smart Chain use?
BNB Smart Chain mainnet uses chain ID 56, and testnet uses chain ID 97.
Do I need an archive node for BNB?
If you need historical state data, yes. Archive nodes store the full state history, which is required for certain analytics and indexing use cases.
How do I get a BNB API endpoint?
You can use public RPCs, but for production, consider a managed provider like OnFinality. Sign up for an API key and get a dedicated endpoint.