In this article I’ll show you how to deploy a NFT collection with 10 thousand NFTs. However, it assumes you have your own images and metadata.
Overview
For this tutorial we will be following the above diagram. In particular we will:
- Structure our metadata
- Upload the Images and Json to IPFS
- Insert the url into our NFT Smart Contract
- Deploy onto the Goerli Network
Structure your metadata
The first thing we need to do is make sure our metadata is structured to scale to 10 thousand NFTs.
First we will create two folders:
- images
- json
As the name implies we can put our 10 thousand NFT images inside the images folder and we can put their corresponding metadata in the json folder as all metadata should be in the json format.
We will be using the OpenSea metadata file format. You can find more information on it here.
Inside these folders we are going to label our images from 1 through to 10 thousand. And then we will have to do the same thing for the Json files.
It’s important to note that in this example I’m just using 10 images, but it’s the same process for 10 thousand images.
You can from the image below that my NFT images are just numbers from 1 to 10 and that the json files are just describing each image. What is special inside this json file is the {cid} reference in the image link. This is going to be the link to our images folder once we upload it to IPFS.
Upload to IPFS
Upload the images
Now that our metadata is structured properly lets upload images folder to IPFS. To do this we are going to use a service called Pinata so if you have never used it before go ahead and sign up, it’s free.
Once inside Pinata we can select our folder to upload and give it a name. After it’s done uploading we will see that it has generated a CID for us. This CID is a link to our images folder and will be need to use it in our json files.
Update the json files
Before we can upload our json files we just need to update the image url with the CID from our recently deployed images folder. To do this we need to replace the {cid} reference in all the json files with our actual CID.
Now we could do this manually for all our images. But if we have 10 thousand images this is going to take a really long time. So it’s better to write your own script to update the JSON files.
If you’re on a Mac you can use the following terminal command.
sed -i '.bak' 's/{cid}/QmdtiMYT54QG8KHxmua4Uy1fgFucLdJHEpYeXmJLb95EMe/g' *
Here you can see we are replacing the {cid} reference with the actual CID. This command also makes backups of your json files so be sure to remove those backups with the following command if the script was successful.
rm *.bak
Upload the json folder to IPFS.
Go over to Pinata and upload the json folder the same way we did it for the images folder. This will generate a new CID for the json files that we will give to our smart contract.
Insert the url into our NFT Smart Contract.
Below you will see that I have created this really basic ERC721 using OpenZeppelin. Feel free to copy the code into Remix. Then you can simply replace your CID in with the {cid} placeholder.
pragma solidity ^0.8.2;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
contract NFT is ERC721 {
uint256 private _tokenIds;
constructor() ERC721("NumbersNFT", "NFT") {}
function mint()
public
returns (uint256)
{
_tokenIds += 1;
_mint(msg.sender, _tokenIds);
return _tokenIds;
}
function tokenURI(uint256 _tokenId) override public pure returns(string memory) {
return string(
abi.encodePacked(
"https://ipfs.io/ipfs/{cid}/",
Strings.toString(_tokenId),
".json"
)
);
}
}
Deploy onto the Goerli Network
Now that everything is complete we can deploy our contract onto the Goerli network. If you uploaded 10,000 NFTs you will notice that you can keep minting up to 10,000 times and even view the results on OpenSea.
Conclusion
Well that’s it for this tutorial. If some of this terminology confuses you and you want to learn more about NFTs feel free to check out our course NFT101. In that 5 hour course we deep dive into everything you need to know to master NFTs.
Leave a Reply