State Variables and Storage Layout
Understand the difference between storage, memory, and calldata, and how state variables persist on the blockchain.
What are State Variables?
Welcome to understanding how data lives on the blockchain! In Solidity, state variables are special variables whose values are permanently stored in the contract's storage on the blockchain.
Think of them as the persistent memory of your smart contract. Their values are saved even after a function finishes executing and across different transactions.
Data Locations in Solidity
Solidity uses different data locations to manage where information is stored during contract execution. These locations have big impacts on gas costs and how your variables behave.
storage: Permanent state on the blockchain.memory: Temporary data for function execution.calldata: Read-only data for external function arguments.
All lessons in this course
- State Variables and Storage Layout
- Mappings and Dynamic Arrays
- Events and Logging Data
- Storage Slots and Gas Optimization