Skip to main content

Storage

Derive Macro Storage 

Source
#[derive(Storage)]
{
    // Attributes available to this derive:
    #[slot]
}
Expand description

Derives storage layout for nested structures.

Use for composite storage types within contracts. For main contracts, use #[derive(Contract)] instead.

§Field Attributes

§#[slot(expr)]

Places field at explicit storage slot. The expression must evaluate to U256.

use fluentbase_sdk::derive::{Storage, eip1967_slot};

pub const MY_SLOT: U256 = eip1967_slot!("eip1967.proxy.implementation");

#[derive(Storage)]
struct Config {
    #[slot(MY_SLOT)]
    implementation: StorageAddress,

    // Auto-layout continues normally
    owner: StorageAddress,
}

Fields with explicit slots:

  • Do not affect auto-layout counter
  • Are excluded from SLOTS constant
  • Must use U256 type (compile error otherwise)

§Example

#[derive(Storage)]
struct Config {
    owner: StoragePrimitive<Address>,
    version: StoragePrimitive<u32>,
}