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 23 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) 1,04 4,92%
aave
Aave (AAVE) 118,67 2,03%
the-graph
The Graph (GRT) 0,371656 3,53%
kusama
Kusama (KSM) 45,21 1,54%
waves
Waves (WAVES) 3,60 0,36%
dash
Dash (DASH) 37,22 4,53%
bitcoin
Bitcoin (BTC) 64.990,07 0,71%
ethereum
Ethereum (ETH) 3.287,82 0,80%
cardano
Cardano (ADA) 0,603887 0,16%
tether
Tether (USDT) 0,926193 0,04%
xrp
XRP (XRP) 0,582370 1,26%
solana
Solana (SOL) 171,99 0,26%
polkadot
Polkadot (DOT) 8,84 0,21%
usd-coin
USDC (USDC) 0,925996 0,10%
dogecoin
Dogecoin (DOGE) 0,198478 1,03%
uniswap
Uniswap (UNI) 12,04 4,99%
terra-luna
Terra Luna Classic (LUNC) 0,000145 1,30%
litecoin
Litecoin (LTC) 95,54 8,76%
chainlink
Chainlink (LINK) 17,54 3,08%
bitcoin-cash
Bitcoin Cash (BCH) 585,66 10,49%
algorand
Algorand (ALGO) 0,256286 2,14%
matic-network
Polygon (MATIC) 0,921423 1,71%
stellar
Stellar (XLM) 0,133782 4,83%
cosmos
Cosmos Hub (ATOM) 11,42 0,03%
filecoin
Filecoin (FIL) 8,84 4,45%
tron
TRON (TRX) 0,111180 0,20%
ethereum-classic
Ethereum Classic (ETC) 32,10 7,39%
dai
Dai (DAI) 0,926118 0,27%
tezos
Tezos (XTZ) 1,32 2,31%
monero
Monero (XMR) 125,22 1,36%