Crate stylus_sdk

Source
Expand description

The Stylus SDK.

The Stylus SDK makes it easy to develop Solidity ABI-equivalent Stylus contracts in Rust. Included is a full suite of types and shortcuts that abstract away the details of Solidity’s storage layout, method selectors, affordances, and more, making it easy to just write Rust. For a guided exploration of the features, please see the comprehensive Feature Overview.

Some of the features available in the SDK include:

  • Generic, storage-backed Rust types for programming Solidity-equivalent smart contracts with optimal storage caching.
  • Simple macros for writing language-agnostic methods and entrypoints.
  • Automatic export of Solidity interfaces for interoperability across programming languages.
  • Powerful primitive types backed by the feature-rich Alloy.

Rust programs written with the Stylus SDK can call and be called by Solidity smart contracts due to ABI equivalence with Ethereum programming languages. In fact, existing Solidity DEXs can list Rust tokens without modification, and vice versa.

Re-exports§

pub use alloy_primitives;
pub use alloy_sol_types;
pub use hex;
pub use keccak_const;
pub use stylus_core;
pub use stylus_proc;
pub use rclite as rc;
pub use stylus_test as testing;

Modules§

abi
Solidity ABIs for Rust types.
block
VM affordances for inspecting the current block.
call
Call other contracts.
contract
VM affordances for inspecting the contract itself.
crypto
VM-accelerated cryptography.
debug
Debug-only items for printing to the console.
deploy
Deploy other contracts.
evm
Affordances for the Ethereum Virtual Machine.
host
Defines a struct that provides Stylus contracts access to a host VM environment via the HostAccessor trait defined in stylus_host. Makes contracts a lot more testable, as the VM can be mocked and injected upon initialization of a storage type. Defines two implementations, one when the stylus-test feature is enabled and another that calls the actual HostIOs.
methods
Types relating to method definitions.
msg
VM affordances for inspecting the current call.
prelude
Common imports for Stylus contracts.
storage
Solidity compatible storage types and persistent storage access.
tx
VM affordances for inspecting the current tx.
types
Traits for common types.

Macros§

console
Prints to the console when executing in a debug environment. Otherwise does nothing.
function_selector
Generates a function selector for the given method and its args.

Type Aliases§

ArbResult
Represents a contract invocation outcome.