Solidity theorytheory 0/50 · 0%
Types · easy

10. Structs and enums

Grouping related state and modelling states.

A `struct` groups related fields into one type; an `enum` gives names to a small set of states and is stored as an integer.

enum Status { None, Active, Closed }

struct Stake {
    uint256 amount;
    uint64 since;
    Status status;
}

mapping(address => Stake) public stakes;

Order struct fields so small types sit together — the compiler packs them into shared 32-byte slots and saves gas.

Check your understanding

  1. 1. How is an enum stored?

  2. 2. Why does struct field order matter?

  3. 3. What is the default value of `Status status`?