This page may contain legacy content

To get our most up-to-date content please access our documentation

November 30, 2021

How to Mint NFTs Without Gas Fees

Table of Contents

Minting NFTs have, from a traditional perspective, required artists and creators to pay costly gas fees due to congested networks. It has, in turn, hindered NFT artists from entering the blockchain space as these fees make the process to mint NFTs unprofitable. However, since non-fungible tokens are one of the most prominent features of the crypto industry, developers have explored a way to mint NFTs without paying any gas fees. As such, the concept of lazy minting was introduced, which solved the issue. Therefore, let’s dig a little deeper into the topic of what NFTs are and then look at the process of how someone can mint NFTs without gas fees. Then, you’ll be well equipped with the proper tools to mint an NFT quickly, and at the same time, mint NFTs in a cost-efficient way.

As networks get congested, the gas prices spike, making it economically non-viable to interact with the various networks. In turn, it became expensive to mint NFTs, something that put economic strains on artists. However, by utilizing lazy minting, it is possible to push the fees forward until an NFT is sold. Moreover, lazy minting becomes a straightforward task when working with the number one Web3 operating system – Moralis. With the platform, it is possible to create a dApp (decentralized application) to mint NFTs without gas fees in just four steps! 

This is possible as Moralis provides excellent development tools such as Moralis Speedy Nodes, Moralis’ NFT API and Price API, and, more importantly, a fully managed backend infrastructure. This allows for a more accessible development process for not only NFTs but all future blockchain projects. 

For these reasons, if you are looking to get involved in the blockchain industry’s proliferation, the first step is to sign up with Moralis! 

What are NFTs? 

Before looking closer at how to mint NFTs without gas fees, let’s discover what NFTs are. NFT is an abbreviation for non-fungible tokens, and a clue to what they are can be found in the actual term. 

The word ”fungible” is a traditional economic term that refers to interchangeable assets. This means that it is viable to exchange one unit of a fungible asset for another as they are of the same type and value. In traditional economics, any currency is considered a fungible asset. Moreover, Bitcoins are fungible tokens, meaning that one Bitcoin is equal to another, making them interchangeable. 

As fungible assets are interchangeable, this suggests that non-fungible assets aren’t. Non-fungible assets are, therefore, not of the same type and value. This means that one NFT can’t directly be exchanged for another as they differ in characteristics. Moreover, more traditional non-fungible assets can be property. Houses are usually unique as they are designed differently and located in different places. This means that the value of one house isn’t always equal to the value of another. As such, they aren’t interchangeable with one another. 

Moreover, NFTs are tokens that aren’t interchangeable due to their uniqueness. The uniqueness makes NFTs ideal for representing ownership of unique assets. They can represent ownership of everything from digital to physical assets. However, when we talk about NFTs that are supposed to be “lazy minted”, it is important to know that the NFTs only represent ownership of assets. This means that the actual assets don’t exist on a blockchain currently until minted. The token simply points to the owner of a specific asset. This might be confusing, but it works similarly to that of a house deed. The deed itself doesn’t contain property, but it points to the owner. 

What is Lazy Minting?

One of the significant concerns with the blockchain industry has been congested networks. The main implication of this has been the increase and volatility of gas prices. For this reason, making transactions on, for example, Ethereum can be quite an expensive process. Furthermore, this also means that the process of minting tokens can be relatively expensive. Due to the high gas prices, restraints are put on digital artists, as it has become economically unviable to mint NFTs. 

The answer to this problem came in the form of lazy minting. Lazy minting allows for a delayed minting process. As such, it is now possible to push the actual minting to the point of purchase. This means that the point of creation is moved forward to a later part of the blockchain, and the minting burden is handed over to the buyer of an NFT. With lazy minting, artists and developers are free to create NFTs without the initial cost, as this only becomes relevant if someone actually purchases the NFTs.  

Moreover, this does not only benefit artists but the blockchain community as a collective as well. As the minting process is pushed to the purchase point, only purchased NFTs are minted. This reduces the number of transactions on the networks, removing some of the strains. 

How to Mint NFTs Without Gas Fees

Lazy minting NFTs can be quite a complex endeavor without the proper tools. Therefore, we will be utilizing Moralis throughout this tutorial since this makes the process more accessible. In this case, we’ll create our own lazy minting NFT dApp. This dApp will allow us to continuously mint NFTs without having to pay any gas fees. Since we’re going to use Moralis, this process becomes possible in four simple steps: 

  1. Create a Moralis server.
  2. Add the ”Rarible NFT Tools” plugin from Moralis.
  3. Create an HTML file.
  4. Add the dApp’s logic.

One of the many features of Moralis is the plugin store. Here we’ll find the ”Rarible NFT Tools” plugin, which is available to everyone with a Moralis account. This plugin enables us to lazy mint NFTs with a single line of code. This, in combination with the already managed backend infrastructure, makes the creation of this dApp a piece of cake. So, without any further ado, let’s get right into the process of how to mint NFTs without gas fees! 

Step 1: How to Mint NFTs Without Gas Fees – Create a Moralis Server

If you haven’t already, the first part of this tutorial is to create a Moralis account. This only takes a couple of seconds, and it is entirely free! Once logged in, you can create a new Moralis server by clicking on ”+ Create a new Server” at the top right of the interface. This will provide three alternatives; however, for this tutorial, it doesn’t really matter which one you opt for. 

Once either alternative is chosen, you’ll need to add a server name, select a region, and finally choose network(s). It is possible to select multiple networks as Moralis supports cross-chain compatibility. Your selection of network(s) should be based on where you would like to launch your dApp. With all the selections added, you can go ahead and spin up the server by clicking on the ”Add Instance” button. 

Finalizing the creation of the server might take a couple of minutes, but it will be up and running shortly, so there is nothing to worry about. Now, with a Moralis server at hand, we can move on to the second step in the process. 

Step 2: How to Mint NFTs Without Gas Fees – Add the ”Rarible NFT Tools” Plugin from Moralis

The second step in the process is to add the ”Rarible NFT Tools” plugin. To do so, you need to click on the downwards arrow button to the right of the server you just created. Then, click on the ”Plugins” button, and finally navigate yourself to the plugin store. 

There are various plugins; however, in this case, we want to click on the ”Read More” button for the ”Rarible NFT Tools” plugin. This will take you to the page for the plugin, where you’ll find additional information on how the plugin can be utilized. Nonetheless, to install the plugin, all you need to do is click the ”Install the Plugin” button at the top right of the page. 

Once clicked, you’ll need to choose the correct server and then configure Rarible. To configure Rarible, you’ll need to add Moralis Speedy Nodes for both the Ethereum mainnet and the Rinkeby testnet. Since you are a Moralis user, you’ll find these under the “Speedy Nodes” tab in the Moralis admin panel. 

With Moralis Speedy Nodes added, clicking on the ”Install” button at the bottom right is all that remains. Adding the plugin might take a short while; however, it will be fully functioning momentarily. 

Step 3: How to Mint NFTs Without Gas Fees – Create an HTML File

With a server up and running and the proper plugin installed, the next step is to structure the website’s contents using HTML code. To do so, the first thing we need to do is open the preferred IDE (integrated development environment) and create a new file called ”index.html”. 

Structuring the content of the dApp should be done according to your own preferences depending on how you want the UI (user interface) to look. However, to give you an idea of what a lazy minting dApp might look like, we took an example from the Moralis YouTube channel

As you can see, the application has a title, three input fields, and a submit button. As such, there is a necessity to add HTML code for these elements. The code for this is quite straightforward, and you can easily add your own spin to it. However, if you are interested in looking closer at the complete code from the HTML file, you can find it at the Moralis GitHub repository under ”index.html”. 

Since the code is quite self-explanatory and this is a tutorial regarding how to mint NFTs without gas fees, we won’t be going into the code in any more detail. Moreover, as the structure of the contents is up to the developer of the dApp, this will most likely vary depending on your own preferences. 

Step 4: How to Mint NFTs Without Gas Fees – Add the dApp’s Logic

The final part of this tutorial revolves around the logic needed to enable users to mint NFTs without paying any gas fees continuously. Moreover, the dApp contains three different functions; however, we will focus on the ”submit()” function since this takes care of the logic for lazy minting the NFTs. 

Before looking closer at the ”submit()” function, we are going to be initializing Moralis. To do so, we need to go back to the admin panel and go to the ”Servers” tab. Following this, we need to click on the ”View Details” button for the server in question and copy the server URL and application ID. With this information, we need to input the following at the top of the JavaScript file for the logic:

const serverUrl = “INSERT SERVER_URL”;
const appId = “INSERT APP_ID”;

The other two functions are ”login()” and ”initApp()”. The first one is a login function that is used to authenticate users via MetaMask. Since we are working with Moralis, this becomes possible with just a few lines of code. Moreover, once the dApp authenticates users, they immediately save to your server’s database. This gives you access to important information such as balances. 

The ”initApp()” function simply renders the application’s interface and adds an onclick event to the button from the HTML code. However, let’s move on to taking a closer look at the code for minting NFTs without gas fees. 

The “submit()” Function

The ”submit()” function holds most of the application’s logic, and it can be broken down into several different parts. To simplify the explanation, we will go through each of the main parts to give you a better idea of how lazy minting works. As such, this is what the first part of the function looks like: 

async function submit(){
    const input = document.querySelector('#input_image');
    let data = input.files[0]
    const imageFile = new Moralis.File(data.name, data)
    await imageFile.saveIPFS();
    let imageHash = imageFile.hash();

Here, the function simply fetches the data from the images that the users of the dApp upload and create a Moralis object. With the object at hand, the Moralis ”saveIPFS()” function is called, allowing us to save files to IPFS with one line of code. Once uploaded to IPFS, the image hash is fetched and saved as a variable. 

let metadata = {
        name: document.querySelector('#input_name').value,
        description: document.querySelector('#input_description').value,
        image: "/ipfs/" + imageHash
    }
    console.log(metadata);
    const jsonFile = new Moralis.File("metadata.json", {base64 : btoa(JSON.stringify(metadata))});
    await jsonFile.saveIPFS();

In the code above, you can see the second part of the function where we construct a new metadata object using the name and description that the user inputs along with the image hash. The function then stringifies the object to JSON format and once again uploads it to IPFS.

let metadataHash = jsonFile.hash();
    console.log(jsonFile.ipfs())
    let res = await Moralis.Plugins.rarible.lazyMint({
        chain: 'rinkeby',
        userAddress: user.get('ethAddress'),
        tokenType: 'ERC721',
        tokenUri: 'ipfs://' + metadataHash,
        royaltiesAmount: 5, // 0.05% royalty. Optional
    })

With the metadata object uploaded to IPFS, the function continues by calling the ”Moralis.Plugins.rarible.lazyMint()” function. This single line of code allows us to lazy mint NFTs to avoid initial gas prices. When called, we include the network, user address, token type, token URI, and a royalties amount.

console.log(res);
    document.querySelector('#success_message').innerHTML = 
        `NFT minted. <a href="https://rinkeby.rarible.com/token/${res.data.result.tokenAddress}:${res.data.result.tokenId}">View NFT`;
    document.querySelector('#success_message').style.display = "block";
    setTimeout(() => {
        document.querySelector('#success_message').style.display = "none";
    }, 5000)
}

Finally, if the function works as intended, a success message is displayed with a link where the users can find the NFT that they just created. 

That’s it for this short tutorial! However, if you want to check out the complete code, you can find it on the Moralis GitHub page. Moreover, if you prefer watching a video clip explaining the process, then we recommend taking a closer look at the following video from Moralis’ YouTube channel: 

https://www.youtube.com/watch?v=n6rPr0sStTI

Mint NFTs Without Gas Fees – Summary

NFTs are powerful and prominent features of the blockchain industry. Unfortunately, it has become rather expensive to mint tokens as the price of gas is high and volatile. This has been damaging for artists as they have been forced to pay the price. However, this issue has now been solved through the concept of lazy minting. 

Lazy minting removes the economic strain on artists and developers, as the actual minting process of an NFT moves to the time of purchase. Moreover, since only sold NFTs are minted, some of the strain on the blockchain networks is eliminated.

Lazy minting NFTs can, however, be a relatively complex endeavor. Fortunately, there are solutions to solve these issues, and one of them is Moralis. Moralis is the number one operating system for Web3 development, and with the platform, it becomes possible to lazy mint NFTs with a single line of code. 

However, this is far from the limits of Moralis, and feel free to tune in to the Moralis blog for additional content. Here you’ll find guides on, for example, how to build Ethereum dApps, how to create a BSC token, how to develop your own NFT marketplace, and much more. 

In addition, if you would like to level up your development skills, then make sure to check out Moralis Academy. At Moralis Academy, we teach blockchain development from scratch. So, if interested, check out our 2021 JavaScript Programming for Blockchain Developers course. There, you’ll learn everything that’s necessary to start your programming journey. After finishing, you’ll be able to continue with other courses at Moralis Academy!

NFT API
Unlock the full potential of your NFT projects with this industry-leading NFT API! Fast, easy, and free.
NFT API
Related Articles
December 18, 2022

Exploring Ethereum Python Implementation for Dapp Development

October 30, 2023

Blockchain API Providers – Comparing Top Blockchain API Services

August 16, 2022

NodeJS SDK for Web3 – Exploring Moralis’ NodeJS SDK

March 9, 2023

xNFT – What is an xNFT (Executable NFT)?

October 25, 2022

What is Sui Blockchain? – The Ultimate Guide

September 6, 2022

How to Build a Polygon Dapp in 3 Steps

January 31, 2024

Building Cryptocurrency Price Trackers: Guide and Project Inspirations

February 22, 2023

Data Availability in Blockchains – Exploring the Data Availability Layer

August 31, 2022

Fastest Way to Build a Web3 App