Skip to main content

Try it Live

Run Chain examples in the interactive playground

Chain Lookup

Methods and properties for looking up chain configurations by chain ID.

byId Record

Chain.byId

Record mapping chain IDs to chain configuration objects. Provides O(1) lookup of any registered chain.
Type: Record<number, Chain> Returns: Chain | undefined for any chain ID Defined in: primitives/Chain/Chain.js:36 Delegates to: primitives/Chain/BrandedChain/byId.js:14

Comparison: byId vs fromId

Both Chain.byId[id] and Chain.fromId(id) lookup chains by ID:
Differences:
  • byId[id] - Direct record access (bracket notation)
  • fromId(id) - Function call, slightly more explicit
Use byId when:
  • You prefer bracket notation
  • You’re accessing multiple chains in a loop
  • You want the most direct syntax
Use fromId when:
  • You prefer function call syntax
  • You want explicit method calls
  • You’re chaining operations

Usage Examples

Basic Lookup

Iterating Over Multiple Chains

Dynamic Chain Selection

Chain Validation

All Registered Chains

Common Chain IDs

Type-Safe Chain Map

Safe Chain Access

Network Switch Handler

Chain Registry Explorer