Summary
The BSC API (BNB Smart Chain API) is a set of JSON-RPC endpoints that allow developers to interact with the BSC network. This reference covers endpoint types, common methods, setup steps, and troubleshooting tips for production workloads.
BSC API Decision Checklist
Before integrating the BSC API, consider these key points:
- Endpoint type: Public, shared, or dedicated RPC? Public endpoints are rate-limited; dedicated nodes offer consistent performance.
- Archive vs. full node: Archive nodes provide historical state data; full nodes only recent. Choose based on your data needs.
- WebSocket support: For real-time subscriptions (e.g., pending transactions, logs), ensure your provider supports WSS.
- Rate limits: Check the allowed requests per second/second (RPS) and monthly quota. Production apps need headroom.
- Geographic latency: Select endpoints close to your user base or use a global load balancer.
- Debug and trace APIs: Required for transaction simulation and advanced monitoring; not enabled on all providers.
- Pricing model: Pay-as-you-go vs. flat fee. Estimate your call volume before committing.
See our RPC pricing and supported networks for more details.
Quick Introduction to BSC API
The BSC API refers to the JSON-RPC interface exposed by BNB Smart Chain (BSC) nodes. Because BSC is EVM-compatible, the API is almost identical to Ethereum's JSON-RPC – methods like eth_blockNumber, eth_getBalance, and eth_sendRawTransaction work the same way. This means existing Ethereum tooling (Hardhat, Foundry, viem, web3.js) can target BSC with minimal changes.
BSC adds a few BEP-specific methods for its finality mechanism and blob support. Understanding these helps you build more reliable dapps.
BSC API Endpoints Overview
BSC endpoints come in three main types:
- Public RPC: Free, but severely rate-limited (e.g., 5–10 req/s). Use only for testing.
- Shared/Service RPC: Provided by infrastructure platforms like OnFinality. Higher limits, archive data, often with WebSocket and trace APIs.
- Dedicated Node: A standalone instance with guaranteed resources, full control, and no noisy neighbours.
For production, a service RPC or dedicated node is recommended. You can find BSC endpoints on our networks page.
BSC JSON-RPC Methods
Here are the most commonly used methods grouped by category:
| Category | Key Methods | Use Case |
|---|---|---|
| Chain info | eth_chainId, eth_blockNumber, net_version | Identify network and current block |
| Account | eth_getBalance, eth_getTransactionCount | Query account state and nonce |
| Block/Transaction | eth_getBlockByNumber, eth_getTransactionReceipt, eth_getLogs | Retrieve on-chain data |
| Execution | eth_call, eth_estimateGas, eth_sendRawTransaction | Simulate and send transactions |
| Event subscription | eth_subscribe, eth_unsubscribe (WebSocket) | Real-time event streaming |
| Debug/Trace | debug_traceTransaction, trace_block | Transaction introspection |
| BSC-specific | eth_getFinalizedBlock, eth_getBlobSidecarByTxHash | Finality queries and blob data |
Most EVM libraries abstract these methods. You rarely call them directly; instead, use the library's API.
Connecting to BSC API
Here's how to connect to the BSC mainnet using curl and viem (JavaScript):
Using curl
curl -X POST https://rpc.onfinality.io/bsc \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_blockNumber",
"params": [],
"id": 1
}'
Using viem (JavaScript)
import { createPublicClient, http } from 'viem';
import { bsc } from 'viem/chains';
const client = createPublicClient({
chain: bsc,
transport: http('https://rpc.onfinality.io/bsc')
});
async function main() {
const blockNumber = await client.getBlockNumber();
console.log('Current BSC block:', blockNumber);
}
main();
WebSocket subscription
import { createPublicClient, webSocket } from 'viem';
import { bsc } from 'viem/chains';
const client = createPublicClient({
chain: bsc,
transport: webSocket('wss://rpc.onfinality.io/bsc/ws')
});
const unwatch = await client.watchBlockNumber({
onBlockNumber: (blockNumber) => console.log('New block:', blockNumber),
});
Common Pitfalls and Troubleshooting
- Rate limiting: Public endpoints often return
429 Too Many Requests. Use a service with higher limits or dedicated nodes. - Finality confirmation: BSC has probabilistic finality (~15 blocks) plus economic finality (BEP-126). For irreversible transactions, wait for
eth_getFinalizedBlockor at least 15 confirmations. - Archive data missing: If you need past states (e.g., historical token balances), ensure your endpoint has archive data enabled.
- WebSocket drops: Unstable connections can cause subscription loss. Implement reconnection logic with exponential backoff.
- Gas estimation failures: If
eth_estimateGasreverts, check the sender balance and contract logic. Useeth_callwithstateOverridefor debugging.
Deciding Between Shared vs. Dedicated BSC API
| Criterion | What to check | Why it matters |
|---|---|---|
| Throughput | Requests per second limit | Affects how many users/contracts you can serve simultaneously |
| Data retention | Archive vs. prune | Determines if you can query historical state |
| API surface | Debug/trace, WebSocket, eth_subscribe | Needed for advanced workflows (simulation, real-time data) |
| Latency | Geographic endpoint locations | Impacts user experience, especially for time-sensitive dapps |
| Uptime SLA | Provider guarantee | High availability reduces downtime risk for production apps |
| Pricing | Pay-as-you-go vs. monthly flat | Align with your budget and scaling pattern |
For small to medium workloads, a shared RPC service is cost-effective. High-volume or latency-sensitive projects benefit from dedicated nodes.
Key Takeaways
- BSC API is EVM-compatible; most Ethereum tools work unchanged on chain ID 56.
- Choose endpoints based on workload: public for testing, service RPC for production, dedicated for high throughput.
- BSC-specific methods like
eth_getFinalizedBlockhelp confirm finality faster. - Always check rate limits, archive support, and WebSocket availability before building.
- OnFinality provides BSC mainnet and testnet RPC endpoints with shared and dedicated options.
Frequently Asked Questions
What is the difference between BSC API and Ethereum API?
They are nearly identical. BSC adds a few custom methods for its finality and blob features, but all standard eth_* methods work.
Do I need an API key for BSC endpoints?
Public endpoints may not require a key but are rate-limited. For production, you'll need an API key from a provider like OnFinality to unlock higher limits and dedicated resources.
How many confirmations should I wait before considering a transaction final?
BSC's probabilistic finality suggests 15 blocks (~30 seconds). For economic finality (BEP-126), you can check eth_getFinalizedBlock which confirms in 2 blocks (~3.75 seconds).
Can I use BSC API for real-time data?
Yes, via WebSocket subscriptions (eth_subscribe). Ensure your provider supports WSS and has adequate throughput.
What if my provider doesn't support archive data?
You can either switch to a provider with archive support or run your own archive node. OnFinality offers archive endpoints for BSC.
Is there a testnet API?
Yes, BSC testnet (Chapel) is available. See our [testnet network page](/networks/bnb-testnet) for endpoints.