BNB Smart Chain

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

#NameTypeRequiredDescription
1transactionobjectYesTransaction object. `to` is required for calls; omit `to` for contract deployments. Optional: `from`, `gas`, `gasPrice`/`maxFeePerGas`/`maxPriorityFeePerGas`, `value`, `data`.
2blockTagstringNoBlock state to simulate against. Defaults to `latest`.Default: latest

Response

TypeDescription
stringHex-encoded gas estimate. The node typically adds a small safety buffer above the raw simulation result.

Example request

curl https://bsc.therpc.io/YOUR_API_KEY \
-X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_estimateGas",
"params": [
{
"to": "0x8894E0a0c962CB723c1976a4421c95949bE2D4E3",
"data": "0x"
},
"latest"
],
"id": 1
}'

Try it live in the BNB Smart Chain playground.

Errors & troubleshooting

CodeMessageCause
3execution revertedThe simulated transaction reverted; the estimate cannot be produced.
-32000gas required exceeds allowanceEstimated gas exceeded the block gas limit or the supplied gas cap.
-32602invalid argumentMalformed 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

curl https://bsc.therpc.io/YOUR_API_KEY \
-X POST \
-H 'Content-Type: application/json' \
-d '{"jsonrpc":"2.0","id":1,"method":"eth_estimateGas","params":[{"to":"0x8894E0a0c962CB723c1976a4421c95949bE2D4E3","data":"0x"},"",null]}'

Ready to call this in production?

Free tier covers personal projects. Pay-as-you-go scales without a card.