This page may contain legacy content

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

January 17, 2022

Gasless Transactions – Exploring Gasless Transactions on Ethereum

Table of Contents

If you’ve been executing transactions on the Ethereum blockchain, you must have dealt with its gas fees. These exorbitant gas fees on Ethereum frustrate many and prevent users from utilizing its network. Therefore, many can’t help to wonder if gasless transactions would perhaps be possible. The good news is that they are. However, they are probably not exactly what you might think they are. Fortunately, in this article, we’ll set things straight by exploring gasless transactions on Ethereum and provide you with a clear understanding of gasless transactions. Also, we’ll show you how to include them in your dApps (decentralized applications). Plus, by taking on an example project, you’ll get a chance to learn to work with several practical tools. These Ethereum gasless transaction tools are Moralis (a.k.a. Firebase for crypto), the ultimate Web3 boilerplate, and Biconomy. 

While Ethereum initially introduced gas fees, it is something that all EVM-compatible chains incorporate. This means that chains such as Polygon, Avalanche, and Binance Smart Chain (BSC) also include transaction fees. However, their transaction fees are much lower since they utilize the proof-of-stake (PoS) concept rather than proof-of-work (PoW), which Ethereum uses. Therefore, we believe these chains are a better alternative when discussing gasless transactions. As a matter of fact, for our example project herein, we will focus on the Avalanche testnet called Fuji. Nonetheless, the principles behind setting up gasless transactions for other EVM-compatible chains are the same. Thus, you can easily apply the knowledge acquired in this article to your Ethereum-based projects. Fortunately, the ultimate Web3 development platform, Moralis, offers cross-chain interoperability. In turn, you can deploy your dApps across multiple chains without breaking a sweat or the bank. So, before proceeding, create your free Moralis account

What is Ethereum Gas?

To ensure that you are all caught up to speed with the basics, let’s start by answering the question, “what is Ethereum gas?”. The word “gas” was purposely chosen for a good reason. Why? Well, just like gas in vehicles, gas on Ethereum also fuels something. However, instead of powering mechanical engines, it powers Ethereum Virtual Machine (EVM) smart contracts or transactions. 

As you most likely know, Ethereum was the first programmable blockchain and remains the leading one. It enables developers to deploy dApps and other tokens on top of it. The same is true for other programmable blockchains. Moreover, in order for users and developers to power all transactions, they need gas. Since gas is the unit that measures the amount of computational effort required for the execution of specific operations on Ethereum, it is paid in ETH. 

Of course, other programmable chains use their native tokens (coins) for that purpose. Moreover, since each transaction on Ethereum requires computational resources (Ethereum is still using the PoW concept), the related transaction fees can be incredibly high when the network is in high demand. These transaction fees are known as Ethereum gas fees. Furthermore, despite high prices, transaction fees are fractions of ETH. As such, they’re referred to as “gwei” (a.k.a. “nano eth”). 

Gasless Transactions Explained

We also want you to avoid thinking incorrectly of gasless transactions. For one, you need to know that in order for a transaction to be executed, gas fees must be paid. There is no way around this. So then, what do gasless transactions mean? Well, “gasless” means that users do not pay for the transaction fees themselves. By using the tools you will learn more about as we move forward, you can create such a feature for your dApps. Of course, you have to be aware of the fact that someone needs to cover the gas fees. This is done in some cases by dev teams or project owners. Moreover, it is important to make a rather clear assessment of the expected number of transactions in these kinds of dApps. That way, you can ensure that your budget allows you to offer gasless transactions to your users.  

Why Gasless Transactions

Not sure why you would want to offer gasless transactions in your dApp? Well, put yourself in your users’ shoes. If there were two dApps that both offered the same functionality and both had a nice UI, wouldn’t you rather use the one that offered gasless transactions? Thus, offering this user-friendly feature may just be the extra touch that will attract more users. 

Gasless Transactions on EVM Chains – Example Project

By taking on an example project, you will learn how to incorporate gasless transactions on EVM-compatible chains. Moreover, as mentioned above, we will be working on the Avalanche Fuji testnet. However, before we start building our example dApp, a preview of what we’ll be creating is in order. This should provide you with a clear understanding of our end goal for this quest. 

Moving forward, we will also guide you through the initial setup. As such, you will need to create your Moralis server and Biconomy account. For more details regarding the actual coding, we will hand you over to one of Moralis’ experts. Using a video tutorial, he will walk you through the code and offer in-depth guidance. What’s more, we’ll show you just how to do gasless transactions!

Our Example dApp Preview

We believe that keeping things as simple as possible is essential when tackling new aspects of blockchain. As such, our example dApp will reflect that belief while still serving its purpose. So, it will enable users to execute gasless transactions on the Avalanche testnet. Of course, the same principles can be applied to any of the Ethereum testnets, Ethereum’s mainnet, or any other EVM-compatible networks. 

Our example Web3 app enables users to store a string by clicking on the “Edit Storage” button (see the image below). Of course, being on a blockchain and to store that string, a transaction must be executed. Moreover, these are the gasless transactions we will cover on behalf of our users. As such, they will be able to edit the string without paying gas fees.

The screenshot above shows you that our example dApp can switch among different blockchains (testnets in our case). Currently selected is the Avalanche Fuji testnet. Moreover, our UI also displays the native token balance for connected users. Finally, it also gives connected users a chance to edit storage via the “Edit Storage” button.

Gasless Transactions in Action

Furthermore, we also completed a transaction with a wallet containing zero AVAX tokens (native tokens on Avalanche). This should demonstrate that our example dApp truly offers zero transaction fees for its users. We did this by using MetaMask to sign in (authenticate). Next, we clicked on the “Edit Storage” button, which enabled us to enter new storage data (a string in our case):

We typed “Hello Moralis” as the new storage data. Next, we selected the EIP-712 signature option (more on this later on) and clicked on the “Set Storage” button. The latter prompted MetaMask for confirmation: 

By clicking on the “Sign” button, we completed the transaction without paying the gas fee. By using Biconomy (see the top-right corner of the above screenshot), we covered the transaction fee in the backend. Also, we got the updated storage state:

How to Offer Gasless Transactions on EVM-Compatible Chains – The Initial Setup

The initial setup contains several steps you need to complete. Fortunately, none of them are complicated. However, to make things easy, we’ll provide step-by-step instructions to make sure that you set things up properly. You will start with the basics, where you’ll need to create your free Moralis account. By doing so, you will have a chance to create your Moralis server. Plus, it will provide you with full access to Moralis’ SDK, including Moralis Speedy Nodes

In addition, you will also learn about the ultimate shortcut to dApp development – the ultimate Web3 boilerplate. The latter enables you to create a dApp with a simple UI in minutes. The boilerplate comes with most of the components an average dApp needs. Moving forward, you have a chance to tweak the Ethereum boilerplate yourself. As such, start by cloning its GitHub address. However, we offer you an additional shortcut – you can use the finished code for this example project. For detailed instructions, watch the video at the end of the article (starting at 6:07). 

Since Biconomy is also an essential part of implementing gasless transactions, you’ll also need to set up an account there. Fortunately, this is not complicated at all. In addition, you’ll need a code editor (we use Visual Studio Code [VSC]) as well to work with the above-provided code. By installing all dependencies for a package manager (yarn or npm) and for Truffle, you’ll be all set. 

Initial Moralis Setup

To make the use of Moralis in your dApp development, including your “gasless transactions” quest, complete these steps:

  1. Create Your Moralis Account – If you haven’t created your Moralis account yet, do this now. You may use this link to sign up with Moralis, which will take you to the sign-up page. Once there, enter your email address and create your password. Finally, confirm your email address by clicking on the confirmation link (check your email inbox). However, in case you already have an active Moralis account, just log in
  1. Create a Moralis Server – Once inside your Moralis admin area (the “Server” tab), you will get to create a new server by clicking on “+ Create a new Server” (the top-right corner). Next, select the kind of network type that best suits your needs from the drop-down menu (as shown below). When working on example projects, you want to go with the “Testnet Server” option.

Once selecting the server type, you’ll see a pop-up window asking you for the details of your new server, including your server’s name (it can be anything you want), region, network, and chain(s). Once you’ve entered all details, click on “Add Instance”:

Note: Make sure you have Avalanche testnet selected.

  1. Access Server Details – After spinning up your server, you’ll be able to obtain its details. Just click on the “View Details” button next to your server name. You’ll need to copy your server’s URL and application ID and paste them into your code file (“.env”).
  1. Initialize Moralis – By populating your “.env” file with the Moralis server details, you get to use Moralis’ SDK to the fullest:

Moralis Speedy Nodes

The video below will guide you through the process of using Moralis Speedy Nodes to deploy smart contracts. This functionality is available to you once you’ve created your Moralis account. To access it, select the “Speedy Nodes” tab at the bottom of the navigation tab on the left-hand side. Next, you’ll need to click on “Endpoints” for the Avalanche chain:

By clicking on “Endpoints” for the Avalanche network, a pop-up window will appear:

For some networks, you will have a chance to use the “Add to MetaMask” button. However, this may not always function due to MetaMask issues. As such, you may need to add a specific network to your MetaMask manually. Moreover, there is a part of these URLs that you’ll need in some code files of our example project (the highlighted part of the address):

Biconomy Setup

At this point, you already know that Biconomy is a trusted forwarder. Thus, it enables us to offer our users a gasless transactions option on many EVM-compatible chains. As with most platforms, you need to create your account to use Biconomy. Thus, go to “biconomy.io” and click on “Dashboard”:

Then, enter your details and click on the sign-up button to create your account:

After successfully signing in, you’ll get to access your Biconomy dashboard. Inside of it, you’ll be able to set up “forwards”. It is “forward” that enables you to pay transaction fees on behalf of your users and offer them gasless transactions. With that said, it is important to ensure that you have enough native tokens to cover all of your users’ transaction fees. In our case, this means ensuring that you have a sufficient amount of play AVAX tokens.  

Note: The video below (starting at 26:45) will guide you through the details of setting up your “forwarding” properly. As such, you will also obtain the data, which you’ll add to your code. Moreover, it is essential to complete the “forwarding” setup as it is vital for offering gasless transactions.

How to Offer Gasless Transactions on EVM-Compatible Chains – Code Walkthrough

Now that you have everything set up properly, it is time to take a closer look at the code required to incorporate gasless transactions in your dApps. As mentioned, one of Moralis’ experts created a video tutorial for that purpose. Starting at 12:14 (video below), he will explain the details of the smart contracts used in this example project. Moreover, if you haven’t cloned the code we made available at GitHub (linked previously) yet, watch the video at 6:07 and complete that part first.

Also, the Moralis expert will show you how to deploy smart contracts using proper logic files (21:35). Further, at 23:48, you’ll learn how to use “ShowTrace”, which is equivalent to Etherscan or BscScan but for Avalanche. Moreover, if you need additional guidance with the Biconomy setup, check out the details starting at 26:34. Then, you will be guided through the rest of the code. This includes “BiconomyProvider.js”, “index.js”, “App.js”, “index.jsx”, and some other files. Plus, he will cover Moralis integration starting at 30:05. Nonetheless, the video guide will also go through the details of signature types. Thus, you will learn the difference between the “personal” and “EIP-712” signatures (42:15). Finally, at 47:38, you’ll have a chance to see our example dApp’s demo.

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

Gasless Transactions – Exploring Gasless Transactions on Ethereum – Summary

If there’s one thing you’ve learned above, it’s that no transactions on EVM-compatible chains can be completed without gas fees. As such, gasless transactions do not mean that there’s no gas required for those transactions. It only means that there is a way to set things up so that the users do not need to pay the transaction fees. Thus, dApps’ owners can set up some sort of transaction “forwarding” using Biconomy. In turn, the transaction fees are covered in the backend of those dApps. Moreover, you’ve learned that this feature has the potential to provide users with a much more pleasant experience and, therefore, add more value to any dApp. On the other hand, it is important to account for the accumulated value of expected transactions so that you can set the right budget. 

In addition, you’ve also learned about the power of Moralis and how easy it makes covering blockchain-related backend functionality. By creating your free Moralis account and creating your server, you get full access to this ultimate Web3 development platform. Moreover, in case you want to get the most out of your free crypto education, make sure to check out the Moralis YouTube channel and the Moralis blog. Both of these outlets publish fresh content regularly. For instance, some of the latest articles show you details about Web3 authentication by showcasing how to build a Web3 login in five steps, the ins and outs of GameFi and play-to-earn (P2E), details about Web3 wallets, how to interact with smart contracts through a website, how to authenticate Android apps with Moralis, DAO smart contract example, what are ERC20 contracts, how to integrate mint function to JS interface, and much more. 

Moralis Money
Stay ahead of the markets with real-time, on-chain data insights. Inform your trades with true market alpha!
Moralis Money
Related Articles
January 1, 2024

Full Web3 Wallets List – Exploring the Best Web3 Wallets

November 22, 2023

Best NFT Data Analytics for 2024 – Real-Time NFT Transfers, Tracking & Discovery

December 26, 2022

Exploring Verse – A New Metaverse Programming Language from Epic Games

March 20, 2023

How to Get an Address’ Token Balance on Solana

October 19, 2022

Solana Smart Contract Building – An Introduction

October 12, 2023

Rinkeby Faucet Guide – What is the Rinkeby Faucet and Testnet?

November 28, 2022

Palm Blockchain – What is the Palm Network?

April 4, 2024

Which is the Best Crypto Logo API to Get the Logo of a Token?

September 12, 2023

How to Get All NFT Tokens Owned by a User Address