Quickstart: write a smart contract in Rust using Stylus
This guide will get you started with Stylus' basics. We'll cover the following steps:
- Setting up your development environment
- Creating a Stylus project with cargo stylus
- Checking the validity of your contract
- Deploying your contract
- Exporting your contract's ABIs
- Calling your contract
- Sending a transaction to your contract
Setting up your development environment
Prerequisites
Rust toolchain
Follow the instructions on Rust Lang's installation page to install a complete Rust toolchain (v1.88 or newer) on your system. After installation, ensure you can access the programs rustup, rustc, and cargo from your preferred terminal application.
VS Code
We recommend VSCode as the IDE of choice for its excellent Rust support, but feel free to use another text editor or IDE if you're comfortable with those.
Some helpful VS Code extensions for Rust development:
- rust-analyzer: Provides advanced features like smart code completion and on-the-fly error checks
- Error Lens: Immediately highlights errors and warnings in your code
- Even Better TOML: Improves syntax highlighting and other features for TOML files, often used in Rust projects
- Dependi: Helps manage Rust crate versions directly from the editor
Docker
The testnode we will use as well as some cargo stylus commands require Docker to operate.
You can download Docker from Docker's website.
Foundry's Cast
Foundry's Cast is a command-line tool that allows you to interact with your EVM contracts. You need to install the Foundry CLI to use Cast.
Nitro devnode
Stylus is available on Arbitrum Sepolia, but we'll use nitro devnode which has a pre-funded wallet saving us the effort of wallet provisioning or running out of tokens to send transactions.
git clone https://github.com/OffchainLabs/nitro-devnode.git
cd nitro-devnode
./run-dev-node.sh