How to deploy a ERC-721 token on Avalanche with OpenZeppelin

https://youtu.be/nPYkfCUXzKE

This guide will help you to create a ERC-721 token which represents ownership of non-fingible tokens or NFTs. In this case, every token is unique and and the same time can be transferred between individuals.

1. Setting up Metamask

First thing you need to do is to setup a custom RPC in your Metamask in order to connect to FUJI Testnet on Avalanche C-Chain. In case you want to operate on Mainnet, please, use the data for Mainnet.

Click on the network selection tool and choose Custom RPC.

You should use following credentials depending on what network you want to interact with. In this guide we will be using FUJI Testnet.

Network Name: Avalanche C-Chain

New RPC URL:

ChainID:

  • 0xa869 for Fuji Testnet
  • 0xa86a for Mainnet

Symbol: C-AVAX

Explorer:

After selecting network you should see this page.

Next step will be requesting C-AVAX tokens.

2. Acquiring faucet tokens

In order to operate on C-CHAIN, you will need to acquire C-AVAX tokens from the faucet. Simple visit the link, provide your Ethereum address and click “REQUEST 10 AVAX”. Next, go to your Metamask and you will see updated balance. Tokens from this faucet are only for testing purposes and don’t represent any value.

3. Creating NFT token with Remix

Now it’s time to create our NFT! Visit Remix, click “SOLIDITY” and “New file”. After that, navigate to the Workspaces section (files under the logo) and see a blank file, which you should rename. In this case we name it avatest.

We will use a ERC-721 OpenZeppelin contract, so there is no need no write anything on our own, we can just write

import “https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/presets/ERC721PresetMinterPauserAutoId.sol";

After this, go to the Solidity compiler section and press “Compile”. Press the “Compile avatest.sol” and return to the file directory.

Next, go to files section and find ERC721PresetMinterPauserAutoId.sol in presets.

After this, go to the Solidity compiler section and press “Compile”. Mind the compiler version, this should be higher than your source file is. For example, in our file, it’s written pragma solidity 0.8.0 and compiler is 0.8.4, so it’s ok. If you didn't change anything in the file, you should be OK.

This contract includes the following abilities:

  • the ability for holders to burn (destroy) their tokens
  • a minter role that allows for token minting (creation)
  • a minter role that allows stopping all token transfers
  • token ID and URI auto-generation

This contract is already ready for deployment so we don’t need to change anything and can move on to “Deploy and run transactions” section which is right under Compiler icon.

4. Deployment

In this section, choose Injected Web3 environment and connect your Metamask account with C-AVAX funds we requested from the faucet. In the “CONTRACT” field, select ERC721PresetMinterPauserAutoId.sol as it’s the main contract.

Right before deployment, click the button next to “Deploy” sign and fill in the requisites:

NAME — name of the token (AVATEST)

SYMBOL — (AVATEST)

BASETOKENURI — since we want to create NFT with an image, this image should have a URL and satisfy metadata criteria like

{
“id”: 0,
“description”: “My NFT”,
“external_url”: “https://forum.openzeppelin.com/t/create-an-nft- and-deploy-to-a-public-testnet-using-truffle/2961”,
“image”: “https://twemoji.maxcdn.com/svg/1f40e.svg",
“name”: “My NFT 0”
}

For implementing an image, you will ned an image on JSON web server like this. However, if you want to skip image, just leave in blank. Press “Transact” button and confirm in Metamask.

In the lower sections, click debug and find transaction hash, copy it.

Then, navigate to the explorer and inset you txhash. You will see the wallet address (0x6F0935E3F3a53a659f6bAf938F387c626d784F84) and our NFT contract address — 0xB281Dd2aF018616e30A7dc484178122a18C6FBaf.

We have deployed our contract but now let’s mint our first NFT!

5. Minting NFT

Return to the Deploy and run transactions section and click under “Deployed contracts”. Here you can see some functions of the contract.

The one that interests us the most — the mint function. Choose an address you want to mint NFT to (in this case we are using the same address we used for creation). Insert the address and confirm in Metamask.

6. Adding NFT token to Metamask

Open your Metamask Assets and click “Add token”. Insert the contract address we previously found out (in our case — 0xB281Dd2aF018616e30A7dc484178122a18C6FBaf), token symbol — AVATEST and since NFT is non-fungible — leave decimals at 0.

Now you can see the token in you Metamask! Congratulations!

Now you can try to mint an NFT on mainnet go on to an NFT marketplace and sell it.

Professional validator, taking part in major testnets and running mainnets.