Storage

Here's the most minimal contract you can write in Cairo:

#[starknet::contract]
pub mod Contract {
    #[storage]
    struct Storage {}
}

Storage is a struct annoted with #[storage]. Every contract must have one and only one storage. It's a key-value store, where each key will be mapped to a storage address of the contract's storage space.

You can define storage variables in your contract, and then use them to store and retrieve data.

#[starknet::contract]
pub mod Contract {
    #[storage]
    struct Storage {
        a: u128,
        b: u8,
        c: u256
    }
}

Actually these two contracts have the same underlying sierra program. From the compiler's perspective, the storage variables don't exist until they are used.

You can also read about storing custom types

Last change: 2023-12-07, commit: 286b664