Skip to main content

NetworkId

Type-safe Ethereum network identifiers for peer-to-peer network discovery.

Overview

Branded number type representing Ethereum network IDs. Network IDs are used for peer-to-peer network identification and discovery, distinct from Chain IDs which are used for transaction replay protection.
NetworkId vs ChainId: These are different concepts!
  • NetworkId: Used for P2P network discovery (devp2p protocol)
  • ChainId: Used for transaction replay protection (EIP-155)
For most public networks they happen to be the same value, but they serve different purposes.

Quick Start

Network Constants

API Reference

Constructors

Methods

NetworkId vs ChainId

Understanding the difference: For most public networks, NetworkId and ChainId have the same value:
However, private networks or some L2s may use different values for each.

Use Cases

Network Detection

Multi-Network Support

Node Connection Validation

  • Chain - Chain configuration with ChainId
  • PeerId - Peer identifiers for P2P
  • NodeInfo - Node information structure

References