Skip to main content

Stylus Rust SDK overview

This section provides an in-depth overview of the features provided by the Stylus Rust SDK. For information about deploying Rust smart contracts, see the cargo stylus CLI Tool. For a conceptual introduction to Stylus, see Stylus: A Gentle Introduction. To deploy your first Stylus smart contract using Rust, refer to the Quickstart.

The Stylus Rust SDK is built on top of Alloy, a collection of crates empowering the Rust Ethereum ecosystem. Because the SDK uses the same Rust primitives for Ethereum types, Stylus is compatible with existing Rust libraries.

The Stylus Rust SDK has been audited in August 2024 at commit #62bd831 by Open Zeppelin which can be viewed on our audits page.

Documentation index

Use this index to navigate the Stylus Rust SDK reference documentation.

Fundamentals

Learn the core concepts of writing smart contracts with the Stylus Rust SDK.

ArticleDescription
Structure of a contractUnderstand how Rust contracts are organized, including project layout, the entrypoint macro, and public methods.
Global variables and functionsAccess blockchain context through the VM interface, including message sender, block info, and cryptographic functions.
ContractsLearn about contract basics, storage definition, method declarations, and the contract lifecycle.
Writing testsWrite and run tests for your contracts using the built-in testing framework without deploying to a blockchain.

Data types

Understand how to work with different data types in Stylus contracts.

ArticleDescription
PrimitivesUse Rust primitive types (bool, integers, addresses) with automatic ABI encoding and Solidity type mappings.
Compound typesWork with complex data structures including arrays, vectors, tuples, and custom structs.
StorageDefine and manage persistent contract state using storage types and the storage macro.
Conversions between typesConvert between Rust types and Solidity-compatible types for cross-contract communication.

Advanced topics

Explore advanced features and optimization techniques for Stylus development.

ArticleDescription
Solidity differencesUnderstand key differences between writing smart contracts in Solidity versus Stylus Rust.
Recommended packagesDiscover third-party Rust crates that work well with Stylus for extended functionality.
Minimal entrypoint contractsBuild lightweight contracts with custom entrypoints for maximum gas efficiency.
Hostio exportsAccess low-level host I/O functions for advanced contract behavior.

Using the CLI

Master the cargo stylus command-line tool for contract development and deployment.

ArticleDescription
Verify contractsVerify your deployed contracts on block explorers for transparency and trust.
Exporting ABIGenerate Solidity-compatible ABI files for integration with frontend apps and tooling.
Debugging with replayDebug failed transactions by replaying them locally with detailed execution traces.
Optimizing WASM binary sizeReduce contract size for lower deployment costs and improved activation efficiency.
Deploying non-Rust WASM contractsDeploy contracts written in C, C++, or other languages that compile to WebAssembly.

WASM concepts

Understand how WebAssembly works within Arbitrum Nitro and its implications for Stylus development.

ArticleDescription
WebAssemblyLearn how WASM compilation, deployment, and execution work in Arbitrum Nitro.
EVM differencesUnderstand behavioral differences between Stylus WASM execution and traditional EVM.
ActivationLearn about the contract activation process required before a Stylus contract can execute.
Caching strategyOptimize contract performance by understanding and leveraging the WASM caching system.

Troubleshooting

ArticleDescription
TroubleshootingFind solutions to common issues encountered when building and deploying Stylus contracts.

External references

Additional resources for Stylus development.

ResourceDescription
Stylus by ExampleLearn Stylus through practical, annotated code examples covering common patterns.
Cargo Stylus CLI GitHubSource code and documentation for the cargo stylus command-line tool.
Rust SDK CrateOfficial API documentation for the Stylus SDK on docs.rs.
Source Code RepositoryBrowse the complete source code for the Stylus Rust SDK.