Hardhat: Creating an NFT Contract using Hardhat and Setting NFT Metadata using IPFS on Filebase
Learn how to create an NFT contract using Hardhat and set the NFT metadata using IPFS on Filebase.
What is Hardhat?
What is Metadata?
1. First, we need an image to use as an NFT. We’ll start by uploading an image to Filebase for us to use.
2. Select ‘Buckets’ from the left side bar menu, or navigate to console.filebase.com/buckets.

3. Enter a bucket name and choose the IPFS storage network to create the bucket.

4. Next, select the bucket from your list of buckets, then select ‘Upload’ in the top right corner to upload an image file.

5. Select an image to be uploaded.

6. Click on your uploaded object to display the metadata for the object.

7. Open a command line interface and create a new directory for your project with the commands:
8. Initialize your npm configuration if you have not previously done so with the command:
9. Install npm dependencies for this project with the commands:
10. Next, initialize Hardhat with the command:
11. Create two new directories for contracts and scripts with the commands:
12. Open your preferred IDE and create a new file inside the contracts directory.
14. From the Alchemy dashboard, we need to create an app.

15. Create a new app.

16. Next, we need an Ethereum wallet.
17. Once you have a Metamask account, change the network to the ‘Ropsten Test Network’ in the top right corner.

18. Next we’ll need some test currency in our wallet to cover the gas fees for the contract creation.

19. Then, create a file called .env and add your Alchemy API URL and Metamask private key to this file.
.env and add your Alchemy API URL and Metamask private key to this file.20. Next, update the hardhat.config.js file with the following content:
hardhat.config.js file with the following content:21. Now let’s compile the contract with the command:
22. Now that the contract is compiled, we need to deploy it.
23. We can now deploy the contract with the following command:
24. Edit the existing deploy.js script so it reflects the following:
deploy.js script so it reflects the following:25. We also need to create a new script in our scripts directory called helpers.js.
helpers.js.26. We also need to edit our hardhat.config.js configuration file to reflect the newly defined tasks we created in the scripts above.
hardhat.config.js configuration file to reflect the newly defined tasks we created in the scripts above.27. Now let’s add a minting task. Create a new script in the scripts directory called mint.js and enter the following content to create your minting task:
mint.js and enter the following content to create your minting task:28. Now we need to edit our .env file to reflect our NFT contract address that we took note of when we deployed our contract.
.env file to reflect our NFT contract address that we took note of when we deployed our contract.29. Let’s edit our helpers.js script to include a helper function called getContract() to read the new environment variable we just added to our .env file.
helpers.js script to include a helper function called getContract() to read the new environment variable we just added to our .env file.30. Let’s mint our NFT now!
31. Lastly, let’s add some metadata to our NFTs.
32. Then, create a metadata file for our NFT.
33. Now we need to edit our mint.js script to include a function that sets this metadata.
mint.js script to include a function that sets this metadata.34. Finally, we’re ready to put it all together. Let’s start by compiling our project:
Last updated