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

eth_getCode - Flashblocks

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

The eth_getCode method returns the bytecode at a given address. This is used to determine if an address is a smart contract and to retrieve the deployed contract code. When the block reference is "pending", Flashblocks detect contract deployments before the block seals.

Parameters

Parameter
Type
Required
Description

address

string

Yes

20-byte address to check

blockParameter

string

Yes

Block number in hex, or "pending"

Request

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

const response = await axios.post('https://go.getblock.io/<ACCESS-TOKEN>/', {
    jsonrpc: '2.0',
    method: 'eth_getCode',
    params: [
    '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
    'pending'],
    id: 'getblock.io'
}, {
    headers: { 'Content-Type': 'application/json' }
});

const code = response.data.result;
const isContract = code !== '0x';
console.log('Is Contract:', isContract);
console.log('Code Length:', (code.length - 2) / 2, 'bytes');

Response

Response Parameters

Parameter
Type
Description

jsonrpc

string

JSON-RPC protocol version ("2.0")

id

string

Request identifier matching the request

result

string

Bytecode at the address (hex). Returns "0x" for EOAs

Use Cases

  • Contract Detection: Verify if address is a smart contract

  • Security Analysis: Examine contract bytecode for vulnerabilities

  • Contract Verification: Compare deployed code with source

  • Proxy Detection: Identify proxy patterns in bytecode

  • Contract Indexing: Catalog deployed contracts

Error Handling

Error Code
Message
Description

-32602

Invalid params

Invalid address format

-32603

Internal error

Node internal failure

SDK Integration

Last updated

Was this helpful?