Skip to content

avaxcadabra/nft-mint

Repository files navigation

Introduction

This tutorial will explain how to :

  1. create and deploy a subnet,
  2. compile and deploy on this newly created subnet a smart contract,
  3. mint some NFTs paid with the blockchain token gouvernance created with the subnet.

Prerequisites

NodeJS and Yarn

Subnet-cli and git

Ubuntu 22.04 or similar

First, install nodejs Version 18 or more recent

curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs

Next, install yarn

sudo npm install -g yarn

Install GIT

sudo apt install -y git

And finally, install avalanche-cli

curl -sSfL https://raw.githubusercontent.com/ava-labs/avalanche-cli/main/scripts/install.sh | sudo sh -s -- -b /usr/local/bin

We install the binary of avalanche of subnet-cli in /usr/local/bin so is in your path

echo $PATH (to verify)

Create and deploy a Subnet

To install and deploy your subnet, you need to know

  1. the name of the subnet
  2. the name of the token and the ticker

Create the subnet myfactory with ticker MFY and chain ID number 123

avalanche subnet create myfactory
  • ✅ Choose your VM: SubnetEVM
  • ✅ ChainId: 123 (or what you want)
  • ✅ Select a symbol for your subnet's native token: MFY
  • ✅ What version of Subnet-EVM would you like?: Use latest version
  • ✅ How would you like to set fees: Low disk use / Low Throughput 1.5 mil gas/s (C-Chain's setting)
  • ✅ How would you like to distribute funds: Airdrop 1 million tokens to the default address (do not use in production)
  • ✅ Advanced: Would you like to add a custom precompile to modify the EVM?: No

The subnet are now created

Let deploy on local network

avalanche subnet deploy myfactory
  • ✅ Choose a network to deploy on: Local Network

Subnet-cli will print a dashboard with networks and endpoints informations

  • ✅ RPC URL: the endpoint to request your blockchain
  • ✅ Funded address and the private key to access funds
  • ✅ Network name: myfactory
  • ✅ Chain ID: 123
  • ✅ Currency Symbol: MFY

🔴 WARNING: Copy the RPC URL and private key somewhere before proceed ! 🔴

Download the web3 app

git clone https://github.com/avaxcadabra/nft-mint ;
cd nft-mint ;
yarn

Hardhat Config

Hardhat uses hardhat.config.js as configuration file. You can define tasks, networks, compilers and more in that file. For more information see here.

In our repository we use a pre-configured file hardhat.config.ts

You need to fill this file with your blockchain information

On the local network configuration, replace

  • ✅ url: put the RPC URL information given when you deploy your subnet
  • ✅ chainId: the number you put on Chain ID

Test with some tasks, if everything are ok

yarn accounts (the account address with the minted tokens you create when deploy your subnet)
yarn balances (the amount of tokens you mint, will be 1 million (base 18)

If everything going well, you are happy and rich with 1 million tokens :-)

Compile Contracts

Now you'll compile the MyNFT.sol contract

yarn compile

Now we deploy the contract on the subnet

yarn deploy

🔴 WARNING: Copy somewhere the address of the contract printed in the ouptup of the deploy command ! 🔴

Mint NFT Web3 APP

First you have to edit the file in src/components/Home.jsx and replace the 7th line :

const contractAddress = "YOUR_DEPLOYED_CONTRACT_ADDRESS" with the address of the contract copied before

Configure metamask

Now you need to access the 1 million token you minted with metamask wallet (1 million 😱)

To do this, just create a new network

In metamask app: parameters > network > create a new network

Fill with the subnet data

  • ✅ Network Name: myfactory
  • ✅ New URL RPC: put the RPC URL information given when you deploy your subnet
  • ✅ Chain ID: the number of Chain ID
  • ✅ Symbol of token: the ticker of your token

Then save

To access the address with the million token, just chose "import an account" with the private key you got when you deployd your subnet

And that's all !!! you got a little bit less then 1 million because when you have deployed the contract, you paid the fees for your subnet transactions 🙂

Let's mint some NFT (ok ok ! I'm not a professional designer)

Start the web3 app

npm run dev

Access the url on your browser http://localhost:3000

Mint and have fun !