Skip to main content

Stylus Rust SDK overview

The Stylus Rust SDK (v0.10.2) lets you write Solidity ABI-equivalent smart contracts in Rust, compiled to WebAssembly and executed on Arbitrum chains. For a conceptual introduction, see Stylus: A Gentle Introduction. To deploy your first contract, see the Quickstart.

The SDK is built on Alloy, the standard Rust Ethereum primitive library. Because both share the same types, Stylus contracts are compatible with the broader Rust Ethereum ecosystem.

The SDK has been audited by OpenZeppelin:

All reports are listed on the security audit reports page.

SDK architecture

The SDK is a Cargo workspace of six crates. Most developers only interact with stylus-sdk and cargo-stylus directly — the others are internal dependencies.

CratePurpose
stylus-sdkMain SDK — storage types, ABI encoding, call abstractions, crypto, deploy, and the prelude module
stylus-procProcedural macros: #[entrypoint], #[public], #[constructor], sol_storage!, sol_interface!
stylus-coreCore trait definitions (Host, HostAccess) shared across the workspace
stylus-testTesting framework with TestVM for unit-testing contracts without a blockchain
stylus-toolsDeployment, activation, verification, and caching operations (used by cargo-stylus)
cargo-stylusCLI tool for building, deploying, debugging, and managing Stylus contracts

Requirements: Rust 1.91.0 or later (pinned in rust-toolchain.toml). Contracts compile to the wasm32-unknown-unknown target.

Feature flags

The stylus-sdk crate exposes these Cargo features:

FeatureDefaultDescription
mini-allocYesUses an efficient WASM allocator. Disable to use a custom global allocator
export-abiNoEnables ABI export via cargo stylus export-abi. Adds debug and uses tiny-keccak
debugNoEnables the console! debugging macro for printing to the Blockchain Explorer's trace view
hostioNoMakes the low-level hostio module public for direct host I/O access
stylus-testNoEnables the testing module with TestVM for writing unit tests without deploying
reentrantNoEnables reentrancy support across stylus-proc, stylus-core, and stylus-test

Public modules

The stylus-sdk crate re-exports these modules from its root:

ModuleDescription
abiABI encoding and decoding types
callCross-contract call abstractions (static calls, delegate calls, value transfers)
cryptoCryptographic utilities (keccak256)
debugThe console! macro for trace-level logging (requires the debug feature)
deployContract deployment via RawDeploy
hostVM host interface (self.vm()) for accessing block context, message data, and storage
hostioLow-level host I/O FFI bindings (requires the hostio feature to be public)
methodsMethod routing utilities
preludeCommon imports — re-exports the types most contracts need
storagePersistent storage types (StorageU256, StorageAddress, StorageMap, StorageVec, etc.)

Documentation index

Fundamentals

ArticleDescription
Structure of a contractProject layout, the #[entrypoint] macro, and #[public] methods
Global variables and functionsAccess blockchain context through self.vm() — message sender, block info, and crypto functions
ContractsStorage definition, method declarations, and the contract lifecycle
Writing testsUnit test contracts with TestVM without deploying to a blockchain

Data types

ArticleDescription
PrimitivesRust primitives (bool, integers, addresses) with automatic ABI encoding and Solidity type mappings
Compound typesArrays, vectors, tuples, and custom structs
StoragePersistent contract state using storage types and the sol_storage! macro
Conversions between typesConverting between Rust types and Solidity-compatible types

Advanced topics

ArticleDescription
Rust to Solidity differencesKey differences between writing contracts in Solidity versus Stylus Rust
Recommended packagesThird-party Rust crates that work well with Stylus
Minimal entrypoint contractsLightweight contracts with custom entrypoints for maximum gas efficiency
Hostio exportsLow-level host I/O functions for advanced contract behavior

Using the CLI

ArticleDescription
Commands referenceComplete reference for all cargo stylus commands, flags, and aliases
Verify contractsVerify deployed contracts using reproducible builds
Exporting ABIGenerate Solidity-compatible ABI files for frontend integration
Debugging with replayDebug transactions by replaying them locally with GDB, LLDB, or StylusDB
Optimizing WASM binary sizeReduce contract size for lower deployment costs
Deploying non-Rust WASM contractsDeploy contracts written in C, C++, or other languages that compile to WebAssembly

WASM concepts

ArticleDescription
WebAssemblyHow WASM compilation, deployment, and execution work in Arbitrum Nitro
VM differencesBehavioral differences between Stylus WASM execution and traditional EVM
ActivationThe contract activation process required before a Stylus contract can execute
Caching strategyLeveraging the WASM caching system for contract performance

Troubleshooting

ArticleDescription
TroubleshootingCommon issues when building and deploying Stylus contracts

External references

ResourceDescription
Stylus by ExamplePractical, annotated code examples covering common patterns
Rust SDK on docs.rsAPI documentation generated from source
Source codeComplete source for the SDK workspace