curl --request POST \
--url https://aurora-mainnet.core.chainstack.com/6df1a1b3061097e66349993a96b8e535 \
--header 'Content-Type: application/json' \
--data '
{
"id": 1,
"jsonrpc": "2.0",
"method": "eth_chainId",
"params": []
}
'{
"jsonrpc": "<string>",
"id": 123,
"result": "<string>"
}curl --request POST \
--url https://aurora-mainnet.core.chainstack.com/6df1a1b3061097e66349993a96b8e535 \
--header 'Content-Type: application/json' \
--data '
{
"id": 1,
"jsonrpc": "2.0",
"method": "eth_chainId",
"params": []
}
'{
"jsonrpc": "<string>",
"id": 123,
"result": "<string>"
}nonequantity — EIP-155 Chain IDeth_chainId code examplesconst { Web3 } = require("web3");
const NODE_URL = "CHAINSTACK_NODE_URL";
const web3 = new Web3(NODE_URL);
async function getChainId() {
const chain = await web3.eth.getChainId();
console.log(chain);
}
getChainId();
eth_chainId method 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.Was this page helpful?