Storage
Smart contracts rely on storage, acting as the persistent memory on the blockchain. In Aztec, because of its hybrid, privacy-first architecture, the management of this storage is more complex than other blockchains like Ethereum.
To learn how to define a storage struct, read this guide. To learn more about storage slots, read this explainer in the Concepts section.
You control this storage in Aztec using a struct annotated with #[storage]
. This struct serves as the housing unit for all your smart contract's state variables - the data it needs to keep track of and maintain.
These state variables come in two forms: public and private. Public variables are visible to anyone, and private variables remain hidden within the contract. A state variable with both public and private components is said to be shared.
Aztec.nr has a few abstractions to help define the type of data your contract holds. These include PrivateMutable, PrivateImmutable, PublicMutable, PublicImmutable, PrivateSet, and SharedMutable.
On this and the following pages in this section, you’ll learn:
- How to manage a smart contract's storage structure
- The distinctions and applications of public and private state variables
- How to use PrivateMutable, PrivateImmutable, PrivateSet, PublicMutable, SharedMutable and Map
- An overview of 'notes' and the UTXO model
- Practical implications of Storage in real smart contracts In an Aztec.nr contract, storage is to be defined as a single struct, that contains both public and private state variables.