Cairo Contract Storage
Overview
Explain how contract storage is declared and accessed, and how storage keys are computed.
Quick Use
- •Read
references/contract-storage.mdbefore answering. - •Use
#[storage]struct for storage fields. - •Use
.read()and.write()on storage variables inContractState.
Response Checklist
- •Ensure storage field types implement
starknet::Store(derive it when possible). - •Mention storage keys are derived from the variable name and hashed.
- •Use
selforref selfcorrectly depending on mutability.
Example Requests
- •"How do I declare storage in a Cairo contract?"
- •"Why does my storage field need Store?"
- •"How is the storage key computed for a variable?"