If you’re looking to get more familiar with the ERC721 contract and how to use this smart contract standard to generate NFTs using OpenZeppeline, then you’re in the right place.
BTW, to be able to follow this tutorial and create an ERC721 token, you may need to look at some of the previous articles:
And also, check this Smart Contract Masterclass to learn how to create ERC20, ERC721, and ERC1155:
NFT Art by Filip Hodas — https://superrare.com/artwork-v2/gmi-10000-29120
Okay, again, this article assumes that you have some basics, you have a Metamask with some test Ether, and you know how to use Remix. If you need additional background on this, check the links above.
1. Head to the OpenZeppeline wizard and select the option for ERC721 as seen below
2. Name your token and specify its symbol. For this demonstration, our ERC721 token is Hedgehog,, and the symbol is HHG.
The BaseURI is to specify the URI of the metadata, and the metadata is basically the image that links to our NFT and additional NFT characteristics. We will be leaving that slot empty for this demonstration, we are chiefly concerned about the mechanism for creating the token. However, if you are interested in creating the metadata, you can follow these metadata standards and store the metadata file as a json file on IPFS.
3. Next, a few selections in the Features Section. Mintable to ensure that new tokens are mintable. Auto Increment Ids to create a serial identifier for each token. These are the options we include for this demonstration.
4. Go ahead and copy your code and go to our online IDE, Remix. Create a new workspace If you’ve been following this series and have only created ERC20 tokens, it is important that ERC721 smart contracts are on a different workspace. I’ll be naming my workspace ERC721. The button to click on to create a new workspace is shown in the screenshot below.
5. Create a new file for your smart contract and call it whatever you’ve named your token, preferably. Mine is Hedgehog.sol. Go ahead and paste your code from the wizard.
6. Next, go to the compiler and select Compiler 0.8.4, and compile your code. Make sure that the compiler version is the same as the pragma solidity version of your smart contract.
7. Go to the deploy section next and select the Injected Web 3 environment and select the contract you want to deploy.
8. Click on Deploy and it should prompt your MetaMask. Go ahead and click on the MetaMask icon in the extensions section of your browser to activate it, then Deploy again. You should see the following:
YAY! 🚀 Once it is deployed, you should see the following:
The symbol option displays the symbol that we specified at the beginning, HHG. The tokenURI will be empty because we didn’t specify it.
Next, I want to demonstrate the Safemint() function. It is basically the same function you get to see on NFT websites when you mint a new NFT. First, go to Metamask and copy your address, then paste into the field. Go ahead and click on safemint and confirm; you can do it multiple times to mint multiple NFTs to your wallet.
Now we can explore a different function, balanceOf. When using this function you need to copy and paste your wallet address to get the result, it returns the number of tokens that we have minted as shown below:
The result from balanceOf() in my case is 2 because I minted the token twice. The number of times that you minted should be displayed. Also, pay attention to the terminal.
That’s the process, I hope it was as simple and relatable as they come, check out my next article on how to deploy an ERC1155 contract!
If you’re interested in Crypto, Metaverse, and NFTs, don’t forget to check these out: