Skip to main content
POST
eth_chainId
Ethereum API method that returns the current chain ID. Chain ID is used to sign replay-protected transactions and generally verify if a network is the desired one. It was introduced in EIP-155.
Get your own node endpoint todayStart for free and get your app to production levels immediately. No credit card required.You can sign up with your GitHub, X, Google, or Microsoft account.

Parameters

  • none

Response

  • quantity — EIP-155 Chain ID

eth_chainId code examples

Learn more about the ChainstackProvider in ethers.js: ethers ChainstackProvider Documentation.

Use case

One possible use case for the eth_chainId method in Ethereum is to determine which chain a user is connected to when using a DApp with the MetaMask browser extension. This can be useful to provide a customized user experience based on the specific chain that the user is interacting with. Here is an example of how the eth_chainId method might be used in this context with MetaMask. Keep in mind that the Chain ID is returned as a hexadecimal value:
JavaScript
In this case, the checkChain function is called to get the current chain ID using the Ethereum object provided by MetaMask. The chain ID is then checked to determine if the user is connected to the Ethereum mainnet and calls the promtSwitch function to prompt the user to switch chain in case the chain ID returned does not match the desiredChainId constant.

Body

application/json
id
integer
default:1
jsonrpc
string
default:2.0
method
string
default:eth_chainId
params
array

Response

200 - application/json

The network Chain ID

jsonrpc
string
id
integer
result
string
Last modified on June 25, 2026