🚩 Challenge #1: 🎟 Simple NFT Example

⚠️ Important: Please complete Challenge #0 first if you haven't already, as it contains essential instructions related to dependencies needed for all upcoming challenges.

🎫 Create a simple NFT project:

👷‍♀️ In this project, you'll build and deploy smart contracts to create, manage, and interact with NFTs. Use a React-based frontend to enable users to mint NFTs, assign them to specific addresses, check token ownership, and burn tokens directly. 🚀

🌟 The final deliverable is an app that lets users interact with the NFT contract. Deploy your contracts to a testnet, then build and upload your app to a public web server.

Checkpoint 0: 📦 Environment Setup 📚

Before you begin, you need to install the following tools:

Then download the challenge to your computer and install dependencies by running:

⚠️ IMPORTANT: Please make sure to run the below commands through WSL only. In PowerShell, you'll get an error because some files are not supported on Windows.

git clone -b nft https://github.com/abhi152003/speedrun_stylus
cd speedrun_stylus
yarn install

In the same terminal, after all the dependencies have installed, run the below commands to start the local devnode in Docker. You'll need to spin up the Stylus nitro devnode by running the script through commands. This script will deploy the contract and generate the ABI so you can interact with the contracts written in RUST:

Contracts will be deployed through the cargo stylus command using the pre-funded account's private key so users can perform any transaction through the frontend while interacting with the contract.

cd speedrun_stylus # if not done
cd packages
cd cargo-stylus
cd nft

Now open your Docker desktop and then return to your IDE and run bash run-dev-node.sh. This will spin up the nitro devnode in Docker. You can check it out in your Docker desktop. This will take some time to deploy the RUST contract, and then the script will automatically generate the ABI. You can view all these transactions in your terminal and Docker desktop. The Docker node is running at localhost:8547, but before running this command make sure about below thing

🚨 Fixing Line Endings and Running Shell Scripts in WSL on a CRLF-Based Windows System

⚠️ 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.


🛠️ Steps to Fix the Issue

Convert Line Endings to LF

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

  1. Install dos2unix (if not already installed):

    sudo apt install dos2unix
    
  2. Convert the script's line endings:

    dos2unix run-dev-node.sh
    
  3. Make the Script Executable:

    chmod +x run-dev-node.sh
    
  4. Run the Script in WSL

    bash run-dev-node.sh
    

Then in a second WSL terminal window, you can run below commands to start your 📱 frontend:

cd speedrun_stylus ( if not done )
cd packages ( if not done )
cd nextjs
yarn run dev OR yarn dev

📱 Open http://localhost:3000 to see the app.


💫 Checkpoint 1: Frontend Magic

⛽ You'll be redirected to the below page after you complete checkpoint 0

image

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

image

The interface allows you to:

  1. Mint NFT
  2. Mint to recipient address
  3. Check the Owner
  4. Burn token
  5. Track all transactions in the Block Explorer

Below are the examples of above all interactions that can be done with the NFT smart contract written in the RUST

image

image

image

After that, you can easily view all of your transactions from the Block Explorer Tab

image

💼 Take a quick look at your deploy script run-dev-node.sh in speedrun_stylus/packages/cargo-stylus/nft/run-dev-node.sh.

📝 If you want to edit the frontend, navigate to speedrun_stylus/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.


Checkpoint 2: 💾 Deploy your contract! 🛰

🛰 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 :

image

The above command will automatically deploy the contract functions written inside speedrun_stylus/packages/cargo-stylus/nft/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.

Checkpoint 3: 🚢 Ship your frontend! 🚁

We are deploying all the RUST contracts at the localhost:8547 endpoint 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):

image

🚀 Deploy your NextJS App

vercel

Follow 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 --prod flag it will deploy it to a preview/test URL.

Checkpoint 4: 📜 Contract Verification

You can verify your smart contract by running:

cargo stylus verify -e http://127.0.0.1:8547 --deployment-tx "$deployment_tx"
# here deployment_tx can be received through the docker desktop's terminal when you have depoloyed your contract using the below command:

cargo stylus deploy -e http://127.0.0.1:8547 --private-key "$your_private_key"
# here you can use pre-funded account's private-key as well

It is okay if it says your contract is already verified.


🏁 Next Steps

Explore more challenges or contribute to this project!

🏃 Head to your next challenge here.