Module stylus_sdk::storage
source · Expand description
Solidity compatible storage types and persistent storage access.
The Stylus node software is composed of two, fully-composable virtual machines.
- The Stylus VM, which compiles WASM contracts built with SDKs like this one.
- The Ethereum Virtual Machine, which interprets EVM bytecode from languages like Solidity and Vyper.
Though these two VMs differ in execution, they are backed by the same EVM State Trie. This means that Stylus contracts have access to the same, key-value based persistent storage familiar to Solidity devs.
Because this resource is foreign to Rust, this module provides standard types and traits for
accessing state when writing programs. To protect the user, the Stylus SDK safeguards storage access
by leveraging Rust’s borrow checker. It should never be possible to alias Storage without unsafe
Rust,
eliminating entire classes of errors at compile time.
Storage Operations are also cached by default, ensuring that efficient usage is clean and auditable.
For a walkthrough of this module’s features, please see The Feature Overview.
Structs§
- Accessor for a storage-backed
Address
. - Accessor for a storage-backed array.
- Accessor for a storage-backed
BlockHash
. - Accessor for a storage-backed
BlockNumber
. - Accessor for a storage-backed
bool
. - Accessor for storage-backed bytes.
- Global accessor to persistent storage that relies on VM-level caching.
- Accessor for a storage-backed
FixedBytes
. - Binds a storage accessor to a lifetime to prevent aliasing. Because this type doesn’t implement
DerefMut
, mutable methods on the accessor aren’t available. For a mutable accessor, seeStorageGuardMut
. - Binds a storage accessor to a lifetime to prevent aliasing.
- Accessor for a storage-backed map.
- Accessor for a storage-backed
Signed
. - Accessor for storage-backed bytes
- Accessor for a storage-backed
alloy_primitives::Uint
. - Accessor for a storage-backed vector.
Traits§
- Trait for accessors that can be used to completely erase their underlying value. Note that some collections, like
StorageMap
, don’t implement this trait. - Trait for managing access to persistent storage. Notable implementations include the
StorageCache
andEagerStorage
types. - Trait for simple accessors that store no more than their wrapped value. The type’s representation must be entirely inline, or storage leaks become possible. Note: it is a logic error if erasure does anything more than writing the zero-value.
- Trait that allows types to be the key of a
StorageMap
. - Accessor trait that lets a type be used in persistent storage. Users can implement this trait to add novel data structures to their contract definitions. The Stylus SDK by default provides only solidity types, which are represented
the same way
. - Trait for top-level storage types, usually implemented by proc macros. Top-level types are special in that their lifetimes track the entirety of all the EVM state-changes throughout a contract invocation.
Type Aliases§
- Accessor for a storage-backed
alloy_primitives::aliases::B8
. - Accessor for a storage-backed
alloy_primitives::aliases::B16
. - Accessor for a storage-backed
alloy_primitives::aliases::B32
. - Accessor for a storage-backed
alloy_primitives::aliases::B64
. - Accessor for a storage-backed
alloy_primitives::aliases::B96
. - Accessor for a storage-backed
alloy_primitives::aliases::B128
. - Accessor for a storage-backed [
alloy_primitives::aliases::B160
]. - Accessor for a storage-backed
alloy_primitives::aliases::B192
. - Accessor for a storage-backed
alloy_primitives::aliases::B224
. - Accessor for a storage-backed
alloy_primitives::aliases::B256
. - Accessor for a storage-backed
alloy_primitives::aliases::I1
. - Accessor for a storage-backed
alloy_primitives::aliases::I8
. - Accessor for a storage-backed
alloy_primitives::aliases::I16
. - Accessor for a storage-backed
alloy_primitives::aliases::I32
. - Accessor for a storage-backed
alloy_primitives::aliases::I64
. - Accessor for a storage-backed
alloy_primitives::aliases::I128
. - Accessor for a storage-backed
alloy_primitives::aliases::I160
. - Accessor for a storage-backed
alloy_primitives::aliases::I192
. - Accessor for a storage-backed
alloy_primitives::aliases::I256
. - Accessor for a storage-backed
alloy_primitives::aliases::U1
. - Accessor for a storage-backed
alloy_primitives::aliases::U8
. - Accessor for a storage-backed
alloy_primitives::aliases::U16
. - Accessor for a storage-backed
alloy_primitives::aliases::U32
. - Accessor for a storage-backed
alloy_primitives::aliases::U64
. - Accessor for a storage-backed
alloy_primitives::aliases::U128
. - Accessor for a storage-backed
alloy_primitives::aliases::U160
. - Accessor for a storage-backed
alloy_primitives::aliases::U192
. - Accessor for a storage-backed
alloy_primitives::aliases::U256
.