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
0xanswer 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 seeing0xcome back where bytecode used to be.
Parameters
| # | Name | Type | Required | Description |
|---|---|---|---|---|
| 1 | address | string (hex) | Yes | The address to read code from. |
| 2 | blockTag | string | No | Block at which to read the code.Default: latest |
Response
| Type | Description |
|---|---|
| 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
Try it live in the Ethereum playground.
Errors & troubleshooting
| Code | Message | Cause |
|---|---|---|
-32602 | Invalid params | Address is malformed or block tag is unrecognised. |
-32000 | Missing trie node | Historical block has been pruned on a non-archive node. |
Common pitfalls
0xis 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-emptycodeHash.- 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_getStorageAtfirst, then calleth_getCodeon 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
-32000missing-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"