BNB Smart Chain (BSC)
Binance Smart Chain API Reference for fast and low-cost interaction with BSC nodes, enabling scalable decentralized applications and seamless smart contract execution.
GetBlock provides RPC endpoints that implement the Ethereum JSON-RPC API standard, which is also adopted by BNB Smart Chain (BSC). This means that all the core methods for interacting with BSC nodes follow this standard. Due to its compatibility with Ethereum, developers can use familiar methods to work with EVM-based networks such as BNB Chain, Polygon, Arbitrum, and others.
Overview of BNB Smart Chain Methods
BNB Smart Chain offers a comprehensive suite of methods that allow developers to efficiently interact with its blockchain infrastructure. This overview organizes the methods into key functional categories for easier understanding and implementation. What you can expect to find in this documentation
Compatibility with the BNB Smart Chain mainnet and testnet
Purpose, functionality, and use cases of each method
Required input parameters
Sample requests and responses
Code examples in multiple programming languages (Python, JavaScript)
What you can do with this API:
Query real-time blockchain data
Manage accounts and balances
Interact with smart contracts
Submit and track transactions
Monitor network activity in real time
To effectively use the BNB Smart Chain JSON-RPC methods, you’ll need a tool to send HTTP requests. One such tool is Axios, a lightweight and widely used HTTP client.
Quickstart with Axios
Axios is a powerful HTTP client that simplifies working with APIs, including BNB Smart Chain’s JSON-RPC interface. Using Axios, you can easily perform transactions, retrieve blockchain data, and more. Below is a step-by-step guide to get started:
1. Set Up Your Project
Choose a package manager and initialize your project:
Or using Yarn:
2. Install Axios
Install Axios to make HTTP requests:
Or:
3. Make Your First Request
Create a file called index.js
and add the following code:
You can also use other networks, such as BSC Testnet, by changing the URL accordingly.
4. Run Your Script
Execute your script:
You should see the latest block number retrieved from the BNB Smart Chain network.
Quickstart with Python and requests
requests is a simple yet powerful Python library for making HTTP requests, perfect for working with BNB Smart Chain’s JSON-RPC interface. Here’s how to get started:
1. Set Up Your Project
Create a project directory and virtual environment:
2. Write Your First Script
Create a file named main.py
and add the following code:
3. Run Your Script
Execute the script with:
The latest BSC block number should appear in your console output.
Blockchain Information & Network
eth_blockNumber
– Get the latest block numbereth_chainId
– Get the chain IDnet_version
– Network versionnet_listening
– Check if the node is listeningnet_peerCount
– Number of peers connectedweb3_clientVersion
– Client versionweb3_sha3
– Keccak-256 hasheth_syncing
– Sync statustxpool_status
– Transaction pool status
Accounts & Wallets
eth_accounts
– List of accountseth_coinbase
– Miner address (coinbase)eth_getBalance
– Get balance of an addresseth_getTransactionCount
– Get nonce of an addresseth_sign
– Sign dataeth_sendTransaction
– Send a transaction (from unlocked account)eth_sendRawTransaction
– Send a signed transaction
Transactions
eth_getTransactionByHash
eth_getTransactionReceipt
eth_getTransactionByBlockHashAndIndex
eth_getTransactionByBlockNumberAndIndex
eth_estimateGas
– Estimate gas for a transactioneth_gasPrice
– Current gas priceeth_maxPriorityFeePerGas
– Suggested priority feeeth_call
– Call a contract method (read-only)
Blocks
eth_getBlockTransactionCountByHash
eth_getBlockTransactionCountByNumber
eth_getUncleCountByBlockHash
eth_getUncleCountByBlockNumber
eth_getUncleByBlockHashAndIndex
eth_getUncleByBlockNumberAndIndex
Smart Contracts
eth_getCode
– Get smart contract bytecodeeth_getStorageAt
– Read contract storageeth_getProof
– Get Merkle proof for account/storage
Logs & Filters
eth_newFilter
eth_newBlockFilter
eth_newPendingTransactionFilter
eth_getFilterChanges
eth_getFilterLogs
eth_getLogs
eth_uninstallFilter
eth_unsubscribe
Debugging / Tracing (debug_*)
debug_traceTransaction
debug_traceCall
debug_traceBlock
debug_traceBlockByHash
debug_traceBlockByNumber
debug_standardTraceBadBlockToFile
debug_standardTraceBlockToFile
debug_accountRange
debug_storageRangeAt
Conclusion
The BNB Smart Chain methods mirror the Ethereum JSON-RPC standard, providing developers with a familiar and efficient interface for interacting with the blockchain. From retrieving block and transaction data to executing smart contract calls, these methods support a wide array of use cases. The included quickstart guides with Axios and Python make it easy to begin integrating BSC into your applications. By organizing and clarifying these capabilities, this overview helps developers of all experience levels build faster and more confidently on BNB Smart Chain.
Last updated