For the complete documentation index, see llms.txt. This page is also available as Markdown.

eth_getCode - Ethereum

Example code for the eth_getCode JSON RPC method. Сomplete guide on how to use eth_getCode JSON RPC in GetBlock Web3 documentation.

This method returns the deployed bytecode at a specific address, hex-encoded. For contract addresses it returns the runtime bytecode; for EOAs it returns 0x. Post-Pectra (EIP-7702) EOAs can temporarily delegate to smart-contract code, in which case this returns the delegated code marker (0xef0100 + implementation address).

Parameters

Parameter
Type
Required
Description

address

string

Yes

20-byte address to query (hex-encoded with 0x prefix)

blockParameter

string

Yes

Block number in hex, or latest, earliest, pending, finalized, safe

Request

curl --location --request POST 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "eth_getCode",
    "params": [
        "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
        "latest"
    ],
    "id": "getblock.io"
}'
const axios = require('axios');

const response = await axios.post('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/', {
    jsonrpc: '2.0',
    method: 'eth_getCode',
    params: [
        "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
        "latest"
    ],
    id: 'getblock.io'
}, {
    headers: { 'Content-Type': 'application/json' }
});

console.log(response.data.result);

Response

Response Parameters

Parameter
Type
Description

jsonrpc

string

JSON-RPC protocol version ("2.0")

id

string

Request identifier matching the request

result

string

Hex-encoded contract runtime bytecode. 0x for EOAs. Post-Pectra: 0xef0100... for delegated EOAs (EIP-7702)

Use Cases

  • Contract Existence Check: Detect whether an address is a contract (non-empty code) or an EOA (0x)

  • EIP-7702 Delegation Detection: Detect when an EOA has delegated to smart-contract code by checking for the 0xef0100 prefix (post-Pectra)

  • Contract Verification: Compare deployed bytecode against expected/compiled bytecode to detect tampering

  • Bytecode Analysis: Feed contract bytecode into tools like evm-disassembler, heimdall, or Panoramix for reverse engineering

Error Handling

Error Code
Message
Description

-32602

Invalid params

Address is malformed, or block parameter is invalid

-32603

Internal error

Node failed to look up account state at the requested block

Web3 Integration

Last updated

Was this helpful?