How to create your own NFT Generative Art Collections with Python

Recently, I had to take an interest in the metaverse, which obviously seems to be the future of the web aka Web3! Without overplaying the early adopter, it would be a shame to miss such this phenomenon. Incidentally, it was also an opportunity to discover NFTs and blockchain and even more concretely on how to create my own NFT’s collection.

One more thing, that would be lying not to say that I was impressed like anyone by the price records broken by some NFTs. For those who still doubting, it testifies that the NFT market could be prone to speculation! For the moment, it seems the next big thing and there is no obvious reason to justify such prices except that is has become the “zeitgeist” where people are excited about NFTs and the price goes up! Market laws at its purest!

But let’s get back to our subject to create what is commonly called Generative Art Collections. It is a new way to create a collection of NFTs with scripts. This process is at the origin of the most popular collections such as CryptoPunks, Bored Ape Yacht Club…

I looked for some resources in Python to generate my own collection. Here is a fraction of this search. For those who don’t know what an NFT and some other concepts regarding the NFT ecosystem below you can get quick definition and links to showcase some of today’s most famous collections.

You can grab the source for each NFT generator and some other resource on my GitHub account

Source: https://github.com/bflaven/BlogArticlesExamples/tree/master/nft_insights

Some of the major collections both in notoriety and in financial value…

What is an NFT?

An NFT is a tokenized digital asset that can be verified on the blockchain and is non-fungible, meaning it is unique and cannot be easily exchanged for a similar asset.
NFTs live on the blockchain, a decentralized global computer network that maintains a public record, they cannot be tampered, destroyed, hacked or counterfeited.

Most online offers or tools relating to the NFT creation and exposure can be summarized around the following triptych: CREATE – TOKENIZE – SALE.

In this post, I am mainly focus on the first part (CREATE). Indeed, the purpose of the NFT is to be exposed and then sold for the lucky ones, therefore, creating these NFTs is a prerequisite.

As indicated in the introduction, I especially tackled the Generative art collections issue which is particularly based on randomness.

I must admit that there are many other NFT’s types but I will leave them aside just like the key success factors in the launching strategy for NFTS collection such as concept, segment, artistic style, community, rarity through traits or interoperability!

An essential piece of the NFT collection: the traits

The essential concept in the creation of a collection is that of traits which will be the digital basis on which you will generate your NFTs. You can work with Photoshop or another image-editing software and create one layer per trait for your NFT.

Let’s take the example given in the project named “Pycasso” where you will generate faces that look to like the ones painted by Pablo Picasso.
I have define 6 Parent Traits and for each parent, it variates between 6 to 4 Sub-Traits. The layers you’ll need to build in Photoshop might look something like this:

--- background: Blue, Orange, Red, Green, Pink, Dust
--- eye: Scary, Sleepy, Friendly, Clumsy, Phoenician, Egyptian
--- eyebrow: Precious, Bold, Julia, Piaf, Fillon
--- face: Nothing, Egyptian, Cocteau, Tillet, Merrick, Ball
--- mouth: Fish, Flower, Wisper, Silent, Trump
--- nose : Greek, Potato, Socrates, Tubular

Then, you can play with “rarity” so one subtrait can appear less frequently in the collection, making the NFTs that possess them rarer and potentially more valuable.

Also think about the way you want that traits appear in the NFT e.g the eyebrow closed to the eye… well in the case of Picasso, you can decide to put the eyebrow far far far away from the eye as it seems the Pablo’s Pattern!

Just export automatically each layer as png transparent and then you are good, you have your basis to generate your NFT collection.

You can find more info on rarity by playing with some NFT generators gathered on my GitHub account used to illustrated this post.

Rarity is important since it creates scarcity which in turn creates value. You will implement rarity in the traits by assigning weights to the different types within one trait. The total of the weights should always add up to 100.

Remember that most NFT collections posted on NFT tools, such as Rarity, are ranked by their rarity, and that contributes to their value. Like I said before, some of the most popular NFT marketplaces are: Mintable, Rarible, OpenSea.

What is NFT Metadata?

NFT metadata is the core of an NFT. It is a JSON document that often contains the following: NFT’s name, Description of the NFT, Link to the hosted image, Traits…

This NFT metadata will be the input of your NFT smart contract which you will deploy on the Ethereum network in the third part.

Hosting for Interplanetary File System (IPFS)

Regarding the NFT collection hosting, a few words because if your intention is to go further, you will necessarily have to be interested in it to ensure the sustainability of your future collection. You will rely on Interplanetary File System (IPFS).

Instead of locating a specific file at a specific domain, as with a URL address, IPFS addresses allow you to identify any piece of content as long as someone on the IPFS network is hosting it. This creates a decentralized method of data storage that can be used to host or backup your NFT collection.

You can explore and choose Pinata for instance : https://www.pinata.cloud/

This service will help you to secure your NFT data and make sure the generative NFT collection you create lasts forever (or at least a really long time) ! Uploading images to the blockchain is very expensive since they are large in size. The best practice is to only upload the link of your image to the blockchain and store your image on an Interplanetary File System (more on that later).

Interplanetary File System = IFS

Pinata allows you to upload NFT images for free using IPFS (InterPlanetary File System). This is a distributed file-sharing system.

Other considerations

I don’t deepen too much the other specifications like Smart Contract, MetaMask, Minting and also where to sell your NFT collection. It exist a numerous resources on each topic. Just here are few insights about some key concepts regarding NFT.

1. Marketplaces

These marketplaces can generally be divided into two types: curated marketplaces and open marketplaces. We may bump into sites like:

Curated marketplaces: Curated platforms only allow approved creators to mint NFTs.

Open marketplaces

2. smart contract

A smart contract is a program that runs on the Ethereum blockchain. Its code and data reside at a specific address on the Ethereum blockchain. NFTs are powered by smart contracts which handle the transferability and verify the ownership.You will use the ERC-721 standard. This is an NFT standard that provides functionalities for smart contracts.

3. Minting

Minting or NFT minting is the process that transforms a digital file into a blockchain digital asset. It is impossible to modify, delete, or edit a digital asset registered on the blockchain.

Fortunately, there are NFT marketplaces such as OpenSea that have adopted a “lazy-minting” strategy. Lazy minting means that you only pay “gas fees” when a buyer purchases your NFT, meaning there is no up-front cost for creators. But, anyway, you can expect to pay something when you mint an NFT.

The question is: “How can you evaluate this “something”?”

When you “mint” an NFT, you are changing the digital files you created into digital assets on the blockchain. How much you pay to mint your NFT collection will depend on where you choose to mint it and how much the transactions fees are associated with chosen marketplace and/or blockchain.

If you decide to mint your NFT on the Ethereum network, a “gas fee” is charged to pay for the energy needed to complete the transaction.

The price of “gas” can vary widely depending on the amount of traffic on the Ethereum network at the time you choose to mint your NFT. Fortunately, you can use Gas Now to track the gas prices and choose to mint your NFT at a time when the fees are low.

Because gas fees have been rising with the increased traffic on the Ethereum network, some people wonder if they can mint a non-fungible token for free.

Handling NFT Python environment with anaconda

Like always with python I am handing the environment with Anaconda.

# update conda
conda update -n base -c defaults conda
 
 
# create an environment with conda
# Conda Environment
conda create --name nft_insights python=3.9.7
conda info --envs
source activate nft_insights
conda deactivate
# if needed to remove
conda env remove -n [NAME_OF_THE_CONDA_ENVIRONMENT]
 
 
# command to install requirement
pip install -r requirements.txt
 
 
# module required
pip install numpy
pip install pillow
pip install streamlit
pip install watchdog
pip install python-dotenv

Conclusion: That is fun to create your own NFTs generative collection even if the added value in aesthetics’ terms sucks but it will not prevent your collection from being the next hit on the emerging but already huge NFT market, who knows! Hurry up anyway because speculation will probably come to an end and some severe market corrections can occur at any time. Last but not least, apart from the interest, this new artistic expression seems to have a tremendous environmental impact because of all these minting operations like the rest of the internet activity by the way. So, all this can stop definitely with the environmental collapse that is the Damocles ‘sword for our physical and virtual worlds.

Videos to tackle this post

Using a simple NFT generator, made with Streamlit

Using a simple NFT generator, made with Streamlit

Using NFT generators with Frida Kahlo, Lionel Messi and Rosie the riveter or Pablo Picasso

The big picture

These attempts to create an NFT Generative Art Collections with Python is part like these 4 videos below to a workshop for the training for “Management de l’Innovation Technologique” at https://exed.polytechnique.edu/ for a project named MetaMuse. The baseline of the MetaMuse project was to offer to create virtual exhibition spaces or galleries, free and paid, of NFTs in the Metaverse.

These videos were made with Sketchup and integrated some NFT created during the Workshop especially one extracted from 007_pycasso_nft_generator

MetaMuse Project : The MetaMuse Teaser Experience

MetaMuse Project : The MetaMuse UX Guggenheim Modern Gallery experience

MetaMuse Project : The MetaMuse Hermitage Museum No Wall Art Gallery experience

MetaMuse Project : The MetaMuse Ziggurat Building Hermitage Museum No Wall Art Gallery experience

More infos