BNB Smart Chain

BNB Smart Chain

debug_traceTransaction

debug_traceTransaction takes one already-mined transaction and replays it instruction by instruction, rebuilding the exact EVM state of the block where it landed and emitting a step-by-step record of execution. That is visibility no plain read method can offer. BNB Smart Chain (BSC) is a PoSA network with roughly three-second blocks where BNB pays gas and BEP-20 tokens flow through venues like PancakeSwap and Venus, so most traces here mean unpicking a DeFi interaction. Point the call at the JSON-RPC endpoint https://bsc.therpc.io/YOUR_API_KEY on chain ID 56. Re-running against historical state is heavy, so it wants a debug-enabled archive node.

Use cases

  • Pin down why a BEP-20 swap or contract call reverted by reading the opcode and stack contents at the REVERT instruction.
  • Profile per-opcode gas to find the hot spots worth trimming before a contract ships to mainnet.
  • Rebuild the full internal call tree of a sandwich or arbitrage bundle with callTracer to study how the transaction moved value.
  • Capture pre-execution account and storage state through prestateTracer for a security post-mortem after an exploit.

Parameters

#NameTypeRequiredDescription
1transactionHashstringYesHash of the transaction to trace.
2optionsobjectNoTracer configuration object.

Response

TypeDescription
objectWith the default tracer: `{gas, failed, returnValue, structLogs[]}` where each structLog entry contains `{pc, op, gas, gasCost, depth, stack?, memory?, storage?}`. With callTracer: a nested call-tree object. With prestateTracer: a pre-execution account/storage map.

Example request

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

Try it live in the BNB Smart Chain playground.

Errors & troubleshooting

CodeMessageCause
-32601Method not founddebug namespace is not enabled on the node (requires --http.api=debug or equivalent).
-32602Invalid paramsTransaction hash is missing, malformed, or the options object contains unknown fields.
-32000transaction not foundThe transaction hash does not exist on the chain or the node lacks archive state for that block.

Common pitfalls

  • Any transaction older than the last few thousand blocks needs full archive state, so a pruned BSC node simply rejects it.
  • The default structLog stream can swell to hundreds of megabytes on a dense transaction. Switch to callTracer, or just turn off the stack and storage dumps in the options object.
  • Custom JavaScript tracers run in a sandboxed interpreter and can hit the node timeout on a long-running transaction. Lower tiers may rate-limit or refuse the call outright.

Supported networks

  • Mainnet — Chain ID: 56
  • Testnet — Chain ID: 97

See also

Parameters

0x-prefixed 32-byte hash

omit for default struct-log tracer

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

Ready to call this in production?

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