pub fn write<T>(slot: b256, offset: u64, value: T) 
Expand description

Stores a stack value in storage. Will not work for heap values.

Additional Information

If the value crosses the boundary of a storage slot, writing continues at the following slot.

Arguments

  • slot: [b256] - The storage slot at which the variable will be stored.
  • offset: [u64] - An offset starting at the beginning of slot at which value should be stored.
  • value: [T] - The value to be stored.

Number of Storage Accesses

  • Reads: 1
  • Writes: 1

Examples

use std::storage::storage_api::{read, write};

fn foo() {
    let five = 5_u64;
    write(b256::zero(), 2, five);
    let stored_five = read::<u64>(b256::zero(), 2).unwrap();
    assert(five == stored_five);
}