Try it Live
Run AccessList examples in the interactive playground
Validation
Type guards and validation functions for AccessList.AccessList.is()
Type guard checking if value is valid AccessList.value: Value to check
true if valid AccessList
Example:
- Must be array
- Each element must be valid Item
- Does not validate address/key byte lengths
AccessList.isItem()
Type guard checking if value is valid AccessList.Item.value: Value to check
true if valid Item
Example:
- Must have
addressproperty - Must have
storageKeysproperty (array) - Does not validate byte lengths
AccessList.assertValid()
Validates access list structure with detailed error messages.list: Value to validate
- Error if not array
- Error if item has invalid structure
- Error if address not 20 bytes
- Error if storage key not 32 bytes
- List must be array
- Each item must be object with
addressandstorageKeys - Addresses must be 20 bytes
- Storage keys must be 32 bytes each
- All keys in item must be valid
Patterns
Runtime Type Check
Validate External Data
Item Validation
Deep Validation
Conditional Processing
Validation Levels
Level 1: Type Guard (is)
Quick runtime check without byte validation.- Trusting internal data
- Performance critical
- Will validate elsewhere
Level 2: Deep Validation (assertValid)
Full validation including byte lengths.- Processing external data
- User input
- Network data
- Before critical operations
Level 3: Custom Validation
Application-specific checks.- Business logic validation
- Gas optimization requirements
- Protocol-specific constraints
Error Messages
assertValid Errors
Handling Errors
Best Practices
-
Validate external data
-
Use type guards for internal data
-
Validate before encoding
-
Provide clear error context
-
Don’t double validate
See Also
- Constructors - Creating lists
- Queries - Inspecting lists
- BrandedAccessList - Type system

