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

BSC API: JSON-RPC Methods, WebSocket, Finality & Examples

Summary

The BSC API is the JSON-RPC interface for BNB Smart Chain (BSC), an EVM-compatible network with mainnet chain ID 56 and testnet chain ID 97. Developers use standard Ethereum-style methods such as eth_blockNumber, eth_getBalance, eth_call, eth_getLogs, and eth_sendRawTransaction, plus BSC-specific finality methods like eth_getFinalizedHeader, eth_getFinalizedBlock, and eth_newFinalizedHeaderFilter. OnFinality exposes EVM-compatible HTTPS and WebSocket endpoints for BSC, including a public mainnet endpoint at https://bnb.api.onfinality.io/public and a public testnet endpoint at https://bnb-testnet.api.onfinality.io/public. For production workloads, use your OnFinality API key and private endpoint from the dashboard. This page covers method categories, finality behavior, WebSocket subscriptions, and curl/viem examples. Use the official BNB public endpoints only for testing: the public list rate limit is 10K/5min and eth_getLogs is disabled on listed mainnet endpoints; OnFinality endpoints are managed separately and should be validated against your plan.

Key Takeaways

  • BSC API is EVM-compatible: standard eth_* methods work with chain ID 56 mainnet and 97 testnet.
  • Use BSC-specific finality methods (eth_getFinalizedHeader/Block) for economic finality, not just block depth.
  • WebSocket subscriptions reduce polling for new blocks, logs, and pending transactions where supported.
  • Validate endpoint method coverage (archive, trace, debug, finality) and use placeholders for API keys in examples.

BSC API Quick Reference

The BSC API follows Ethereum JSON-RPC conventions on BNB Smart Chain. Mainnet uses chain ID 56 (0x38) and BNB as the native asset; testnet uses chain ID 97 (0x61) and tBNB. Because BSC is EVM-compatible, existing libraries like viem, ethers, and web3.js work with only the RPC URL changed.

OnFinality provides EVM-compatible HTTPS and WebSocket endpoints for BSC. Public mainnet: https://bnb.api.onfinality.io/public. Public testnet: https://bnb-testnet.api.onfinality.io/public. For production, create an API key and use your private endpoint from the OnFinality dashboard. Do not hardcode credentials; use environment variables.

CriterionWhat to checkWhy it matters
Mainnet chain ID56 / 0x38Set correctly in wallets and clients to avoid transaction failures
Testnet chain ID97 / 0x61Use for Chapel testnet deployments and tBNB faucets
Endpoint typeHTTPS and WebSocket availabilityRequired for subscriptions and live data without polling
Finality methodseth_getFinalizedHeader, eth_getFinalizedBlockConfirms economic finality sooner than block depth alone

Standard eth_* JSON-RPC Methods for BSC

The BSC API supports standard Ethereum JSON-RPC methods. The most common groups are chain info, account state, block/transaction data, contract execution, and event logs. Use these before reaching for proprietary APIs.

CriterionWhat to checkWhy it matters
Chain infoeth_chainId, eth_blockNumber, net_versionIdentify network and current block height
Account stateeth_getBalance, eth_getTransactionCountCheck balances and nonces
Blocks/transactionseth_getBlockByNumber, eth_getBlockByHash, eth_getTransactionByHash, eth_getTransactionReceiptRetrieve block and transaction data
Contracts/callseth_call, eth_estimateGasSimulate reads and estimate execution
Logseth_getLogsQuery event logs by address, topics, block range

eth_call, eth_getLogs, Block & Transaction Retrieval, and Troubleshooting

Use eth_call for read-only contract interactions. Pass a transaction object with to and data, and a block parameter such as latest or a specific block number. The response is the encoded return data. For historical state, providers must support archive data; otherwise, calls against past blocks may fail. OnFinality BSC mainnet configuration includes archive support, but verify your plan.

eth_getLogs is central for event indexing. On the official public BNB mainnet endpoints, eth_getLogs is disabled according to BNB Chain docs; attribute that limitation to the public list and do not assume the same for OnFinality. Managed providers typically enable logs but may enforce range limits. Use block ranges and topic filters to reduce response size.

When retrieving transactions, start with eth_getTransactionByHash, then eth_getTransactionReceipt for status and logs. If you receive null, the transaction may still be pending or not yet indexed. Polling works, but WebSocket subscriptions reduce latency.

BSC-Specific Finality Methods

BNB Smart Chain implements a dual-layer finality mechanism. Economic Finality provides fast finality through a slashing mechanism, while Probabilistic Finality is fallback based on block depth. The API exposes methods to query finalized state directly.

Use eth_getFinalizedHeader to get the latest finalized block header, eth_getFinalizedBlock to get the full finalized block, and eth_newFinalizedHeaderFilter to create a filter that tracks new finalized headers. These methods help confirm irreversibility sooner than waiting for a large confirmation count. Treat them as BSC-specific extensions beyond standard Ethereum.

CriterionWhat to checkWhy it matters
eth_getFinalizedHeaderLatest finalized block headerLightweight finality check
eth_getFinalizedBlockLatest finalized block objectConfirm irreversible block data
eth_newFinalizedHeaderFilterFilter ID for finalized header notificationsPoll finality updates without scanning

WebSocket Subscriptions for Real-Time Events

Use WebSocket subscriptions (eth_subscribe) for newHeads, logs, and newPendingTransactions instead of polling when your application needs low-latency updates. WebSockets maintain a persistent connection, reducing request overhead and avoiding rate-limit pressure from repeated polling.

Choose polling when events are infrequent, you need historical ranges, or the provider does not expose WSS. For high-frequency event streams such as DEX swaps or oracle updates, subscriptions are usually the better path. Implement reconnection with exponential backoff because connections can drop.

``ts import { createPublicClient, webSocket } from 'viem'; import { bsc } from 'viem/chains'; const client = createPublicClient({ chain: bsc, transport: webSocket('wss://YOUR_ONFINALITY_WS_ENDPOINT'), }); const unwatch = client.watchBlockNumber({ onBlockNumber: (blockNumber) => console.log('New block:', blockNumber), }); ``

curl and viem Examples with Safe Placeholders

Always replace placeholders with your own OnFinality endpoint and credentials. The examples below use https://bnb.api.onfinality.io/public for public read-only calls and YOUR_API_KEY for authenticated access. Never commit API keys to source control.

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

``ts 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(blockNumber); ``

BSC Health, Transaction, Receipt, and Trace/Debug Methods

The inspected official BSC API documentation includes eth_health to check node health, eth_getTransactionsByBlockNumber to fetch transactions by block number, and eth_getTransactionDataAndReceipt to combine transaction and receipt data in one call. Use these when they simplify your workflow; test them against your provider before relying on them.

Trace and debug methods such as debug_traceTransaction or trace_block are not part of standard JSON-RPC; availability depends on the provider. OnFinality's BNB mainnet configuration states that trace/API access is provided, but confirm the exact method names and plan eligibility from your OnFinality dashboard. Do not assume every public endpoint supports them.

Endpoint Selection and Operational Checks

When moving beyond public endpoints, evaluate providers using workload fit, method support, WebSocket availability, archive data, and finality support. Use the BNB Chain network page to compare OnFinality options: /networks/bnb.

For dedicated setup, start with the endpoint guide /rpc-assistant/bnb-smart-chain-endpoint. For provider selection, review /rpc-assistant/bnb-chain-rpc-provider. For developer workflow, use /rpc-assistant/binance-smart-chain-developer.

  • Confirm mainnet chain ID 56 and testnet chain ID 97 before sending transactions.
  • Test eth_getFinalizedBlock and eth_getLogs against your actual endpoint with realistic block ranges.
  • Check whether your plan includes archive data for historical eth_call or trace/debug methods.
  • Use WebSocket subscriptions only when real-time events justify persistent connections; otherwise poll with sensible intervals.
  • Keep credentials in environment variables and rotate API keys regularly.

Frequently Asked Questions

What is the BSC API?

The BSC API is the JSON-RPC interface for BNB Smart Chain. It uses EVM-compatible methods for reading chain data, sending transactions, and interacting with contracts, plus BSC-specific finality methods.

How do I connect to BSC mainnet vs testnet?

Use chain ID 56 (0x38) for mainnet and 97 (0x61) for testnet. OnFinality public endpoints are https://bnb.api.onfinality.io/public for mainnet and https://bnb-testnet.api.onfinality.io/public for testnet. For production, use a private endpoint with an API key.

Which WebSocket subscription methods are supported for BSC?

Standard Ethereum subscriptions like eth_subscribe for newHeads, logs, and newPendingTransactions are supported where the provider offers WebSocket endpoints. Check your OnFinality endpoint for WSS URLs and plan support.

What are eth_getFinalizedHeader and eth_getFinalizedBlock?

They return the latest finalized block header and block object, respectively. These BSC-specific methods help applications determine economic finality sooner than waiting for many confirmations.

How do I use eth_getLogs reliably on BSC?

Use block ranges and topic filters to limit results. Note that the official public BNB mainnet endpoints disable eth_getLogs; managed providers like OnFinality typically support it, but validate against your actual endpoint.

Do OnFinality BSC endpoints require an API key?

Public endpoints at https://bnb.api.onfinality.io/public and https://bnb-testnet.api.onfinality.io/public are available without a key, but for production you should use a private endpoint with an API key to access higher limits and avoid public congestion.

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