calculateErc7201(keccak256: Function, id: string): Uint8Array
Calculates a collision-resistant storage slot using the ERC-7201 formula: keccak256(keccak256(id) - 1) & ~0xff.
The last byte is cleared to provide an additional 256 slots for related storage variables.
Parameters:
keccak256: (data: Uint8Array) => Uint8Array- Keccak256 hash functionid: string- Namespace identifier (recommend reverse domain notation)
Uint8Array - 32-byte storage slot with last byte cleared
Example:
Formula Breakdown
- Collision resistance: Double hash prevents preimage attacks
- 256 slots: Last byte cleared provides slots 0x00-0xFF for related variables
- Deterministic: Same ID always produces same slot
Usage Patterns
Solidity Storage Pattern
Multiple Related Slots
Namespace Conventions
Comparison with ERC-8042
| Feature | ERC-7201 | ERC-8042 |
|---|---|---|
| Formula | keccak256(keccak256(id) - 1) & ~0xff | keccak256(id) |
| Related slots | 256 (last byte) | None |
| Collision resistance | Higher (double hash) | Standard (single hash) |
| Use case | General upgradeable contracts | Diamond Standard |
See Also
- calculateErc8042 - Simpler diamond storage formula
- ERC-7201 Specification
- Keccak256 - Hash function documentation

