Using the CLI
Learn how to set up and use the Stylus CLI to create, build, and deploy smart contracts.
Using the Stylus CLI
The Stylus CLI is your primary tool for developing smart contracts on Arbitrum Stylus. It handles project creation, compilation to WASM, and deployment.
Installation
First, ensure you have Rust installed, then install the Stylus CLI:
`` cargo install cargo-stylusbash
`
Creating a New Project
Create a new Stylus project with:
` cargo stylus new my-project cd my-projectbash
`
This creates a new Rust project with the necessary Stylus dependencies and configuration.
Building Your Contract
Compile your contract to WASM:
` cargo stylus check cargo stylus buildbash
`
The check command validates your contract without deploying, while build compiles it for deployment.
Deploying
Deploy to a Stylus-enabled chain:
` cargo stylus deploy --private-key bash
``
You'll need an RPC endpoint and a funded wallet for deployment.
Code Example
# Install Stylus CLI
cargo install cargo-stylus
# Create new project
cargo stylus new my-first-contract
cd my-first-contract
# Check contract validity
cargo stylus check
# Build for deployment
cargo stylus build
# Deploy (requires private key and RPC)
cargo stylus deploy --private-key $PRIVATE_KEY