In this article, we’ll show how you can begin generating NFTs in just 15 minutes. However, if you’d like to skip the tutorial and dive straight into the code, you can find it at the following GitHub repository:
Full Generating NFTs Documentation – https://github.com/ashbeech/moralis-mutants-nft-engine
The NFT industry grew tremendously during 2021, and the increased attention towards these tokens partly originated from the popularity of NFT collections such as Bored Ape Yacht Club and CryptoPunks. These are extensive collections of thousands and thousands of computer-generated tokens. What’s more, during the peak of their popularity, NFTs that are part of these collections sold for hundreds of thousands of dollars. The popularity and lucrative nature of these collections make them quite interesting, which is why we’ll dive deeper into the process of generating NFTs herein.
The easiest way to generate NFTs is through the utilization of the Moralis operating system. Along with a solid backend infrastructure, Moralis provides an excellent NFT API making all NFT development processes more accessible. Further, Moralis plays a significant role in how we can generate NFTs in only 15 minutes!
However, if you’re already familiar with the process of generating NFTs, or want to learn more about other areas of NFT development, check out additional content here at NFTCoders. For example, an excellent read is our article on how to build an NFT marketplace or how to create an NFT minting website!
Begin Generating NFTs in 15 Minutes with Moralis
In the following three main sections, we’ll take our time to dive deeper into the process of generating NFTs. As such, if you follow along, you’ll hopefully be able to create amazing NFT collections similar to Bored Ape Yacht Club or CryptoPunks!
As we mentioned in the introduction, we’ll use the Moralis operating system to make the development process quicker and more accessible. Thanks to this, we’ll be able to start generating thousands of NFTs in just minutes through the following three steps:
- Creating Layers of Art
- Generating Digital Art
- Minting NFTs
To make the process as accessible as possible, we’ll utilize an already prepared template we initially linked to in this article. As such, we can save valuable time and resources since we don’t need to create all elements from scratch. Nonetheless, without further ado, let’s dive right into the process of creating the art layers.
Step 1: Generating NFTs – Creating Layers of Art
NFT assemblies such as CryptoPunks are generally computer-generated collections of art layers that make up complete images or avatars. Depending on your vision, these layers might vary; however, popular examples are backgrounds, eyes, noses, clothing, etc. Nonetheless, it doesn’t matter what you want to include; the process of generating NFTs starts with creating these layers.
The first thing we recommend that you do is to visit the GitHub page and clone all the files to your local directory. However, in this initial step, we’ll direct our focus to the “Moralis Mutants.psd” file. This file has some already prepared components, and we need the template showing us how to structure the layers.
With the files on your computer, you can proceed by opening the files in your preferred software. We’ll be using Photoshop (PS), but if you prefer another alternative, that works fine as well.
The file contains a few layers such as accessories, arms, eyes, etc. Even if art layers already exist, we don’t need them unless we’re looking to generate “Moralis Mutants”. Nevertheless, we’re interested in the file’s structure. As such, it’s up to you to add or remove layers you don’t want to include. However, focus on keeping the same structure for the files since this will make it easier to follow the process as we go along.
You additionally need to keep the number of NFTs you want to generate in mind when designing the layers. For example, if you’re planning on generating ten NFTs, you won’t need as many layers as if you’re planning on minting 10,000.
Exporting the Art Layers
When you feel like you have the design down for all your layers, the next part of the first step is to export each layer into individual files. We need them separate as this will allow our NFT generating engine to combine layers in various ways to create unique art pieces.
Exporting each individual layer is relatively straightforward if you’re working with PS. In fact, all you need to do is hit “Files” at the top of the PS interface, click on “Exports”, and finally hit “Layers to Files”. Exporting the files will result in separate files for all individual layers.
The initial step’s last part is sorting all the files into folders. As such, we need to create folders for each layer category. For example, one for ”Accessories”, ”Torso”, ”Backgrounds”, etc. You can see below what it should look like:
The folders themselves additionally have to follow a particular structure. Within each folder for the layers, we need additional folders determining the rarity of the layers. As such, we should add three additional folders, “original”, ”rare”, and ”super_rare”. Then it’s up to you to sort all layers depending on how rare you want them to be in the final art pieces!
Step 2: Generating NFTs – Generating Digital Art
The second step consists of three parts: 1) creating a Moralis dapp, 2) making a few adjustments to the NFT engine, and 3) generating the NFTs themselves. Moreover, we need a Moralis dapp since it will supply us with the necessary tools to create the pieces of art and upload the files to IPFS. Thus, let’s kick things off by taking a closer look at how you can create your own Moralis dapp.
Creating a Moralis Server
To create a Moralis account, you’ll need to sign up with the platform. Once you have an account at your disposal, you can navigate to the admin panel and hit ”Create New Dapp”. This will prompt you to select the network(s), pick a region, and name your dapp. Once you are happy with your selections, all that remains is to click on ”Create Your Dapp” to get the Web3 app going.
Since this is a guide, we’re opting for Polygon’s Mumbai testnet. If you’d like to follow along, we recommend you do the same before committing to a mainnet. This is great to ensure everything works as it should before paying any gas fees.
With a server at hand, you have access to some essential information. So, if you click on the “Settings” button for the server in question, you’ll be able to see “Dapp Credentials”. Below this heading, you’ll find the dapp URL, application ID, and master key, which we’ll need later.
Adjusting the NFT Engine
If you haven’t already, the first thing you’ll need to do from here is to clone the files from GitHub to your local IDE (integrated development environment). Once you have access to all files locally, you can navigate to ”config.js”, which should be located in the ”input” folder. From there, you can scroll down to the ”Begin Collection Config” section, where we’ll make some adjustments.
You should inspect all these elements to ensure they fit your collection. However, the essential parts that are central for the engine are the ”baseImageUri”, ”editionSize”, and ”layer” constants. Let’s take a closer look at each of these, starting with the former.
The ”baseImageUri” should be set to your Moralis dapp URL that we found under ”Dapp Credentials” when we created the Moralis dapp in the last part. As such, you can simply copy the dapp URL and paste it into the code. Moreover, depending on the desired size of your collection, you might also want to change the ”editionSize” const.
Lastly, we’ll ensure that the ”layers” const has the proper structure. This is what it initially looks like:
const layers = [
addLayer("Background", { x: 0, y: 0 }, { width: width, height: height }),
addLayer("Base Torso"),
addLayer("Base Head"),
addLayer("Torso"),
addLayer("Arms"),
addLayer("Mouths"),
addLayer("Eyes"),
addLayer("Accessories"),
addLayer("Noses"),
];
The elements should correspond to the layers you created in the initial step. Moreover, the layer furthest ”back” should be at the top of the list. For example, let’s take a closer look at the initial structure where we see ”Background” at the top of the list. This means that all backgrounds will be the first layer to which we add additional layers on top. If ”Background” were at the bottom of the list, it would cover all other layers.
Engine Configurations
Once we’re satisfied with all the alterations to the ”config.js” file, we additionally need to change some parameters in the NFT engine. As such, let’s proceed by navigating to the ”index.js” file, where the central part of the code can be found.
We can scroll down to the ”// Moralis creds” section that looks like this:
// Moralis creds
const serverUrl = process.env.SERVER_URL;
const appId = process.env.APP_ID;
const masterKey = process.env.MASTER_KEY;
const apiUrl = process.env.API_URL;
// xAPIKey available here: https://deep-index.moralis.io/api-docs/#/storage/uploadFolder
const apiKey = process.env.API_KEY;
Here, we need to add the dapp URL, application ID, and master key, which can be found under the ”Dapp Credential” heading. Finally, you need to add an API URL and key, which you can find from the address in the code we presented above in this section.
Generating the Digital Art
Now that all the configurations are completed, we can continue generating the one-of-a-kind art pieces. This process is relatively easy, and all you basically need to do is input the following command into the terminal:
node index.js
Once you hit enter, the code will generate the specified number of unique art pieces. However, if you generate a large number of pieces, it might take some time to upload everything to IPFS. With all the individual art pieces, all that remains is generating the NFTs!
Step 3: Generating NFTs – Minting NFTs
Now that we have the art at our disposal, all that remains is to create the tokens themselves. However, before we start the minting process, we need to have a MetaMask wallet that is connected to the Polygon Mumbai testnet and have some testnet MATIC. As such, the first thing you’ll need to do is get a MetaMask wallet.
Once you have a MetaMask wallet, you must change the network to Mumbai. One alternative to do so is through “Chainlist.wtf” (DYOR [do your own research] is highly suggested before using platforms such as “Chainlist.wtf”). All you need to do is navigate to the webpage, search for Mumbai, connect your wallet, and click on “Add Chain”.
Now that the network is available, you can acquire testnet MATIC through a Polygon faucet. From there, all you need to do is input your wallet address to receive some ”fake” MATIC that can be used to pay for the transactions.
Creating a Smart Contract
To mint the tokens, we need smart contracts. For simplicity, we’ll use an already developed Solidity contract in the GitHub repository: ”NFTContract.sol”. What’s more, we’re going to use Remix to create this contract, as it’s easy to compile and deploy contracts through this software. So, you can essentially visit the GitHub page and copy-paste the contract into Remix. This is what it should look like:
contract NFTContract is ERC1155, Ownable {
using SafeMath for uint256;
constructor()
ERC1155(
"ipfs://INSERT_YOUR_CID_METAHASH/metadata/{id}.json" // You can get this saved in the dashboard of your Moralis server instance.
)
{
// account, token_id, number
_mint(msg.sender, 1, 1, "");
_mint(msg.sender, 2, 1, "");
_mint(msg.sender, 3, 1, "");
}
Before compiling and deploying the contract, we have to configure the code a bit. The first thing you’ll notice from the code is that you will need the ”CID” for your files. You can find the CID on your dapp’s dashboard. With the CID at your disposal, you need to replace ”INSERT_YOUR_CID_METAHASH” with the CID.
Moreover, the code was originally only fit for minting three NFTs. As such, if you’re planning on generating more NFTs, you need to create a loop that covers all your PNG and JSON files.
Compile and Deploy the Contract
The final step of the process is to compile and deploy the contract. So, let’s proceed and take a closer look at compiling the contract. As we opt to use Remix, this process becomes super easy. All you need to do is find ”Solidity Compiler” at the left of the Remix interface, select the correct version of Solidity, pick the contract, and hit ”Compile”.
Once the contract is compiled, you can proceed to deploy it to the blockchain. As such, you can click on the ”Deploy” tab below ”Solidity Compiler”. Following this, all that remains is to select ”Injected Web3”, choose the right contract, and hit the ”Deploy” button.
When the deployment process is finalized, Remix will supply the contract address, which you can use to watch the tokens on the testnet version of OpenSea!
Generating NFTs in 15 Minutes – Summary
In this brief tutorial, we could generate thousands of NFTs in less than 15 minutes. This was possible due to an already prepared template in combination with Moralis and the Web3 operating system’s APIs. As such, we could break down the process of generating NFTs into the following three steps:
- Creating Layers of Art
- Generating the Digital Art
- Minting the NFTs
If you have further interest in NFT development, you’ll find additional fresh and relevant content here at NFTCoders. For example, check out our article on lazy minting, allowing you to create NFTs without having to pay gas fees. Additionally, if you’re interested in game development, you’ll find our “NFT Game Development” fascinating!