Generate random NFTs with Node.js + Sourcecode

10 min readJan 16, 2022

Randomly mix layers and create unique NFTs with both image and metadata using Node.js and JIMP.

In this tutorial we will be generating random NFTs with its own metadata using different traits, using the OpenSea standards (This tutorial can be adapted also to Solana and other chains, keep in mind that you will need to build the metadata following the standards of the chain you’re using), this means that following this guide you will end up with a pack of NFTs ready to upload to the Ethereum or Polygon chain.

Creating NFTs from scratch is not a standalone task, we would need an artist to draw the traits by layers. So we will need all the sets of eyes, mouths, noses, and every trait we want to include in our NFTs.

Important note: Every layer/image should have the same dimensions; our script will focus on overlaying layers with transparent backgrounds, which is far easier than positioning them one by one. All traits PNG files will have the same dimensions as the background trait.

See below an example of an NFT that what we will be building, with the right order of layers, examples of wrong layers, and a quick of 27 NFTs. For the sake of this tutorial I’ve drawn a few layers of a little guy with the iPad Pro and the Procreate app (I’m a developer, not a designer, but at least we can get a real world-like project):

As displayed above, we will be having the following traits, in this precise order, which you can download right here from Github. Each trait is exported singularly :

1- Background
2- Body
3- Outfit
4- Head
5- Nose
6- Mouth
7- Eyes
8- Sunglasses
9- Headwear

Coding the script with Node.js

Now that we have the traits to use in our NFT generator, we can proceed to code it. This tutorial takes in mind that you already have Node.js and NPM installed, and you know the basics of creating an NPM project. You can follow along the source code on this Github repository where there’s the final code of this tutorial and the traits used to generate a good amount of NFTs.


Software Engineer, Entrepreneur and Writer — Italy 🇮🇹