Skip to main content

Prerequisites and setup

This guide will help you set up everything you need to develop Stylus contracts.

System requirements

  • Operating System: macOS, Linux, or Windows (WSL2)
  • RAM: Minimum 8GB, 16GB recommended
  • Disk Space: At least 20GB free

Install Rust

Installing Rust

You'll use Rust to write your smart contracts. Stylus compiles Rust code to WASM, which runs on the Stylus virtual machine alongside the EVM.

The Rust toolchain includes rustc (compiler), cargo (package manager), and rustup (version manager).

macOS/Linux:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Windows:

Download and run rustup-init.exe.

Configure for WASM:

rustup target add wasm32-unknown-unknown

Verify:

rustc --version
cargo --version

Install cargo-stylus CLI

Installing cargo-stylus

The Stylus CLI is your toolkit for speeding up the development process. It handles project scaffolding, building contracts to WASM, checking onchain activation, and deploying your contracts.

Windows users need WSL

cargo-stylus requires a Unix environment. On Windows, install WSL 2 and run all cargo stylus commands from the WSL terminal — native Windows command prompts are not supported.

The cargo-stylus CLI tool helps you create, build, and deploy Stylus contracts.

Install:

cargo install cargo-stylus

Verify:

cargo stylus --version

Update:

cargo install cargo-stylus --force

Install Docker (for local testnet)

Installing Docker for local testing

The Nitro devnode (and Docker) lets you spin up a local devnet to test your contracts before deploying them to an actual network. This gives you a fast feedback loop without spending testnet funds.

Running a Nitro devnode also solves the issue of having tokens to deploy and execute contracts, as the devchain gives you pre-funded accounts.

macOS:

Download Docker Desktop for Mac.

Linux:

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

Windows:

Download Docker Desktop for Windows (requires WSL2).

Start Nitro devnode:

git clone https://github.com/OffchainLabs/nitro-devnode.git
cd nitro-devnode
./run-dev-node.sh

Verify:

curl -X POST http://localhost:8547 \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'

Install Foundry

Installing Foundry

Foundry is a toolkit for Ethereum development that includes cast, a command-line tool for interacting with smart contracts, sending transactions, and querying chain data.

Install:

curl -L https://foundry.paradigm.xyz | bash
foundryup

Verify:

cast --version

Update:

foundryup

Verify installation

# Check Rust version
rustc --version

# Check cargo-stylus
cargo stylus --version

# Check Docker
docker --version

# Check Foundry's cast
cast --version

Expected output:

rustc 1.88.0 (or higher)
cargo-stylus 0.10.0 (or higher)
Docker version 24.0.0 (or higher)
cast 1.0.0 (or higher)

Next steps