Introduction To Meta-Transactions

In this guide, we will explore the concept of gasless transactions(Meta Transactions) and how digital signatures are important.

·

5 min read

Introduction To Meta-Transactions

Overview

Hello reader! We are going to be talking about meta transactions and how digital signatures are useful in performing meta transactions. My first practical encounter of how it works was when I was listing my profile picture(pfp) on open sea and all i had to do was sign the transaction, paying no gas fee. Sounds cool right? Do not worry if you have not heard this term before; all will be explained to you by the end of the guide.

In Ethereum world, state changes are triggered by transactions and the execution of this transactions cost gas which is eventually paid in Ether right? But what if you want to create a transaction and you have no money to pay for gas! This is where digital signatures and meta-transactions comes in.

What are Digital Signatures?

In blockchain, digital signatures are a way to proof ownership of a particular private key without even revealing it. The following are the core functionalities of signature viz :

  • ownership and authorization: owner of the private key authorizes the execution of a transaction

  • non-repudiation: proof of authorization is undeniable

  • data integrity: transaction signed cannot be modified by anyone else.

Having said that, digital signature are very instrumental to performing meta transactions

What are Meta Transactions?

Let's quickly explore the concept of meta transactions otherwise known as gasless transactions. A gasless transaction is a regular Ethereum transaction which contains another transaction, the actual transaction. This actual transaction is signed by a user and then sent to an operator or preferably an executor; no gas fees incurred. The operator takes this signed transaction and submits it to the blockchain paying for the fees himself. The smart contract for verification ensures there is a valid signature on the actual transaction and then executes it.

In simple terms, meta transactions are transactions who’s data is created and signed off-chain by one person and executed by another person who pays the gas fees.

How important is this?

Taking into consideration how high gas fees can be when performing transactions, new users might find it difficult to interact with dapps thereby reducing adoption or even onboarding them. The importance of gasless transaction cannot be over-emphasized in the Ethereum world, as it facilitates the on-boarding of first-time dapp users. Beyond that, it tends to save gas and reduce the amount of transactions performed on-chain. There are quite different implementation of these, below are a few implementation for meta transactions:

  1. Listing on Opensea : Listing order is created off-chain, the hash and signature of the order is stored off-chain. When someone buys the item, the order would be matched and gas would be paid by the buyer.
  2. Sending Tokens : Imagine you participated in an hackathon and won, submitted your Ethereum address for the prize of 1000 USDT with 0 ether in it . You are unable to make use of them since you don’t have enough money(ETH) to execute any transactions or transfer them out. In this case the process is the same, a message with some data is created and signed by whoever wants to execute a transaction. That signed data is then verified and sent in a normal Ethereum transaction by another party.

In other to understand this concept, i did a project that helped solidify my understanding of it. You can check it out here DigSIg, also checkout the source code and do well to read the ReadMe on Github.

Note

There are a lot of improvements that can be added to fit your usecase, the goal of this is to show you how Person A can sign a message off-chain without paying gas and then be executed by Person B. From here on there are limitless improvements and changes that could be done to fit your needs.

DigSig Code Breakdown

DisSig accepts three things to sign as message, which is the address of the recipient, amount, and nonce value. When signed it returns the signature which is passed to an actor to verify on the verify page. Furthermore, the core functionality of DigSig can be divided in to two main part viz:

a. Signing messages off-chain

b. Verifying the signed message on-chain

Signing Message Off-chain

Before signing a message, our message input is gotten from the form value when submitted and structured in this format.

Recipient: 0x712dummyaddress, Amount: 100, Nonce: 12

Using ethers js, we can easily hash and sign the message respectively.

signMessage.png

Verifying the signed message on-chain

Once the message is created and signed, it is passed to the actor who will be executing the transaction on-chain. For signature verification on-chain, a contract is created and it major functionality can be done with a few simple steps.

  • Step 1: Verify the signature of the meta-transaction. This verifyMessage function takes in the original signer, hashed message and a split of the signature(v,r,s). It passes if true, reverts with the error message if false. The next line of code is to prevent against replay attacks.
   require (verifyMessage(from, _hashedMessage, _v, _r, _s),"DiSig: Invalid signature or incorrect hash");

   require(!nounceUsed[signer][nounce], "DigSig: Already used nounce");
  • Step 2: Sends the funds out to the recipient after it passes those pre-conditions.
 (bool sent, ) = to.call{value: amount}("");
  require(sent, "DigSig: Failed to send Matic");

This is the major execution of the contract. All values passed in while verifying message is passed in from the front-end. For more details, check out the source code on github.

Others

Had fun developing this project, and here are some of the tools used

  • Solidity - for writing smart contract

  • Javascript: For writing scripts

  • Moralis - for interacting with the smart contract

  • Ether js for hashing and signing message

Hope you were able to learn about meta transactions and it's importance in the Ethereum world? Feel free to drop your comments and suggestions.

Thanks. Be sure to check out other articles to learn more about Meta Transactions 1, 2