Arrays and Mappings
- Mappings. A mapping is the EVM’s key-value store: every key readable, none enumerable, defaults for the rest.
- Arrays. Storage arrays grow and shrink at real gas cost: unbounded iteration is a denial-of-service bug.
- Enumeration patterns. Enumerable sets pair a mapping with an index array: the standard pattern for listable members.
Structs and Enums
- Structs. A struct groups fields: packed into slots, its layout an explicit gas decision.
- Enums. An enum names a closed set of states: Stage.Open, Stage.Settled: matched exhaustively by discipline.
- Struct packing. Packing small fields into one slot saves storage: uint128 pairs sharing what uint256 wastes.
Designing Contract State
- Minimal state. The best contract state is minimal: every slot is attack surface, cost and migration burden.
- Derived off-chain. Anything computable from events derives off-chain: indexers, not storage, hold the history.
- Invariants first. State design starts from invariants: totals that must balance, stated before any field exists.
Before and after this level
- Before: Level 2: State & Data Locations: Contract Storage, Memory and Calldata, State Mutation.
- Next: Level 4: Functions & Access: Visibility, Modifiers, Access-Control Patterns.
In the app each of these ideas is taught and then asked back, and the level ends with a checkpoint and flashcards. See Checkpoints and flashcards.
Frequently asked questions
What does Solidity Level 3: Collections & Data Models cover?
Arrays and Mappings, Structs and Enums, Designing Contract State: 3 lessons and 9 ideas.
What should I know before this level?
The level before it, Level 2: State & Data Locations, which covers Contract Storage, Memory and Calldata, State Mutation.