🧪 An open-source, up-to-date toolkit for building decentralized applications (dapps) on the Arbitrum blockchain. It's designed to make it easier for developers to create and deploy smart contracts and build user interfaces that interact with those contracts.
⚙️ Built using Rust, NextJS, RainbowKit, Stylus, Wagmi, Viem, and TypeScript.
- ✅ Contract Hot Reload: Your frontend auto-adapts to your smart contract as you edit it.
- 🪝 Custom hooks: Collection of React hooks wrapped around wagmi to simplify interactions with smart contracts with TypeScript autocompletion.
- 🧱 Components: Collection of common web3 components to quickly build your frontend.
- 🔥 Burner Wallet & Local Faucet: Quickly test your application with a burner wallet and local faucet.
- 🔐 Integration with Wallet Providers: Connect to different wallet providers and interact with the Arbitrum network.
Before you begin, you need to install the following tools:
- Node (>= v20.18)
- Yarn (v2+)
- Git
- Rust
- Docker
- Foundry Cast
To get started with Scaffold-Stylus, follow the steps below:
git clone https://github.com/Arb-Stylus/scaffold-stylus.git
cd scaffold-stylus
yarn install
# Initialize submodules (required for Nitro dev node)
git submodule update --init --recursiveInstall Rust, and then install the Stylus CLI tool with Cargo:
cargo install --force cargo-stylus cargo-stylus-checkPrerequisite:
cargo-stylusversion^0.6.1rustcversion match withpackages/stylus/your-contract/rust-toolchain.toml
Set default toolchain match rust-toolchain.toml and add the wasm32-unknown-unknown build target to your Rust compiler:
rustup default 1.87
rustup target add wasm32-unknown-unknown --toolchain 1.87You should now have it available as a Cargo subcommand:
cargo stylus --helpIn your first terminal:
yarn chainThis command starts a local Stylus-compatible network using the Nitro dev node script (./nitro-devnode/run-dev-node.sh). The network runs on your local machine and can be used for testing and development. You can customize the Nitro dev node configuration in the nitro-devnode submodule.
In your second terminal:
yarn deployThis command deploys a test smart contract to the local network. The contract is located in packages/stylus/your-contract/src and can be modified to suit your needs. The yarn deploy command uses the deploy script located in packages/stylus/scripts to deploy the contract to the network. You can also customize the deploy script .
In your third terminal:
yarn startVisit your app at: http://localhost:3000. You can interact with your smart contract using the Debug Contracts page, which provides a user-friendly interface for testing your contract's functions and viewing its state.
yarn stylus:test- Edit your smart contract
lib.rsinpackages/stylus/your-contract/src - Edit your frontend in
packages/nextjs/app - Edit your deployment scripts in
packages/stylus/scripts
Scaffold-Stylus enables you to create and deploy multiple contracts within a single project. Follow the steps below to create and deploy your own contracts.
Use the following command to create a new contract and customize it as needed:
yarn new-module <contract-name>The generated contract will be located in packages/stylus/<contract-name>.
yarn deploy [...options]This command runs the deploy.ts script located in packages/stylus/scripts. You can customize this script with your deployment logic.
Available Options:
--network <network>: Specify which network to deploy to--estimate-gas: Only perform gas estimation without deploying--max-fee=<maxFee>: Set maximum fee per gas in gwei
Note: Deployment information is automatically saved in packages/stylus/deployments by default.
To deploy your contracts to other networks (other than the default local Nitro dev node), you'll need to configure your RPC endpoint and wallet credentials.
-
Set the RPC URL
Configure your target network's RPC endpoint using the proper
RPC_URL_<network>environment variable. You can set this in your shell or create a.envfile (see.env.examplefor reference):RPC_URL_SEPOLIA=https://your-network-rpc-url
Note: If RPC URL is not provided, system will use default public RPC URL from that network
-
Set the Private Key
For real deployments, you must provide your own wallet's private key. Set the
PRIVATE_KEY_<network>environment variable:PRIVATE_KEY_SEPOLIA=your_private_key_here
Security Note: A development key is used by default when running the Nitro dev node locally, but for external deployments, you must provide your own private key.
-
Set the Account Address
Set the
ACCOUNT_ADDRESS_<network>ACCOUNT_ADDRESS_SEPOLIA=your_account_address_here
-
Update Frontend Configuration
Open
packages/nextjs/scaffold.config.tsand update thetargetNetworksarray to include your target chain. This ensures your frontend connects to the correct network and generates the proper ABI indeployedContracts.ts:import * as chains from "viem/chains"; // ... targetNetworks: [chains.arbitrumSepolia],
This template supports Arbitrum networks only. You can test which networks are available and their RPC URLs:
yarn test:networksThis will show you all supported networks and their corresponding RPC endpoints.
Once configured, deploy to your target network:
yarn deploy --network <network>Important Security Notes:
- The values in
.env.exampleprovide a template for required environment variables - Always keep your private key secure and never commit it to version control
- Consider using environment variable management tools for production deployments
Your contract must meet Arbiscan's verification requirements:
- No external libraries
- No constructor arguments
- No custom optimization settings
- No specific compiler version requirements
Check full documentation for more details
Make sure your constructor does not contain any args
pub fn constructor(&mut self)The scaffold includes built-in local verification to ensure your Stylus contract deployments are reproducible. To enable verification during deployment, set verify: true in your deployment script:
await deployStylusContract({
contract: "your-contract",
verify: true,
...deployOptions,
});This runs cargo stylus verify locally after deployment, which:
- Verifies that the deployed bytecode matches your source code
- Ensures reproducibility across different environments
- Validates the deployment transaction
Note: This feature is still under development and may not work as expected. Check full documentation for more details
For public verification on Arbiscan, follow these steps:
- Create a dedicated repository containing only your contract source code
- Navigate to Arbiscan:
- Go to Arbiscan Verify Contract
- Enter your deployed contract address
- Follow the verification process:
- Select "Solidity (Standard-Json-Input)" as the compiler type
- Enter your contract source code (github link)
- Provide any constructor arguments if applicable
- Submit for verification
Check official document for detail instructions: https://docs.arbitrum.io/stylus/how-tos/verifying-contracts-arbiscan
Note: Arbiscan verification for Stylus contracts is still evolving. If you encounter issues, consider using the local verification method or check Arbiscan's latest documentation for Stylus-specific instructions.
If you encounter an error stating that stylus is not recognized as an external or internal command, run the following command in your terminal:
sudo apt-get update && sudo apt-get install -y pkg-config libssl-devAfter that, check if stylus is installed by running:
cargo stylus --versionIf the version is displayed, stylus has been successfully installed and the path is correctly set.
If you face issues with the ABI not being generated, you can try one of the following solutions:
-
Restart Docker Node: Pause and restart the Docker node and the local setup of the project. You can do this by deleting all ongoing running containers and then restarting the local terminal using:
yarn run dev
-
Modify the Script: In the
run-dev-node.shscript, replace the line:cargo stylus export-abi
with:
cargo run --manifest-path=Cargo.toml --features export-abi
-
Access Denied Issue: If you encounter an access denied permission error during ABI generation, run the following command and then execute the script again:
sudo chown -R $USER:$USER target
⚠️ This guide provides step-by-step instructions to resolve the Command not found error caused by CRLF line endings in shell scripts when running in a WSL environment.
Shell scripts created in Windows often have CRLF line endings, which cause issues in Unix-like environments such as WSL. To fix this:
Using dos2unix:
-
Install
dos2unix(if not already installed):sudo apt install dos2unix
-
Convert the script's line endings:
dos2unix run-dev-node.sh
-
Make the Script Executable:
chmod +x run-dev-node.sh
-
Run the Script in WSL:
bash run-dev-node.sh
Visit our docs to learn how to start building with Scaffold-Stylus.
To learn more about its features, check out our website.
We welcome contributions to Scaffold-Stylus!
Please see CONTRIBUTING.md for more information and guidelines for contributing to Scaffold-Stylus.
