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§

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 and EagerStorage 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§