Skip to main content

Try it Live

Run Chain examples in the interactive playground

Constructors

Methods for creating Chain instances from chain configuration objects and chain IDs.

Universal Constructor

Chain(chain)

Universal constructor creates Chain instance from chain object. Identity function that sets proper prototype.
Parameters:
  • chain: Chain - Chain configuration object
Returns: Chain Defined in: primitives/Chain/Chain.js:14

Static Constructors

Chain.from(chain)

Creates Chain instance from chain configuration object. Identity function that sets proper prototype.
Parameters:
  • chain: Chain - Chain configuration object
Returns: Chain Use cases:
  • Wrapping chain objects from tevm/chains
  • Adding prototype methods to plain chain objects
  • Type conversion for libraries expecting Chain instances
Defined in: primitives/Chain/Chain.js:21

Chain.fromId(id)

Look up chain by chain ID. Returns chain configuration or undefined if not found.
Parameters:
  • id: number - Chain ID to lookup
Returns: Chain | undefined - Chain object or undefined if not found Common chain IDs:
  • 1 - Ethereum Mainnet
  • 10 - OP Mainnet
  • 42161 - Arbitrum One
  • 8453 - Base
  • 137 - Polygon
  • 43114 - Avalanche C-Chain
Use cases:
  • Dynamic chain selection based on user input
  • Loading chain config from environment variables
  • Validating chain IDs before operations
  • Network switching in dApps
Defined in: primitives/Chain/Chain.js:28 Delegates to: primitives/Chain/BrandedChain/fromId.js:15

Usage Examples

Basic Usage

Dynamic Chain Loading

Environment-Based Chain Selection

Safe Chain Lookup

Multi-Chain Application

Type-Safe Chain Handling

Notes

  • from() is an identity function - returns the same object with prototype set
  • fromId() delegates to getChainById from tevm/chains
  • All chain objects come from tevm/chains registry
  • Chain IDs are unique identifiers defined by EIP-155
  • New chains are added to tevm/chains registry regularly