Ethereum

Ethereum

eth_getCode

eth_getCode returns the EVM bytecode living at an address on Ethereum mainnet (chain ID 1), the network where every contract call and deployment is paid for in ETH. Pass an address and a block, and the node reads the codeHash recorded in that account's state and hands back the actual bytecode behind it. Externally owned accounts hold no code, so they answer 0x; a deployed contract answers with its full runtime bytecode. Point the call at https://ethereum.therpc.io/YOUR_API_KEY, and because the block argument is honoured, you can read the code as it stood at any height, not just the chain head.

Use cases

  • Tell a contract from a plain wallet: a 0x answer means an EOA, anything longer means deployed code. Wallets gate "this is a smart contract" warnings on exactly this check.
  • After deploying, compare the returned runtime bytecode against what your compiler emitted, the same comparison Etherscan does when it marks a contract verified.
  • Spot proxies by their fingerprint — the tiny EIP-1167 minimal-proxy stub, or a transparent/UUPS proxy whose logic address sits in the EIP-1967 implementation slot.
  • Check whether a contract was already SELFDESTRUCTed at a given height by reading its code at that block and seeing 0x come back where bytecode used to be.

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://ethereum.therpc.io/YOUR_API_KEY \
-X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_getCode",
"params": [
"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
"latest"
],
"id": 1
}'

Try it live in the Ethereum 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

  • 0x is ambiguous: a never-deployed EOA and a contract that already self-destructed look identical. To tell them apart you need history — read the code at an earlier block, or check whether the account ever had a non-empty codeHash.
  • Against a proxy you get the proxy's own bytecode, not the logic it delegates to. To reach the implementation, read the EIP-1967 slot with eth_getStorageAt first, then call eth_getCode on that address.
  • Reading code at an old height needs an archive node; on a pruned full node the state is gone and you'll hit a -32000 missing-trie-node error instead of bytecode.

Supported networks

  • Mainnet — Chain ID: 1
  • Sepolia — Chain ID: 11155111

See also

Parameters

0x-prefixed 20-byte address

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

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

Ready to call this in production?

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