POST
/
4ab982aa70a7baead515ffdb5915df3f
curl --request POST \
  --url https://fantom-mainnet.core.chainstack.com/4ab982aa70a7baead515ffdb5915df3f \
  --header 'Content-Type: application/json' \
  --data '{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "eth_chainId",
  "params": []
}'
{
  "jsonrpc": "<string>",
  "id": 123,
  "result": "<string>"
}

Fantom API method that returns the current chain ID. Chain ID is used to sign replay-protected transactions and verify whether a network is the desired one. It was introduced in EIP-155.

Get you own node endpoint today

Start 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

Use the Chainstack EVM Knife to convert the Chain ID from Hexadecimal to Decimal.

eth_chainId code examples

const { 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();

Use case

One possible use case for the 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.

Body

application/json
id
integer
default:1
jsonrpc
string
default:2.0
method
string
default:eth_chainId
params
any[]

Response

200 - application/json
The network Chain ID
jsonrpc
string
id
integer
result
string