> ## Documentation Index
> Fetch the complete documentation index at: https://docs.chainstack.com/llms.txt
> Use this file to discover all available pages before exploring further.

# eth_chainId | Arbitrum

Arbitrum 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](https://eips.ethereum.org/EIPS/eip-155).

<Check>
  **Get your own node endpoint today**

  [Start for free](https://console.chainstack.com/) and get your app to production levels immediately. No credit card required.

  You can sign up with your GitHub, X, Google, or Microsoft account.
</Check>

## Parameters

* `none`

## Response

* `quantity` — EIP-155 Chain ID

## `eth_chainId` code examples

<CodeGroup>
  ```javascript web3.js theme={"system"}
  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();
  ```

  ```javascript ethers.js theme={"system"}
  const ethers = require('ethers');
  const NODE_URL = "CHAINSTACK_NODE_URL";
  const provider = new ethers.JsonRpcProvider(NODE_URL);

  const chainId = async () => {

      // This will return the value in Hex
      const chainId = await provider.send("eth_chainId");
      console.log(`Hex Chain ID: ${chainId}`);
    };

  chainId();
  ```

  ```python web3.py theme={"system"}
  from web3 import Web3  
  node_url = "CHAINSTACK_NODE_URL"

  web3 = Web3(Web3.HTTPProvider(node_url)) 
  print(web3.eth.chain_id)  
  ```
</CodeGroup>

## Use case

One possible use case for the `chain_id` method in Arbitrum 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 `chain_id` method might be used in this context with MetaMask. Keep in mind that the chain ID is returned as a hexadecimal value:

```js JavaScript theme={"system"}
// Check which network is selected on MetaMask
async function checkChain() {
  
    // Declare the desired chain ID to match
    const desiredChainId = '0xA4B1'; // Arbitrum mainnet chain ID
  
    // Retrieve the current Chain ID selected by the user 
    ethereum.request({
        method: 'eth_chainId'
    }).then(chainId => {
      
        // compare the actual chain ID it to the declared chain ID 
        if (chainId !== desiredChainId) {
          
            console.log(`You are currently on the wrong network. Please switch to the mainnet.`);
            // Call the promtSwitch function
            promtSwitch()
          
        } else {
            console.log("This is the correct network")
        }
    })
}
// Prompt user to switch to a determined network based on the chain ID
async function promtSwitch() {
    await window.ethereum.request({
        method: 'wallet_switchEthereumChain',
        params: [{
            chainId: '0xA4B1' // chainId must be in HEX with 0x in front
        }],
    });
}
```

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 Arbitrum mainnet and calls the `promtSwitch` function to prompt the user to switch chains in case the chain ID returned does not match the `desiredChainId` constant.


## OpenAPI

````yaml /openapi/arbitrum_node_api/chain_info/eth_chainId.json POST /5b8d22690a57f293b3a1ed8758014e35
openapi: 3.0.0
info:
  title: Chainstack Node API
  version: 1.0.0
  description: This is an API for interacting with a Chainstack node.
servers:
  - url: https://nd-000-364-211.p2pify.com
security: []
paths:
  /5b8d22690a57f293b3a1ed8758014e35:
    post:
      tags:
        - Update
      summary: eth_chainId
      operationId: getChainId
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                id:
                  type: integer
                  default: 1
                jsonrpc:
                  type: string
                  default: '2.0'
                method:
                  type: string
                  default: eth_chainId
                params:
                  type: array
                  default: []
      responses:
        '200':
          description: The network Chain ID
          content:
            application/json:
              schema:
                type: object
                properties:
                  jsonrpc:
                    type: string
                  id:
                    type: integer
                  result:
                    type: string

````