Storage

Este es el contrato mínimo que puedes redactar en Cairo:

#[starknet::contract]
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.

Puede definir variables de storage en su contrato y luego usarlas para almacenar y recuperar datos.

#[starknet::contract]
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.

También puede leer sobre almacenamiento de tipos personalizados

Last change: 2023-11-20, commit: 3890c7b