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.
For a walkthrough of this module’s features, please see The Feature Overview.
Structs§
- Storage
Address - Accessor for a storage-backed
Address
. - Storage
Array - Accessor for a storage-backed array.
- Storage
Block Hash - Accessor for a storage-backed
BlockHash
. - Storage
Block Number - Accessor for a storage-backed
BlockNumber
. - Storage
Bool - Accessor for a storage-backed
bool
. - Storage
Bytes - Accessor for storage-backed bytes.
- Storage
Cache - Global accessor to persistent storage that relies on VM-level caching.
- Storage
Fixed Bytes - Accessor for a storage-backed
FixedBytes
. - Storage
Guard - 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
. - Storage
Guard Mut - Binds a storage accessor to a lifetime to prevent aliasing.
- Storage
Map - Accessor for a storage-backed map.
- Storage
Signed - Accessor for a storage-backed
Signed
. - Storage
String - Accessor for storage-backed bytes
- Storage
Uint - Accessor for a storage-backed
alloy_primitives::Uint
. - Storage
Vec - Accessor for a storage-backed vector.
Traits§
- Erase
- Trait for accessors that can be used to completely erase their underlying value.
Note that some collections, like
StorageMap
, don’t implement this trait. - Global
Storage - Trait for managing access to persistent storage.
Implemented by the
StorageCache
type. - Simple
Storage Type - 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.
- Storage
Key - Trait that allows types to be the key of a
StorageMap
. - Storage
Type - 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
.
Type Aliases§
- Storage
B8 - Accessor for a storage-backed
alloy_primitives::aliases::B8
. - Storage
B16 - Accessor for a storage-backed
alloy_primitives::aliases::B16
. - Storage
B32 - Accessor for a storage-backed
alloy_primitives::aliases::B32
. - Storage
B64 - Accessor for a storage-backed
alloy_primitives::aliases::B64
. - Storage
B96 - Accessor for a storage-backed
alloy_primitives::aliases::B96
. - Storage
B128 - Accessor for a storage-backed
alloy_primitives::aliases::B128
. - Storage
B160 - Accessor for a storage-backed [
alloy_primitives::aliases::B160
]. - Storage
B192 - Accessor for a storage-backed
alloy_primitives::aliases::B192
. - Storage
B224 - Accessor for a storage-backed
alloy_primitives::aliases::B224
. - Storage
B256 - Accessor for a storage-backed
alloy_primitives::aliases::B256
. - Storage
I8 - Accessor for a storage-backed
alloy_primitives::aliases::I8
. - Storage
I16 - Accessor for a storage-backed
alloy_primitives::aliases::I16
. - Storage
I32 - Accessor for a storage-backed
alloy_primitives::aliases::I32
. - Storage
I64 - Accessor for a storage-backed
alloy_primitives::aliases::I64
. - Storage
I128 - Accessor for a storage-backed
alloy_primitives::aliases::I128
. - Storage
I160 - Accessor for a storage-backed
alloy_primitives::aliases::I160
. - Storage
I192 - Accessor for a storage-backed
alloy_primitives::aliases::I192
. - Storage
I256 - Accessor for a storage-backed
alloy_primitives::aliases::I256
. - Storage
U8 - Accessor for a storage-backed
alloy_primitives::aliases::U8
. - Storage
U16 - Accessor for a storage-backed
alloy_primitives::aliases::U16
. - Storage
U32 - Accessor for a storage-backed
alloy_primitives::aliases::U32
. - Storage
U64 - Accessor for a storage-backed
alloy_primitives::aliases::U64
. - Storage
U128 - Accessor for a storage-backed
alloy_primitives::aliases::U128
. - Storage
U160 - Accessor for a storage-backed
alloy_primitives::aliases::U160
. - Storage
U192 - Accessor for a storage-backed
alloy_primitives::aliases::U192
. - Storage
U256 - Accessor for a storage-backed
alloy_primitives::aliases::U256
.