Skip to main content

Using Stylus CLI

This guide will get you started using cargo stylus is a CLI toolkit built to facilitate the development of Stylus contracts.

It is available as a plugin to the standard cargo tool used for developing Rust programs.

Installing cargo stylus

Prerequisites

Rust toolchain

Follow the instructions on Rust Lang's installation page to install a complete Rust toolchain (v1.81 or older, v1.82 is currently not supported) on your system. After installation, ensure you can access the programs rustup, rustc, and cargo from your preferred terminal application.

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 below example sets your default Rust toolchain to 1.80 as well as adding the WASM build target:

rustup default 1.80
rustup target add wasm32-unknown-unknown --toolchain 1.80

You can verify that cargo stylus is installed by running cargo stylus -V in your terminal, returning something like:stylus 0.5.6

Using cargo stylus

Cargo Stylus Commands

CommandDescriptionOptions
newCreate a new Stylus project• name: Project name (required)
• --minimal: Create a minimal contract
initInitialize a Stylus project in current directory• --minimal: Create a minimal contract
export-abiExport a Solidity ABI• --output: Output file (defaults to stdout)
• --json: Write JSON ABI using solc
activateActivate an already deployed contract• --address: Contract address to activate
• --data-fee-bump-percent: Percent to bump estimated fee (default 20%)
• --estimate-gas: Only estimate gas without sending tx
cacheCache contract using Stylus CacheManagerSubcommands:
• bid: Place bid on contract
• status: Check contract status
• suggest-bid: Get suggested minimum bid
checkCheck a contract• --wasm-file: WASM to check
• --contract-address: Deploy address
deployDeploy a contract• --estimate-gas: Only perform estimation
• --no-verify: Skip reproducible container
• --cargo-stylus-version: Version for Docker image
verifyVerify contract deployment• --deployment-tx: Hash of deployment tx
• --no-verify: Skip reproducible container
• --cargo-stylus-version: Version for Docker image
cgenGenerate C code bindings• input: Input file path
• out_dir: Output directory path
replayReplay transaction in gdb• --stable-rust: Use stable Rust
• --child: Child process flag
traceTrace a transaction• --endpoint: RPC endpoint
• --tx: Transaction hash
• --project: Project path
• --use-native-tracer: Use native tracer
Common Options

These options are available across multiple commands:

OptionDescription
--endpointArbitrum RPC endpoint (default: http://localhost:8547)
--verbosePrint debug info
--source-files-for-project-hashPaths to source files for project hash
--max-fee-per-gas-gweiOptional max fee per gas in gwei
Authentication Options

Available for commands involving transactions:

OptionDescription
--private-key-pathPath to file containing hex-encoded private key
--private-keyPrivate key as hex string (exposes to shell history)
--keystore-pathPath to Ethereum wallet keystore file
--keystore-password-pathKeystore password file path

Example Usage

Create a new Stylus project

cargo stylus new my_project

Initialize a Stylus project in the current directory

cargo stylus init

Export a Solidity ABI

cargo stylus export-abi --output abi.json

Activate an already deployed contract

cargo stylus activate --address 0x1234567890123456789012345678901234567890

Deploy a contract

cargo stylus deploy --RPC-endpoint http://localhost:8547 --private-key-path /path/to/private-key --max-fee-per-gas-gwei 100

Cache a contract using the Stylus CacheManager for Arbitrum chains

cargo stylus cache bid --address 0x1234567890123456789012345678901234567890

Verify a contract deployment

cargo stylus verify --deployment-tx 0x1234567890123456789012345678901234567890

Feel free to explore the Stylus Rust SDK reference for more information on using Stylus in your Arbitrum projects.