Chapter 5

State and Storage

One of the first Solidity concepts that trips people up is data location. Not all variables behave the same way: some live only during execution, while others are written permanently to the blockchain.

If a contract stores token balances, those values belong in storage because they must still exist tomorrow. If a function creates a temporary list while checking an order, memory is often enough because the list disappears after the call.

This is not just a technical distinction. It shapes contract economics. On Ethereum, persistent state is expensive, so good developers design data layouts that are accurate, minimal, and efficient to update.