Introduction
In this tutorial I will show you guys how to create your very own NFT collection in Python.
Prerequisites
- Download Python.
- Open any IDE like VS Code, and then open ur terminal. Once you have your terminal opened you can clone the repository by typing
git clone https://github.com/sem/NFT-Image-Generator
. - Now you have the repository cloned, you will need to install the requirements by typing the following in your terminal:
Mac/Linux
pip3 install -r requirements.txt
Windows
pip install -r requirements.txt
What is Pinata?
Pinata cloud is a pinning service that allows users to host files on the IPFS network. We will have to use this so that we can have a path to our images to put it in the corresponding metadata.
What is metadata?
NFT metadata is the core of an NFT. It is a JSON document that often contains a path to the image along with a description and the name of the NFT etc.
Get an API key from Pinata
- Go to pinata.cloud and make an account.
- Click on your icon in the top right corner and navigate to API Keys.
- Click on the 'New Key' button, enable 'Admin' and give the key a name.
- Once you've made the key, copy the JWT (Secret access token).
Set up the config
Now comes the most important part, setting up the config. It will make sure that the images can be uploaded to the right Pinata account and that all names and descriptions will be set correctly for each individual NFT in your collection.
{
// Name of your collection
"project_name": "name of your project",
// Amount of images you want to create
"amount": 50,
// Description of the collection
"description": "description of your collection",
// JWT (Secret access token) from Pinata that you had copied
// earlier.
"api_key": "your secret access token",
// All folders containing seperate layers that will be used
// to make your final images. You can add as many folders as
// you want as long as they start with a sequential number
// that represents the order of the layers.
"folders": [
"1 background",
"2 body",
"3 eyes"
],
// Files to be ignored in the corresponding folders while
// making the NFT images.
"ignore": [
".DS_Store"
]
}
You should have a file structure that looks something like the following:
NFT-Image-Generator/
├─ main.py
├─ config.json
├─ requirements.txt
├─ 1 background/
│ ├─ red.png
│ ├─ green.png
│ ├─ blue.png
├─ 2 body/
│ ├─ female.png
│ ├─ male.png
│ ├─ zombie.png
├─ 3 eyes/
│ ├─ sun_glasses.png
│ ├─ normal_eyes.png
│ ├─ vr_glasses.png
Make sure each folder contains at least one image.
Creating the images
Now the config and folders are set up, we're finally able to create the images. Good job 👏. All you have to do now is open up your terminal and run the Python file.
Mac/Linux
python3 main.py
Windows
python main.py
If you have followed along step by step, then your images and the metadata should appear in a folder called 'output'. You can also log in to Pinata and your output should be right there at the files tab.
Conclusion
We have now created our own collection of unique images along with the metadata that's needed to deploy them as NFT's!
If you’ve reached this far, congratulations! There will be another tutorial soon to actually deploy your images and start earning money.
Top comments (0)