githubEdit

eth_chainId - Polygon

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

The eth_chainId method returns the current chain ID used for signing replay-protected transactions (EIP-155). This method is essential for applications that need to verify they are connected to the correct network and for properly signing transactions.

Parameters

  • None

Request

cURL
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"
}'

Response

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

Response Parameters

Field
Type
Description

jsonrpc

string

JSON-RPC version (2.0)

id

string

Request identifier

result

string

Chain ID in hexadecimal format (0x89 = 137 for Polygon Mainnet)

Use Case

The eth_chainId method is essential for:

  • Network verification: Confirm connection to the correct network before operations

  • Transaction signing: Include correct chain ID for EIP-155 replay protection

  • Multi-chain applications: Dynamically detect and switch between networks

  • Wallet integration: Verify network configuration matches user expectations

  • Security: Prevent cross-chain replay attacks

Example: Network Verification

Error Handling

Status Code
Error Message
Cause

403

Forbidden

Missing or invalid ACCESS-TOKEN

-32600

Invalid Request

Malformed request body

Web3 Integration

Last updated

Was this helpful?