Skip to content

Storage

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

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

Storage is a struct annotated 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 {
        pub a: u128,
        pub b: u8,
        pub c: u256
    }
}

You can also read about storing custom types.

Powered By Nethermind