Docs
Supported ChainszkSync EraJSON-RPC APINetwork Methods

eth_chainId - zkSync RPC Method

Get the chain ID for zkSync Era. Essential for transaction signing and network verification.

Returns the chain ID used for transaction signing on zkSync Era.

Why zkSync? Build on Matter Labs' flagship zkEVM powering the Elastic Network of interoperable hyperchains with ZK Stack modular framework, hyperchain interoperability, native account abstraction, and $1.9B in tokenized real-world assets.

Use Cases

The eth_chainId method is essential for:

  • Transaction signing - Ensure transactions are signed for the correct network
  • Network verification - Confirm connection to the expected chain
  • Multi-chain apps - Handle different networks programmatically
  • Wallet integration - Validate network before transactions

Request Parameters

Request

This method accepts no parameters.

Response Body

Response
resultQUANTITY

Chain ID in hexadecimal

Code Examples

Bash
curl -X POST https://api-zksync-era-mainnet-full.n.dwellir.com/YOUR_API_KEY \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "eth_chainId",
    "params": [],
    "id": 1
  }'
JavaScript
import { JsonRpcProvider } from 'ethers';

const provider = new JsonRpcProvider('https://api-zksync-era-mainnet-full.n.dwellir.com/YOUR_API_KEY');

const network = await provider.getNetwork();
console.log('Chain ID:', network.chainId);

// Verify network before transaction
async function verifyNetwork(expectedChainId) {
  const network = await provider.getNetwork();
  if (network.chainId !== BigInt(expectedChainId)) {
    throw new Error(`Wrong network. Expected ${expectedChainId}, got ${network.chainId}`);
  }
  return true;
}
Python
from web3 import Web3

w3 = Web3(Web3.HTTPProvider('https://api-zksync-era-mainnet-full.n.dwellir.com/YOUR_API_KEY'))

chain_id = w3.eth.chain_id
print(f'Chain ID: {chain_id}')

# Verify network
def verify_network(expected_chain_id):
    chain_id = w3.eth.chain_id
    if chain_id != expected_chain_id:
        raise ValueError(f'Wrong network. Expected {expected_chain_id}, got {chain_id}')
    return True
Go
package main

import (
    "context"
    "fmt"
    "log"

    "github.com/ethereum/go-ethereum/ethclient"
)

func main() {
    client, err := ethclient.Dial("https://api-zksync-era-mainnet-full.n.dwellir.com/YOUR_API_KEY")
    if err != nil {
        log.Fatal(err)
    }

    chainID, err := client.ChainID(context.Background())
    if err != nil {
        log.Fatal(err)
    }

    fmt.Printf("Chain ID: %d\n", chainID)
}

On this page