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.
chain: Chain- Chain configuration object
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.
chain: Chain- Chain configuration object
Chain
Use cases:
- Wrapping chain objects from tevm/chains
- Adding prototype methods to plain chain objects
- Type conversion for libraries expecting Chain instances
Chain.fromId(id)
Look up chain by chain ID. Returns chain configuration or undefined if not found.
id: number- Chain ID to lookup
Chain | undefined - Chain object or undefined if not found
Common chain IDs:
1- Ethereum Mainnet10- OP Mainnet42161- Arbitrum One8453- Base137- Polygon43114- Avalanche C-Chain
- Dynamic chain selection based on user input
- Loading chain config from environment variables
- Validating chain IDs before operations
- Network switching in dApps
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 setfromId()delegates togetChainByIdfrom 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

