Better Programming

Advice for programmers.

Follow publication

Create NFTs Using Solidity With Open Zeppelin and Publish It on IPFS

View it on OpenSea

Namya Aankur Gupta
Better Programming
Published in
5 min readJun 16, 2022

Photo by Shubham Dhage on Unsplash

NFTs and digital collectibles are growing popular as the web3 space continues to make significant advancements in the blockchain arena. The enormous popularity of NFTs like Cryptokitties and Bored APE pushed investors to purchase ERC721-compatible digital collectibles.

In this article, we will guide you through the procedure of creating your first ERC-721 (NFT) contract on Solidity with Open Zeppelin.

Developing a Smart Contract with Solidity and deploying it on the blockchain might sound daunting at first: solidity, security, gas optimisation, developer environment, and gas fees, are only some of the things you’ll need to go through to host your code on the blockchain.

Tools like the OpenZeppelin Wizard that offers developers click and write functionalities to create composable and secure smart contracts in no time, used with Web3 developer tools like Alchemy, make the experience of writing a deploying code on the blockchain easy, fast, and reliable like never before.

In this tutorial, you’re going to learn how to develop and deploy an ERC721 (NFT) smart contract.

Tech Stack

  • Alchemy
  • OpenZeppelin
  • Remix
  • Ethereum Goerli

1. Open Zeppelin

First of all, let’s go to OpenZeppelin, then on the Wizard tab, click on ERC721. All NFTs are ERC721 tokens.

Open Zeppelin ERC-721, Source: self

We want our tokens to be Mintable, have Enumerable and URI Storage as the features. Name your token as per your wish and also enter the desired symbol.

Code for Mintable, Enumerable, URIStorage Source: self

2. Remix IDE

Now, click on the Open in Remix button in the upper right-hand side corner. It will open the Remix IDE and will have the code written. You can change the compiler version to 0.8.4.

Here, is the updated code, be sure to change it in Remix. We need to remove the Ownable part of the solidity program as we want that people other than ownable can also mint our NFTs. Also, we have added MAX_SUPPLY as 5000 so that the NFTs are limited.

3. Alchemy- Create app

Next, we need to sign up for Alchemy. Click on Create App and name your app whatever you wish. I named it Namzz nft. Then click on View Key and copy the HTTPS address.

Alchemy after creating the app, Source: self

4. Metamask- Add Network

Further, we need to create our network on Metamask by clicking on Add Network. Name the testnet as per your wish. I named it Namzz Goerli testnet. Paste the https URL that we copied from alchemy. Add ID as 5 for Goerli and enter ETH as the symbol. Click on Add Network button.

Network Created, Source: self

You can get some test Ethereum from the Goerli faucet. Here is the link. Login with your Alchemy account and enter your address. You will get the test ether within seconds!

5. Compile and Deploy the NFT Smart Contract on the Goerli Testnet

On Remix, go to Deploy and select Injected Web3 as the Environment. It will get connected to you network automatically. You will get the address of your metamask along with the balance ether. Select your smart contract in the Contract Tab and click on Deploy.

It will show a metamask popup asking you to pay the fees. Click on Confirm and wait for 10 seconds. It will add the deployed contract in the Remix!

Deployed Contract in Metamask, Source: self

6. Formatting the NFT Metadata

For OpenSea to pull in off-chain metadata for ERC721 tokens, the contract will need to return a URI pointing to the hosted metadata. To find this URI, OpenSea, Rarible and other popular marketplaces will use the tokenURI method contained in the ERC721Uristorage standard.

Head over to OpenSea developer doc and copy the metadata structure. Paste it in json online editor and edit the description according to your wish. According to the OpenSea documentation, the NFT Metadata should be stored in a .json file and structured as follows:

NFT Meta Data

7. Creating and Uploading the Metadata on IPFS

Now that we have a brief understanding of what will be contained in your NFT metadata, let’s learn how to create it and store it on IPFS- Inter Planetary File System.

Go to Filebase, and make an account there. Verify your email and login. Now, we need to click on create bucket, the bucket name being in small case letters, I named it namzz-nft. Select IPFS and create. Now upload the image you want to make as the nft. Click on the image and copy the IPFS Gateway URL. Enter this link in the image section of JSON file.

Save the JSON file in the name of metadata.json and upload it on Bucket in FileBase.

Save the JSON file as metadata.json, Source: self

Click on your file and copy the IPFS CID.

8. Mint Your Goerli Testnet NFT

Then head on over to Remix. Orange methods are methods that actually write on the blockchain whereas Blue methods are methods learning from the blockchain.

Click on the safeMint method dropdown icon and paste your address and the following string into the uri field:

ipfs://<your_metadata_cid>

Clicking on transact will create a Metamask popup prompting you to pay the gas fees. Click on “sign” and go on minting your first NFT!

Transact via Metamask

Enter your address in the balanceOf button and enter your address. Run it — it should show you have 1 NFT.

1 NFT available

Do the same with the tokenUri method, inserting “0” as the id argument — it should display your tokenURI.

Great! You just minted your first NFT! 🎉 Now it’s time to move to OpenSea to check if the metadata is read.

9. View the NFT on OpenSea

Navigate to testnets.opensea.io and log in with your Metamask wallet. Then click on your profile picture, you should see your newly minted NFT there. If the image is not yet visible, click on it, and click on the “refresh metadata” button.

Sometimes OpenSea has hard times recognizing testnet metadata — and could take up to 6 hours to see it.

Congratulations, you have successfully created, modified, and deployed your first smart contract. Minted your first NFT, and published your image on IPFS!

Thanks for reading.

Sign up to discover human stories that deepen your understanding of the world.

Responses (4)

Write a response

Hello, great blog we from iMintify have worked on a No-Code Smart Contract creator what makes it possible to deploy a NFT Smart Contract for Free in just 2 minutes! With a user friendly interface. We also support Free IPFS bulk upload by just drag…

Are these the same steps to officially mint and list an nft on opensea?

Thanks very useful!