Develop, Deploy, Verify an NFT (ERC721) token with Hardhat and Ethers.js

WEB3 MENTORING PROGRAM
👉 Apply here: https://bit.ly/3gteqcP

3 month mentoring program to become a professional Web3 developer Build a killer portfolio of Web3 projects to get a 6 figure job

👉 Program: https://bit.ly/3f7dmej
👉 Testimonials: https://bit.ly/3gteNUL
👉 Questions? julien [at] eattheblocks [dot] com

==
ERC-721 is a free, open standard that describes how to build non-fungible tokens on the Ethereum blockchain. All ERC-721 tokens are unique from one another. During this tutorial I’ll go through how to develop, deploy and verify an ERC-721 token while using Hardhat.

Keep in mind that this is going to be bare bones NFT. We’re just going to implement the essentials of what it takes to make an ERC721 contract for Ethereum. This basic NFT concept could be expanded and be made into something far more interesting but that would take more time and development. Anyway, let’s get into it.

Hey, my name is Anthony. At Eat The Blocks, we help teach web3 development.

The first thing that we want to do is open a Terminal and navigate to our desktop.

Let’s make a folder for our project.

And now CD into that folder.

We have to install all of these dependencies for our project in order to do what we want it to do, which is deploy and verify an ERC721 token on Ethereum. We’re also setting up Hardhat which is a JavaScript framework and it’s going to help us deploy and verify  our smart contract.

The install of these installs might take some time to finish so just sit back, be patient but once they are installed you can open up your project in a code editor.

Now that we have our project open in a code editor let’s first change the name of our smart contract. This contract came with Hardhat and it’s just a template so we can do whatever we want to it.

Let’s name our contract: OneOfAKind.sol

As we jump into our template contract that came with Hardhat, We can delta everything inside of this contract that we don’t actually need and modify it to do what we want it to do, so let’s add our token name at the top.

We have to import one of the OpenZeppelin contracts that we installed called ERC721 and we’ll inherit that contract into our own smart contract to implement this NFT function that we want to do.

Inside of a constructor we’ll set some parameters for our token and give it a name and a symbol.

That’s literally it! Here is a very simple ERC721 NFT token. It has everything that we need for this demonstration so now we can move onto the next part…

We now have to modify the hardhat configuration script which is going to be necessary for actually communicating with a node provider url and our metamask account.

At the top of the hardhat config script we have to import a few things such as the Nomic Labs plugin for Etherscan and a dotenv dependency.

Let’s also specify the network that we want to actually deploy to today. In our case we want to deploy to the Ethereum goerli testnet

We also want to set up the etherscan plugin apiKey so that we can verify this contract with hardhat after we deploy it.

Now we have to modify our deploy script in order to successfully deploy our token with hardhat.

We can delete everything inside of this file that we don’t need.

Ethers.js is a great library for Ethereum development. We’ll use it for defining our token during the deployment process. Basically, Ether.js is communication with our smart contract and setting up the token credentials from inside of our constructor function. Here we can specify our token name and its symbol. And then console.log our deployment so it’ll let us know if our token was successfully deployed or not.

After we complete our deploy script we want to create a dotenv file that holds our sensitive information such as our metamask private key, our alchemy node url endpoint and an etherscan apiKey. You never want to share this information with anybody because you’ll be vulnerable to hacks. So it’s best practice to really keep this information private no matter what. Once you set your variables and match the same variables from your hardhat config file, then your project will actually be able to communicate with Alchemy, Metamask and Etherscan.

Also add “Dot Config” to the end of this require statement.

Finally we can start the deployment process by opening up a terminal and compiling our contract to check for any errors that may pop up.

Since we don’t have any errors we can now deploy our contract with hardhat to the Ethereum Goerli testnet and we’ll use this command to do that. Keep in mind that the actual deployment process will take some time because now we’re interacting with Ethereum and our contract needs to be processed by a Validator in order to be published on the blockchain.

Ok sweet! It looks like our deployment was successful and here is our smart contract address that we can now view on the Etherscan.

If you’ve made it this far, congratulate yourself because you now deployed an NFT to an Ethereum testnet…

(Visited 2 times, 1 visits today)

You might be interested in

LEAVE YOUR COMMENT

Your email address will not be published. Required fields are marked *

eos
EOS (EOS) 0,883336 1,57%
aave
Aave (AAVE) 58,50 1,26%
the-graph
The Graph (GRT) 0,060058 1,02%
kusama
Kusama (KSM) 25,60 4,47%
waves
Waves (WAVES) 2,23 0,16%
dash
Dash (DASH) 41,27 7,86%
bitcoin
Bitcoin (BTC) 15.812,73 1,38%
ethereum
Ethereum (ETH) 1.167,02 3,31%
cardano
Cardano (ADA) 0,296700 0,05%
tether
Tether (USDT) 0,965580 0,06%
xrp
XRP (XRP) 0,377572 1,19%
solana
Solana (SOL) 12,89 0,00%
polkadot
Polkadot (DOT) 5,07 1,48%
usd-coin
USD Coin (USDC) 0,965580 0,10%
dogecoin
Dogecoin (DOGE) 0,097459 5,07%
uniswap
Uniswap (UNI) 5,23 3,05%
terra-luna
Terra Luna Classic (LUNC) 0,000154 1,62%
litecoin
Litecoin (LTC) 73,61 3,34%
chainlink
Chainlink (LINK) 7,04 5,09%
bitcoin-cash
Bitcoin Cash (BCH) 107,19 1,39%
algorand
Algorand (ALGO) 0,229882 1,29%
matic-network
Polygon (MATIC) 0,802888 1,30%
stellar
Stellar (XLM) 0,085321 0,73%
cosmos
Cosmos Hub (ATOM) 9,68 2,46%
filecoin
Filecoin (FIL) 4,19 1,78%
tron
TRON (TRX) 0,051654 0,03%
ethereum-classic
Ethereum Classic (ETC) 18,84 1,58%
dai
Dai (DAI) 0,965580 0,00%
tezos
Tezos (XTZ) 0,948268 0,77%
monero
Monero (XMR) 132,08 1,51%