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

eth_chainId - Ethereum

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

This method returns the currently configured chain ID as a hex-encoded integer. Chain ID is defined by EIP-155 and is the value applications sign into transactions to prevent replay across chains. Ethereum mainnet returns 0x1, Sepolia returns 0xaa36a7, and Hoodi returns 0x88bb0.

Parameters

This method takes no parameters.

Request

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

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

console.log(response.data.result);
example.py
import requests

response = requests.post(
    'https://go.getblock.io/<ACCESS-TOKEN>/',
    headers={'Content-Type': 'application/json'},
    json={
        'jsonrpc': '2.0',
        'method': 'eth_chainId',
        'params': [],
        'id': 'getblock.io'
    }
)

print(response.json())

Response

{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": "0x1"
}

Response Parameters

Parameter
Type
Description

jsonrpc

string

JSON-RPC protocol version ("2.0")

id

string

Request identifier matching the request

result

string

Hex-encoded chain ID (0x1 = Ethereum mainnet, 0xaa36a7 = Sepolia, 0x88bb0 = Hoodi)

Use Cases

  • Transaction Signing: Wallets and signers include the chain ID in signed transactions per EIP-155 to prevent replay attacks across chains

  • Chain-Selection Logic: dApps confirm the connected endpoint matches the intended network before initiating a write

  • Multi-Chain Router Behavior: Cross-chain aggregators verify the target chain before sending calldata to the correct contract

  • Wallet UX: Prompt users to switch networks when the connected chain ID doesn't match the dApp's expected chain

Error Handling

Error Code
Message
Description

-32603

Internal error

Node failed to return its configured chain ID

Web3 Integration

Last updated

Was this helpful?