Using Stylus CLI
This guide will get you started with cargo stylus a CLI toolkit that helps developers manage, compile, deploy, and optimize their Stylus contracts efficiently.
This overview will help you discover and learn how to use cargo stylus tools.
Installing cargo stylus
cargo stylus is a plugin to the standard cargo tool for developing Rust programs.
Prerequisites
Rust toolchain
Follow the instructions on Rust Lang's installation page to install a complete Rust toolchain (v1.91 or newer) on your system. After installation, ensure you can access the programs rustup, rustc, and cargo from your preferred terminal application.
Docker
We will use the testnet and some cargo stylus commands, which require Docker to run.
You can download Docker from Docker's website.
Foundry's Cast
Foundry's Cast is a command-line tool for interacting with your EVM contracts.
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
Installation
In your terminal, run:
cargo install --force cargo-stylus
Add WASM (WebAssembly) as a build target for the specific Rust toolchain you are using. The example below sets your default Rust toolchain to 1.91, as well as adding the WASM build target:
rustup default 1.91
rustup target add wasm32-unknown-unknown --toolchain 1.91
You can verify the cargo stylus installation by running cargo stylus -V in your terminal, returning something like:stylus 0.10.7
Using cargo stylus
cargo stylus commands reference
For the complete list of cargo stylus commands, flags, defaults, and aliases, see the commands reference.
How-tos
| Topic | Description |
|---|---|
| Learn how to optimize WASM binaries | The cargo-stylus tool allows you to optimize WebAssembly (WASM) binaries, ensuring that your contracts are as efficient as possible. |
| Debug Stylus transactions | A guide to debugging transactions, helping you identify and fix issues. Gain insights into your Stylus contracts by debugging transactions. |
| Verify contracts | Ensure that your Stylus contracts are correctly verified. Step-by-step instructions on how to verify your contracts using cargo-stylus. |
| Run a Stylus dev node | Learn how to run a local Arbitrum dev node to test your Stylus contracts. |