Expand description
Procedural macros for The Stylus SDK.
You can import these via
use stylus_sdk::prelude::*;For a guided exploration of the features, please see the comprehensive Feature Overview.
Macros§
- sol_
interface - Facilitates calls to other contracts.
- sol_
storage - The types in
#[storage]are laid out in the EVM state trie exactly as they are in Solidity. This means that the fields of astructdefinition will map to the same storage slots as they would in EVM programming languages. Hence, it is often nice to define types using Solidity syntax, which makes this guarantee easier to see.
Attribute Macros§
- entrypoint
- Defines the entrypoint, which is where Stylus execution begins.
Without it the contract will fail to pass
cargo stylus check. Most commonly this macro is used to annotate the top level storagestruct. - public
- Just as with storage, Stylus SDK methods are Solidity ABI-equivalent. This means that contracts written in different programming languages are fully interoperable. You can even automatically export your Rust contract as a Solidity interface so that others can add it to their Solidity projects.
- storage
- Allows a Rust
structto be used in persistent storage.
Derive Macros§
- AbiType
- Implements the AbiType for arbitrary structs, allowing them to be used in external method return types and parameters. This derive is intended to be used within the alloy_sol_types::sol macro.
- Erase
- Some
StorageTypevalues implementErase, which provides anerase()method for clearing state. The Stylus SDK implementsErasefor all primitives, and for vectors of primitives, but not for maps. This is because a Solidity mapping does not provide iteration, and so it’s generally impossible to know which slots to clear. - Solidity
Error - Allows an error
enumto be used in method signatures.