BNB Smart Chain

BNB Smart Chain

eth_getCode

Because BNB Smart Chain runs a geth-equivalent EVM and charges gas in BNB, the same compiled bytecode you would deploy on Ethereum lives on-chain here too. eth_getCode hands you that deployed bytecode for any address, captured as of the block you name. You get back a hex string of EVM opcodes, or 0x when nothing is there. Aim the call at https://bsc.therpc.io/YOUR_API_KEY on chain ID 56 to read a contract's runtime code straight from state. Worth doing before you trust an address with a BEP-20 approval or a router swap.

Use cases

  • Tell a smart contract apart from a plain externally-owned account by checking whether the response equals 0x.
  • Compare the on-chain bytecode against your locally compiled artifact to confirm a fresh BSC deployment landed intact.
  • Spot proxy contracts by matching the returned opcodes against EIP-1167 minimal-proxy or EIP-1967 storage patterns.
  • Audit whether a contract had already been self-destructed by querying its code at an earlier chain-56 block.

Parameters

#NameTypeRequiredDescription
1addressstring (hex)YesThe address to read code from.
2blockTagstringNoBlock at which to read the code.Default: latest

Response

TypeDescription
string (hex)Hex-encoded EVM bytecode, or "0x" if the address is an EOA, the contract was self-destructed, or no code existed at that block.

Example request

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

Try it live in the BNB Smart Chain playground.

Errors & troubleshooting

CodeMessageCause
-32602Invalid paramsAddress is malformed or block tag is unrecognised.
-32000Missing trie nodeHistorical block has been pruned on a non-archive node.

Common pitfalls

  • An empty 0x result covers two different situations: a wallet that never held code, and a contract destroyed earlier. Absence alone cannot tell the two apart.
  • Querying a proxy hands back the thin forwarding bytecode, never the logic contract it delegates to. Resolve the implementation slot separately.
  • Reading code from a long-past block needs an archive node, since pruned BSC nodes drop the historical state behind that height.

Supported networks

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

See also

Parameters

0x-prefixed 20-byte address

hex block number or "latest"/"earliest"/"pending"/"safe"/"finalized"

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

Ready to call this in production?

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