githubEdit

eth_getCode - Polygon

Example code for the eth_getCode json-rpc method. Сomplete guide on how to use eth_getCode json-rpc in GetBlock.io Web3 documentation.

The eth_getCode method returns the code at a given address. This is used to determine if an address is a smart contract (has code) or an externally owned account (no code).

Parameters

Parameter
Type
Required
Description

address

string

Yes

20-byte contract address

blockParameter

string

Yes

Block number in hex, or "latest", "earliest", "pending"

Request

cURL
curl --location --request POST 'https://go.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "eth_getCode",
    "params": ["0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0", "latest"],
    "id": "getblock.io"
}'

Response

Response (example)
{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": "0x606060..."
}

Response Parameters

Field
Type
Description

jsonrpc

string

JSON-RPC version (2.0)

id

string

Request identifier

result

varies

The bytecode at the address, or 0x if no code exists

Use Case

The eth_getCode method is useful for:

  • Contract verification

  • Security analysis

  • Account type detection

  • Contract deployment verification

Error Handling

Status Code
Error Message
Cause

403

Forbidden

Missing or invalid ACCESS-TOKEN

-32600

Invalid Request

Malformed request body

-32602

Invalid params

Invalid method parameters

Web3 Integration

Last updated

Was this helpful?