Skip to main content
POST
eth_getCode
BNB API method that retrieves the compiled bytecode of a smart contract, providing its address as a parameter. This method returns a hexadecimal string representing the smart contract’s bytecode. Developers can use this bytecode to verify whether a smart contract is legitimate and ensure that it performs its intended functions.
When called against a block older than the latest ~128 blocks, this method is treated as an archive request (2 RUs instead of 1 RU). See request units.
Get your own node endpoint todayStart for free and get your app to production levels immediately. No credit card required.You can sign up with your GitHub, X, Google, or Microsoft account.

Parameters

  • address — the address of the smart contract to query.
  • quantity or tag — the integer of a block encoded as hexadecimal or the string with:
    • latest — the most recent block in the blockchain and the current state of the blockchain at the most recent block. A chain reorganization is to be expected.
    • safe — the latest justified block. Under BSC fast finality, a block becomes justified when more than two-thirds of the validators vote for it and its direct child carries their attestation in its header, so safe usually trails latest by a block or two.
    • finalized — the latest finalized block: a justified block whose direct child is also justified. Two conflicting blocks can both reach finality only if one-third or more of the validators violate the voting rules.
    • earliest — the earliest available or genesis block.
    • pending — the pending state and transactions block. The current state of transactions that have been broadcast to the network but have not yet been included in a block.

Response

data — the compiled bytecode of a smart contract. Returns 0x if the address is not associated with a smart contract.

eth_getCode code examples

The following example retrieves the compiled bytecode from the CAKE token smart contract.

Use case

A practical use case for the eth_getcode method is verifying whether an address is associated with a smart contract. This can be particularly useful for blockchain explorers, auditors, and DApp developers, who must ensure that the account they interact with is legitimate.

Body

application/json
id
integer
default:1
jsonrpc
string
default:2.0
method
string
default:eth_getCode
params
string[]

The address identifier.

Response

200 - application/json

The smart contract code.

jsonrpc
string
id
integer
result
object
Last modified on November 13, 2026