Type Hierarchy
Tevm provides three levels of types for each primitive:1. Branded Type (Strictest)
The base branded type - a validated, immutable value:- You have a validated address and want type safety
- You need maximum strictness
- You want to ensure the value came from Tevm’s validators
- Runtime: Plain
Uint8Array(20 bytes) - Validation: Already validated during construction
- Methods: None (use namespace functions)
- Overhead: Zero
2. Class Instance (Most Convenient)
Branded type with methods attached via prototype:- You want familiar OOP ergonomics
- You prefer method chaining
- Bundle size is not a primary concern
- Runtime:
Uint8Arraywith prototype methods - Validation: Validated during construction
- Methods: Available as
addr.method() - Overhead: Minimal (prototype chain)
3. Input Type (Loosest)
Note: Tevm does not currently exportAddressLike union types. The Address() constructor and from() functions accept multiple input types:
API Patterns
Class API (OOP Style)
- Familiar OOP patterns
- Method discovery via autocomplete
- Method chaining
- Imports entire class (~18 KB)
- All methods included in bundle
Namespace API (Functional Style)
- Tree-shakeable (only bundle what you use)
- Functional programming friendly
- Explicit dependencies
- More verbose
- No method chaining
- Must pass value as first argument
Tree-Shakeable Imports (Optimal Bundle Size)
Brand Symbol
All branded types use a sharedbrand symbol:
brand symbol:
unique symbol- TypeScript ensures uniqueness- Compile-time only - erased at runtime
- Shared across all primitives - consistent pattern
Type Variants
Hierarchical Types with Boolean Flags
Some types have specialized variants using boolean flags:Validation
All branded types are validated at construction:AddressType, it’s valid. No need for runtime validation libraries like Zod.
Console Formatting
Branded types display formatted in console:Uint8Array performance.
Comparison Table
| Feature | Class API | Namespace API | Tree-Shakeable |
|---|---|---|---|
| Import | import { Address } | import * as Address | import { fromHex, toHex } |
| Bundle Size | ~18 KB | ~18 KB | ~500 bytes (3 functions) |
| Syntax | addr.toHex() | Address.toHex(addr) | toHex(addr) |
| Type | Class instance | AddressType | AddressType |
| Methods | Prototype | Functions | Functions |
| Tree-shaking | ✗ No | ✗ No | ✓ Yes |
| Performance | Fast | Fast | Fastest |

