Try it Live
Run Chain examples in the interactive playground
BrandedChain
Tree-shakeable functional API for Chain operations with optimal bundle size.Overview
BrandedChain is the functional layer underlying the Chain class. It provides:
- Zero-overhead type wrapping for chain configuration objects
- Tree-shakeable individual function exports
- Data-first unopinionated methods taking chain as first parameter
- Bundle optimization through selective imports
Type Definition
Available Functions
All Chain functionality available as tree-shakeable functions:Constructors
Chain Lookup
Data-First Pattern
All BrandedChain functions follow data-first pattern:Tree-Shaking Strategies
Strategy 1: Import Specific Chains (Smallest Bundle)
Best for: Applications using a fixed set of known chains.Strategy 2: Import Registry Functions (Larger Bundle)
Best for: Applications with dynamic chain selection.Strategy 3: Hybrid Approach (Balanced)
Best for: Applications with common chains but occasional dynamic lookup.Strategy 4: Code Splitting (Best of Both)
Best for: Large applications with route-based chain usage.- Main bundle: ~1KB
- Admin bundle: +150KB (loaded on demand)
Bundle Size Comparison
| Import Strategy | Bundle Size | Flexibility | Use Case |
|---|---|---|---|
| Specific chains only | ~1KB | Low | Fixed chains, production apps |
from() only | ~1KB | Low | Wrapper around chain objects |
fromId() or byId | ~150KB | High | Dynamic chain selection |
| Hybrid | ~150KB* | Medium | Common + dynamic |
| Code splitting | 1KB + 150KB† | High | Large apps, route-based |
Usage Examples
Minimal Bundle (Fixed Chains)
Dynamic Chain Loading
Multi-Chain Application
Functional Composition
Type-Safe Chain Operations
When to Use BrandedChain vs Chain
Use BrandedChain When:
- Bundle size critical (mobile, embedded)
- Fixed chain set (production apps)
- Tree-shaking important
- Functional style preferred
- Direct imports from tevm/chains
Use Chain Class When:
- Dynamic chains needed
- Convenience over size
- Traditional API preferred
- Prototype methods desired
Interoperability
BrandedChain and Chain are fully compatible:Re-exports from tevm/chains
BrandedChain re-exports all chains from tevm/chains:Related
- Chain - Main Chain class documentation
- Constructors - Creating chains
- Chain Lookup - Looking up chains by ID
- Metadata - Chain properties
- tevm/chains - Chain registry source

