Try it Live
Run AccessList examples in the interactive playground
Manipulation
Operations for modifying AccessList instances (immutable).AccessList.withAddress()
Add address to access list if not already present.list: Original access listaddress: Address to add
- Returns new list (immutable)
- No-op if address already exists
- Adds with empty storageKeys array
- O(n) operation (includes check)
AccessList.withStorageKey()
Add storage key for address (adds address if needed).list: Original access listaddress: Address to add key forkey: Storage key to add
- Returns new list (immutable)
- Adds address if not present
- No-op if key already exists for address
- O(n×m) operation
AccessList.deduplicate()
Remove duplicate addresses and storage keys.list: Access list to deduplicate
- Merges duplicate addresses
- Removes duplicate storage keys within merged addresses
- Preserves original item order (first occurrence)
- O(n²×m) operation (byte-by-byte comparison)
AccessList.merge()
Combine multiple access lists with automatic deduplication....lists: Access lists to merge
- Concatenates all lists
- Automatically deduplicates result
- Empty lists are ignored
- O(k×n²×m) operation (k = number of lists)
Patterns
Incremental Building
Conditional Addition
Bulk Addition
Merge Transaction Lists
Optimize After Building
Builder Pattern
Safe Merge
Immutable Updates
Performance Considerations
| Operation | Complexity | Notes |
|---|---|---|
| withAddress | O(n) | Check + copy array |
| withStorageKey | O(n×m) | Check + copy nested |
| deduplicate | O(n²×m) | Byte comparison |
| merge | O(k×n²×m) | k lists merged |
-
Deduplicate once at end
-
Check before adding
-
Batch operations
-
Merge once instead of repeated withAddress
Best Practices
-
Always deduplicate before using
-
Use immutable pattern
-
Build incrementally, optimize once
-
Merge before deduplicating
-
Check before expensive operations
See Also
- Constructors - Creating lists
- Queries - Inspecting lists
- Gas Optimization - Cost analysis

