Ethereum

Ethereum

eth_chainId

eth_chainId reports the EIP-155 chain identifier that the endpoint is serving. For Ethereum mainnet — the ETH network — that value is 0x1, decimal 1. The identifier is baked into every signed transaction so a signature valid on one network can't be replayed on another; checking it before you sign is how a wallet proves it's talking to the right chain rather than Sepolia (0xaa36a7) or Holesky. Call https://ethereum.therpc.io/YOUR_API_KEY with no parameters and you'll get 0x1 back from any healthy mainnet node.

Use cases

  • Network guard before signing. Confirm the result is 0x1 before submitting, so a user who switched their wallet to a testnet doesn't accidentally fire a mainnet-intended transaction into the void.
  • Health + identity probe. Pair it with eth_blockNumber for a two-call check that the endpoint is both alive and serving chain 1, not some fork.
  • Pick the right deployment. In a multi-chain app, map the returned ID to the correct contract addresses — your USDC or router on mainnet differs from the one on every testnet.
  • Replay protection. The chain ID is the EIP-155 ingredient that stops a mainnet-signed transaction from being rebroadcast on another EVM chain; reading it lets you build that check in explicitly.

Parameters

This method takes no parameters. Pass an empty array [].

Response

TypeDescription
string (hex)Hex-encoded chain ID integer (e.g. "0x1" for Ethereum mainnet).

Example request

curl https://ethereum.therpc.io/YOUR_API_KEY \
-X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_chainId",
"params": [],
"id": 1
}'

Try it live in the Ethereum playground.

Errors & troubleshooting

CodeMessageCause
-32603Internal errorNode failed to retrieve chain configuration.

Common pitfalls

  • eth_chainId and net_version are not interchangeable. net_version returns the older network ID as a decimal string; on Ethereum mainnet both happen to be 1, but the chain ID is what EIP-155 signing actually uses, so always sign against this method's value.
  • The response is a hex string ("0x1"), not a number. Comparing the raw string against "1" or 1 will silently fail — normalize with BigInt(result) or parseInt(result, 16) first.

Supported networks

  • Mainnet — Chain ID: 1
  • Sepolia — Chain ID: 11155111

See also

curl https://ethereum.therpc.io/YOUR_API_KEY \
-X POST \
-H 'Content-Type: application/json' \
-d '{"jsonrpc":"2.0","id":1,"method":"eth_chainId","params":[]}'

Ready to call this in production?

Free tier covers personal projects. Pay-as-you-go scales without a card.