Step-by-step instruction: How to create an NFT collection using Golang and Ethereum (IPFS)
In the last article, we learned how to generate images for the NFT collection, and today I want to share with you how we can publish the generated images along with metadata in a decentralized storage.
After spending a lot of time researching existing NFT projects, I’ve met some developers publishing their images to centralized file storage's like AWS S3. In my humble opinion, the main message of NFT tokens is that no one can ever change the token itself and its contents. Therefore, we must take this into account when developing and be as far away from centralized systems as possible. That is why, we will publish all our files in a decentralized storage — IPFS.
So, to ensure that our content stays persisted (pinned), we need to run our own IPFS nodes. We can set up IPFS nodes ourselves, but it’s much more convenient to use a ready-made service like Pinata.
Uploading media files
Now let’s talk about how to work with the Pinata service for publishing NFT media files.
According to the documentation, we need to call the pinFileToIPFS endpoint to pin the files. Let’s write the code that actually does this:
Please note that in order to call pinata endpoints, you need to get an API key and Secret key.
If the file is successfully uploaded, we will get the IPFS hash of the file. Hash Example: QmPbxeGcXhYQQNgsC6a36dDyYUcHgMLnGKnF8pVFmGsvqi
Now that we have learned how to upload files to IPFS storage, we can try to upload NFT media files along with ERC-721 metadata:
As a result, the program will generate json files in the ERC-721 format:
In the next article, we will start creating a smart contract on Ethereum block-chain using Solidity.
In the previous article, we generated 10,000 NFT images from base layers.
P.S. All source code can be found on GitHub.