🚩 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:
- Node (>= v18.17)
- Yarn (v1 or v2+)
- Git
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 the command below to spin up the nitro devnode in Docker. This will deploy the contract and generate the ABI so you can interact with the contracts written in RUST:
bash run-dev-node.sh
This command 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.
🚨 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
-
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
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.
📊 Performance Tracking
Before submitting your challenge, you can run the performance tracking script to analyze your application:
-
Navigate to the performance tracking directory:
cd packages/nextjs/services/web3
-
Update the contract address: Open the
performanceTracking.js
file and paste the contract address that was deployed on your local node. (you can get contract address same as we have mentioned above in Docker_Img) -
Run the performance tracking script:
node performanceTracking.js
This will provide insights about the savings when you cache your deployed contract. The output will show performance analysis similar to the image below:
📝 Important: Make sure to note down the Latency Improvement and Gas Savings values from the output, as you'll need to include these metrics when submitting your challenge.
💫 Checkpoint 1: Frontend Magic
⛽ 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:
- Mint NFT
- Mint to recipient address
- Check the Owner
- Burn token
- 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
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_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 :
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):
🚀 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.
🚀 Deploying to Arbitrum Sepolia
If you want to deploy your NFT contract to the Arbitrum Sepolia testnet, follow these steps:
-
Run the Sepolia Deployment Script
Export your private key in the terminal :
export PRIVATE_KEY=your_private_key_of_your_ethereum_wallet
Open your terminal and run:
cd packages/cargo-stylus/nft bash run-sepolia-deploy.sh
This will deploy your NFT contract to Arbitrum Sepolia and output the contract address and transaction hash.
-
Configure the Frontend for Sepolia
- Go to the
packages/nextjs
directory:cd packages/nextjs
- Copy the example environment file:
cp .env.example .env
- Open the
.env
file and set the following variables:
ReplaceNEXT_PUBLIC_RPC_URL=https://sepolia-rollup.arbitrum.io/rpc NEXT_PUBLIC_PRIVATE_KEY=0xyour_private_key_of_your_ethereum_wallet
your_private_key_of_your_ethereum_wallet
with your actual Ethereum wallet private key (never share this key publicly).
- Go to the
-
Start the Frontend
yarn run dev
Your frontend will now connect to the Arbitrum Sepolia network and interact with your deployed NFT contract.
⚡️ Cache Your Deployed Contract for Faster, Cheaper Access
📖 Contracts deployed on Arbitrum Sepolia can use this command for gas benefits, time savings, and cheaper contract function calls. Our backend will benchmark and place bids on your behalf to ensure your contract is not evicted from the CacheManager contract, fully automating this process for you.
Before caching your contract, make sure you have installed the Smart Cache CLI globally:
npm install -g smart-cache-cli
After deploying your contract to Arbitrum Sepolia, you can cache your contract address using the smart-cache
CLI. Caching your contract enables:
- 🚀 Faster contract function calls by reducing lookup time
- 💸 Cheaper interactions by optimizing access to contract data
- 🌐 Seamless access to your contract from any environment or system
💡 Info: Both the
<address>
and--deployed-by
flags are mandatory when adding a contract to the cache.
📝 Simple Example
smart-cache add <CONTRACT_ADDRESS> --deployed-by <YOUR_WALLET_ADDRESS_WITH_WHOM_YOU_HAVE_DEPLOYED_CONTRACT>
🛠️ Advanced Example
smart-cache add 0xYourContractAddress \
--deployed-by 0xYourWalletAddress \
--network arbitrum-sepolia \
--tx-hash 0xYourDeploymentTxHash \
--name "YourContractName" \
--version "1.0.0"
<CONTRACT_ADDRESS>
: The address of your deployed contract (required)--deployed-by
: The wallet address you used to deploy the contract (required)--network arbitrum-sepolia
: By default, contracts are cached for the Arbitrum Sepolia network for optimal benchmarking and compatibility--tx-hash
,--name
,--version
: Optional metadata for better organization
⚠️ Warning: If you omit the required fields, the command will not work as expected.
💡 For more options, run
smart-cache add --help
.
For more in-depth details and the latest updates, visit the smart-cache-cli package on npmjs.com.
🏁 Next Steps
Explore more challenges or contribute to this project!
🏃 Head to your next challenge here.