Contract Structure
- Contract modules. A Starknet contract is a module with the #[starknet::contract] attribute: state plus entry points.
- Storage struct. The Storage struct declares persistent state: every field a storage variable.
- Constructor. The constructor runs once at deployment: initial owners and parameters written into storage.
Storage
- Reads and writes. State reads with self.field.read() and writes with write: access explicit, costs visible.
- Storage mappings. A storage Map keys values by address or id: balances and ownership tables.
- Storage packing. Storage slots cost: packing small fields and lean layouts are money, as on every chain.
External Functions
- external and view. #[external] functions mutate state; view functions promise reads only: the ABI surface.
- Contract state parameter. Entry points receive self: ContractState threading storage access through signatures.
- Inputs validated. Every external input is untrusted: validated before any storage write, always.
Before and after this level
- Before: Level 5: Modules & Packages: Modules, Scarb, Package Organisation.
- Next: Level 7: Events & Contract Interaction: Events, Dispatchers and Interfaces, Contract-to-Contract Communication.
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 Cairo Level 6: Starknet Contracts cover?
Contract Structure, Storage, External Functions: 3 lessons and 9 ideas.
What should I know before this level?
The level before it, Level 5: Modules & Packages, which covers Modules, Scarb, Package Organisation.