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

Reads a value of type T from slots of 32 bytes each, starting at the location specified by slot and offset given in words.

Deprecation Notice

This function is deprecated in favor of read_quads and read_slot.
To preserve exactly the same behavior as read, use read_quads. To read a value from
a single dynamic slot of a variable size, use read_slot.

Additional Information

If the stored value crosses the boundary of a 32-byte-long storage slot, reading continues at the following slot.

If T is a zero-sized type, no storage access will occur. Storage API does not store zero-sized types in storage,
so reading from the slot and offset where a zero-sized type would be stored will return None.

Arguments

  • slot: [b256] - The storage slot from which to count the offset. The value can be read from this or the following slots.
  • 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, 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).unwrap();
    assert_eq(five, stored_five);
}