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.
| Article | Description |
|---|---|
| Structure of a contract | Understand how Rust contracts are organized, including project layout, the entrypoint macro, and public methods. |
| Global variables and functions | Access blockchain context through the VM interface, including message sender, block info, and cryptographic functions. |
| Contracts | Learn about contract basics, storage definition, method declarations, and the contract lifecycle. |
| Writing tests | Write 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.
| Article | Description |
|---|---|
| Primitives | Use Rust primitive types (bool, integers, addresses) with automatic ABI encoding and Solidity type mappings. |
| Compound types | Work with complex data structures including arrays, vectors, tuples, and custom structs. |
| Storage | Define and manage persistent contract state using storage types and the storage macro. |
| Conversions between types | Convert between Rust types and Solidity-compatible types for cross-contract communication. |
Advanced topics
Explore advanced features and optimization techniques for Stylus development.
| Article | Description |
|---|---|
| Rust to Solidity differences | Understand key differences between writing smart contracts in Solidity versus Stylus Rust. |
| Recommended packages | Discover third-party Rust crates that work well with Stylus for extended functionality. |
| Minimal entrypoint contracts | Build lightweight contracts with custom entrypoints for maximum gas efficiency. |
| Hostio exports | Access 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.
| Article | Description |
|---|---|
| Verify contracts | Verify your deployed contracts on block explorers for transparency and trust. |
| Exporting ABI | Generate Solidity-compatible ABI files for integration with frontend apps and tooling. |
| Debugging with replay | Debug failed transactions by replaying them locally with detailed execution traces. |
| Optimizing WASM binary size | Reduce contract size for lower deployment costs and improved activation efficiency. |
| Deploying non-Rust WASM contracts | Deploy 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.
| Article | Description |
|---|---|
| WebAssembly | Learn how WASM compilation, deployment, and execution work in Arbitrum Nitro. |
| VM differences | Understand behavioral differences between Stylus WASM execution and traditional EVM. |
| Activation | Learn about the contract activation process required before a Stylus contract can execute. |
| Caching strategy | Optimize contract performance by understanding and leveraging the WASM caching system. |
Troubleshooting
| Article | Description |
|---|---|
| Troubleshooting | Find solutions to common issues encountered when building and deploying Stylus contracts. |
External references
Additional resources for Stylus development.
| Resource | Description |
|---|---|
| Stylus by Example | Learn Stylus through practical, annotated code examples covering common patterns. |
| Cargo Stylus CLI GitHub | Source code and documentation for the cargo stylus command-line tool. |
| Rust SDK Crate | Official API documentation for the Stylus SDK on docs.rs. |
| Source Code Repository | Browse the complete source code for the Stylus Rust SDK. |