Hash the properly encoded key with the declared mapping slot.
LET’S PICTURE IT
A directory combines the lookup name with the directory identifier to select one drawer.
SEE IT FOR YOURSELF
Pack small values into Solidity storage slotsStep 1 / 4
In this simple default-layout example, two uint128 values come before one uint256. Each slot holds thirty-two bytes.
In this simple default-layout example, two uint128 values come before one uint256. Each slot holds thirty-two bytes.The first sixteen-byte value occupies the low-order half of slot zero. Low-order bytes are shown on the right.The second uint128 fits in the remaining sixteen bytes. Both values now share slot zero.C needs a complete thirty-two-byte slot, so it begins at slot one. Two packed small values plus C use two slots.
Animated local teaching model. No wallet, RPC or live blockchain data. Some labels and hashes are abbreviated for readability.
Start from the declaration
A mapping reserves a declared slot p used in deriving entry locations. That slot does not store an enumerable list of keys or a mapping length.
Encode the key under its type
For an address key, use its padded thirty-two-byte representation, then the thirty-two-byte slot number. Do not concatenate a twenty-byte address with a word and assume the same result.
Hash the combined input
For mapping(address => uint256), Keccak-256 of those two words identifies the entry’s slot. Other key types can require different key encoding rules.
Keep network state separate
A local slot calculation identifies a location under a supplied layout. It does not read that location, confirm the implementation or prove a live balance.