Persistent key-value storage for a single contract account: a mapping from 256-bit slot keys to 256-bit values.
Uninitialized slots return 0. All values are masked to 256 bits on write.
Summary
Functions
Loads a value from a storage slot.
Creates a new empty storage.
Creates storage pre-loaded with initial slot values.
Stores a value into a storage slot.
Returns the storage contents as a map for inspection.
Types
@type t() :: %EEVM.Storage{slots: %{required(non_neg_integer()) => non_neg_integer()}}
Functions
@spec load(t(), non_neg_integer()) :: non_neg_integer()
Loads a value from a storage slot.
Returns 0 for uninitialized slots — the EVM treats all 2^256 slots as existing with a default value of 0.
Example
iex> storage = EEVM.Storage.new()
iex> EEVM.Storage.load(storage, 42)
0
@spec new() :: t()
Creates a new empty storage.
@spec new(%{required(non_neg_integer()) => non_neg_integer()}) :: t()
Creates storage pre-loaded with initial slot values.
Useful for testing or simulating contract state.
Example
iex> storage = EEVM.Storage.new(%{0 => 42, 1 => 100})
iex> EEVM.Storage.load(storage, 0)
42
@spec store(t(), non_neg_integer(), non_neg_integer()) :: t()
Stores a value into a storage slot.
Returns the updated storage. Writing 0 to a slot is valid and keeps the key in the map (in a production EVM, this could trigger a gas refund).
Example
iex> storage = EEVM.Storage.new() |> EEVM.Storage.store(0, 42)
iex> EEVM.Storage.load(storage, 0)
42
@spec to_map(t()) :: %{required(non_neg_integer()) => non_neg_integer()}
Returns the storage contents as a map for inspection.