π« Create a simple Counter:
π·ββοΈ You'll compile and deploy your first smart contracts. Then, you'll use a template React app full of important components and hooks. Finally, you'll deploy a Counter contract written in RUST to a public network to share with friends! π
π The final deliverable is an app that lets users interact with the counter contract. Deploy your contracts to a testnet, then build and upload your app to a public web server.
Before starting, ensure you have the following installed:
-
Rust (including
rustc,rustup, andcargo) - Install with (β οΈ Must use WSL terminal to run these commands):curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source ~/.bashrc # or restart your terminal
-
cargo-stylus
-> Install cargo-stylus with the below command:cargo install cargo-stylus
β οΈ Note for Ubuntu users: If you face issues related to pkg-config while trying to install cargo-stylus, run these commands:sudo apt update sudo apt install pkg-config sudo apt install libssl-dev sudo apt install build-essential
-
Foundry - Required for smart contract development
curl -L https://foundry.paradigm.xyz | bashAfter installation, you'll see instructions to add Foundry to your shell profile (like .bashrc or .zshrc). Usually, you can do:
export PATH="$HOME/.foundry/bin:$PATH"Add the above line to your ~/.bashrc or ~/.zshrc file, then reload your shell:
source ~/.bashrcsource ~/.zshrcfoundryupEnsure your tools are ready to use:
cargo stylus --versioncargo --versionrustup --versionrustc --versioncurl --versioncast --versionforge --version-
Open your terminal.
-
Clone the repository:
git clone -b counter https://github.com/abhi152003/speedrun_stylus.git speedrun_stylus_counter
cd speedrun_stylus_counteryarn install
-
Start the local devnode in Docker:
cd packages/stylus-demobash run-dev-node.sh
-
In a second terminal window, start your frontend:
cd speedrun_stylus_counter/packages/nextjsyarn run dev
-
Open http://localhost:3000 to see the app.
-
Open your WSL terminal.
-
Ensure you have set your Git username and email globally:
git config --global user.name "Your Name"git config --global user.email "[email protected]" -
Clone the repository:
git clone -b counter https://github.com/abhi152003/speedrun_stylus.git
cd speedrun_stylusyarn install
-
Start the local devnode in Docker:
cd packages/stylus-demobash run-dev-node.sh
-
Copy the contract address from the bash terminal output. You will need to paste this address into the
contractAddressvariable in theDebugContractcomponent.
π‘ Note: If both contract addresses are the same, you don't need to do anything - you're ready to go and interact with the stylus-based smart contracts written in RUST!
Docker_Img
-
In a second WSL terminal window, start your frontend:
cd speedrun_stylus/packages/nextjsyarn run dev
-
Open http://localhost:3000 to see the app.
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
After you have completed the setup and are ready to submit your solution, follow these steps:
-
Create a New GitHub Repository
- Go to GitHub and create a new repository (public or private as required by the challenge).
-
Set Your Local Repository's Remote URL
- In your project directory, update the remote URL to your new repository:
git remote set-url origin https://github.com/yourusername/your-repo.git
- In your project directory, update the remote URL to your new repository:
-
Push Your Code to GitHub
- Add and commit any changes if you haven't already:
git add . git commit -m "Initial commit for challenge submission"
- Push your code:
git push -u origin counter
- Add and commit any changes if you haven't already:
-
Submit Your Challenge
- Copy your repository link in the following format (without
.gitat the end):https://github.com/yourusername/your-repo - Use this link to submit your challenge as instructed.
- Copy your repository link in the following format (without
β½ You'll be redirected to the below page after you complete checkpoint 0
Then you have to click on the debug contracts to start interacting with your contract. Click on "Debug Contracts" from the Navbar or from the Debug Contracts Div placed in the middle of the screen
The interface allows you to:
- Set any number
- Add numbers
- Increment count
- Perform multiplications
- Track all transactions in the Block Explorer
After that, you can easily view all of your transactions from the Block Explorer Tab
πΌ Take a quick look at your deploy script run-dev-node.sh in speedrun-rust/packages/stylus-demo/run-dev-node.sh.
π If you want to edit the frontend, navigate to speedrun-rust/packages/nextjs/app and open the specific page you want to modify. For instance: /debug/page.tsx. For guidance on routing and configuring pages/layouts checkout the Next.js documentation.
π° You don't need to provide any specifications to deploy your contract because contracts are automatically deployed from the run-dev-node.sh
You can check that below :
The above command will automatically deploy the contract functions written inside speedrun_stylus/packages/stylus-demo/src/lib.rs
This local account will deploy your contracts, allowing you to avoid entering a personal private key because the deployment happens using the pre-funded account's private key.
We are deploying all the RUST contracts at the
localhost:8547endpoint where the nitro devnode is spinning up in Docker. You can check the network where your contract has been deployed in the frontend (http://localhost:3000):
π Deploy your NextJS App
yarn vercelFollow the steps to deploy to Vercel. Once you log in (email, github, etc), the default options should work. It'll give you a public URL.
If you want to redeploy to the same production URL you can run
yarn vercel --prod. If you omit the--prodflag it will deploy it to a preview/test URL.
yarn testYou can verify your smart contract by running:
cargo stylus verify -e http://127.0.0.1:8547 --deployment-tx "$deployment_tx"cargo stylus deploy -e http://127.0.0.1:8547 --private-key "$your_private_key"It is okay if it says your contract is already verified.
π Head to your next challenge here.





