BNB Smart Chain
eth_estimateGas
Gas on BNB Smart Chain is paid in BNB, and eth_estimateGas tells you how much a transaction will consume before you commit. The node dry-runs the call against current state on its geth-equivalent EVM, then returns the gas units the operation would burn. A BEP-20 transfer, a PancakeSwap swap, a fresh contract deployment: all of them estimate the same way. Aim it at https://bsc.therpc.io/YOUR_API_KEY (chain ID 56). The simulation never reaches a validator and changes nothing on-chain. Only the estimate comes back.
Use cases
- Derive the gas limit to stamp on a transaction before signing it with BNB.
- Estimate the up-front cost of deploying a new BEP-20 token or DeFi contract to BSC.
- Probe whether a swap or transfer would succeed, since a reverting path returns an error instead of a number.
- Power live fee figures in BSC wallets and dApp confirmation screens.
Parameters
| # | Name | Type | Required | Description |
|---|---|---|---|---|
| 1 | transaction | object | Yes | Transaction object. `to` is required for calls; omit `to` for contract deployments. Optional: `from`, `gas`, `gasPrice`/`maxFeePerGas`/`maxPriorityFeePerGas`, `value`, `data`. |
| 2 | blockTag | string | No | Block state to simulate against. Defaults to `latest`.Default: latest |
Response
| Type | Description |
|---|---|
| string | Hex-encoded gas estimate. The node typically adds a small safety buffer above the raw simulation result. |
Example request
Try it live in the BNB Smart Chain playground.
Errors & troubleshooting
| Code | Message | Cause |
|---|---|---|
3 | execution reverted | The simulated transaction reverted; the estimate cannot be produced. |
-32000 | gas required exceeds allowance | Estimated gas exceeded the block gas limit or the supplied gas cap. |
-32602 | invalid argument | Malformed transaction object. |
Common pitfalls
- The figure is a best-effort guess, not a ceiling. Pad it by roughly 20% so a branch that costs slightly more does not strand the transaction out of gas.
- A simulated revert yields a JSON-RPC error (often code 3), not a gas number. Branch on that case instead of parsing a missing result.
- On BSC's ~3s blocks, contract state can move between estimate and inclusion, so a Venus or PancakeSwap call may end up consuming a different amount than predicted.
Supported networks
- Mainnet — Chain ID: 56
- Testnet — Chain ID: 97
See also
Parameters
Transaction object. `to` is required for calls; omit `to` for contract deployments. Optional: `from`, `gas`, `gasPrice`/`maxFeePerGas`/`maxPriorityFeePerGas`, `value`, `data`.
"latest" | "pending" | hex block number