calculateErc8042(keccak256: Function, id: string): Uint8Array
Calculates a storage slot using the ERC-8042 (Diamond Storage) formula: keccak256(id).
Simpler than ERC-7201, used primarily by the EIP-2535 Diamond Standard.
Parameters:
keccak256: (data: Uint8Array) => Uint8Array- Keccak256 hash functionid: string- Storage namespace identifier
Uint8Array - 32-byte storage slot
Example:
Formula
Usage Patterns
Diamond Standard Storage
Legacy Diamond Implementations
When to Use ERC-8042
Use ERC-8042 when:- Implementing EIP-2535 Diamond Standard
- Compatibility with existing diamond contracts required
- Following established diamond patterns
- Simpler formula preferred
- General upgradeable proxy patterns
- Need related storage slots (last byte cleared)
- Maximum collision resistance required
- Not tied to diamond standard
Comparison with ERC-7201
| Feature | ERC-8042 | ERC-7201 |
|---|---|---|
| Formula | keccak256(id) | keccak256(keccak256(id) - 1) & ~0xff |
| Complexity | Simple | More complex |
| Related slots | None | 256 (last byte) |
| Collision resistance | Standard | Higher |
| Gas cost | Slightly lower | Slightly higher |
| Primary use | Diamond Standard | General proxies |
Diamond Standard Integration
See Also
- calculateErc7201 - Enhanced namespaced storage
- ERC-8042 Specification
- EIP-2535 Diamond Standard
- Keccak256 - Hash function documentation

