Skip to main content

Overview

ChainId is a branded number type representing an EIP-155 chain identifier. Used for replay protection and identifying which network a transaction targets.

Type Definition

The branded type prevents accidentally mixing chain IDs with other numbers.

Creating ChainId

from

Create from a non-negative integer.
Validation: Throws InvalidFormatError if value is not a non-negative integer.

Constants

Pre-defined chain IDs for common networks:
GOERLI (5) is deprecated. Use SEPOLIA or HOLESKY for testnet development.

Methods

toNumber

Convert to plain number.

equals

Compare two chain IDs.

isMainnet

Check if chain ID is Ethereum mainnet.

Common Chain IDs

EIP-155 Replay Protection

Chain ID is embedded in transaction signatures to prevent replay attacks across chains:

Namespace Usage

See Also