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
callTracerto study how the transaction moved value. - Capture pre-execution account and storage state through
prestateTracerfor a security post-mortem after an exploit.
Parameters
| # | Name | Type | Required | Description |
|---|---|---|---|---|
| 1 | transactionHash | string | Yes | Hash of the transaction to trace. |
| 2 | options | object | No | Tracer configuration object. |
Response
| Type | Description |
|---|---|
| object | With 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
Try it live in the BNB Smart Chain playground.
Errors & troubleshooting
| Code | Message | Cause |
|---|---|---|
-32601 | Method not found | debug namespace is not enabled on the node (requires --http.api=debug or equivalent). |
-32602 | Invalid params | Transaction hash is missing, malformed, or the options object contains unknown fields. |
-32000 | transaction not found | The 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