pub fn read<T>(slot: b256, offset: u64) -> Option<T> 
Expand description

Reads a value of type T starting at the location specified by slot and offset. If the
value crosses the boundary of a storage slot, reading continues at the following slot.

Arguments

  • slot: [b256] - The storage slot to load the value from.
  • offset: [u64] - An offset, in words, from the start of slot, from which the value should be read.

Returns

  • [Option] - Option(value) if the storage slots read were valid and contain value. Otherwise,
    returns None.

Number of Storage Accesses

  • Reads: 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);
    assert(five == stored_five.unwrap());
}