Implementing meta transactions in your smart contract using Biconomy SDK

Implementing meta transactions in your smart contract using Biconomy SDK

In this blog, we will be implementing the biconomy framework tools which are used for enabling meta transactions in smart contracts.

A meta-transaction can be defined as the way that allows the user to interact with the public blockchain without paying any transaction fee.

A meta-transaction is a general Ethereum transaction containing another transaction, the actual transaction. The actual transaction is then signed by the user and then sent to an operator or something similar which means no gas and blockchain interaction is required.

In order to perform meta-transactions, a user needs to sign a message. After a user signs it, DApp (Decentralised Application ) sends the message to a relayer who sends that message into an actual transaction to a public node so the transaction can be mined.

Biconomy is the scalable relayer infrastructure network and transaction management platform enabling DApps to reduce the friction between DApps and end-users.

👉 This whole process is divided into three-phase:

  1. Changing in smart contract

  2. Initialize Biconomy instance at client side

  3. Create Biconomy Dashboard for DApp

In order to enable meta-transaction using biconomy tools, follow the below steps:

  1. Adding a Contract in the existing Smart Contract :
  • Make one smart contract for internal meta transaction as shown below, refer to the code here :

  • Inherit this contract into your existing contract. Here, I have used the below TestContract.sol. Deploy this contract on the kovan test network and copy the contract address and ABI code.

2. Initializing biconomy instance at the client-side :

Mexa integration is a two-step process:

1) Register your DApp on Mexa Dashboard, a dashboard for developers, and copy API Key generated for your DApp.

2) Integrate Mexa SDK in your DApp code using API Key you got from the dashboard.

First, install biconomy SDK using the npm package manager. Biconomy’s SDK is called Mexa

👉npm install @biconomy/mexa

👉Import Biconomy Mexa.

👉import { Biconomy } from “@biconomy/mexa”

Create one config object as shown below for contract address and abi and apikey.

Now initialize the biconomy instance, refer to the code here .

  • Make onSubmit function for initializing meta transaction with user’s signed message. Now call the contract get method for getting an updated quote which will be fetched from the blockchain network.

  • And at the last add one more async function for sending signed transactions on the network via MetaMask.

Now call this component from App.js

3. Create Biconomy Dashboard for your DApp.

First, create your account on the biconomy platform. You can use the following link:

Biconomy Dashboard
Edit description
dashboard.biconomy.io

4. Click on the register button for generating the API key for your DApp.

5. Write your DApp name and select the appropriate network you want for your DApp. For this tutorial, We used “Kovan Network”.

6. Click on “View DApp”

7. Your DApp dashboard will be opened. There is one API key that we need to add to our frontend file. You have to add the required amount of kovan faucet to the Gas Tank. All transaction gas fees will be deducted from this only. Users don’t need to pay gas fees from their accounts.

8. Click on add contract button and add the contract name, address which we deployed already, and abi code for the same. And add this contract to your DApp.

9. Next step is to click on “Manage API” and go to “New API”. From the given list select your contract and select contract methods that you want to work as meta transactions. In this way build your API for each and every function you want to execute and Native Meta transaction.

Now, go to your VS code Editor and start the development server and see it’s working as a Native Meta transaction.

GitHub - aniforverizon/blockchain-meta
*This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, a sample…*
github.com

Getting Started
Register your dApp, Integrate the SDK (Mexa) and start sending API requests
docs.biconomy.io

Native Meta Transaction
*Enable meta transactions or gasless transactions in your Dapp with our native meta transaction API. No extra signature…*
docs.biconomy.io

Happy Learning !!!

For any further queries or anything related to Blockchain Development, Coding, Blogging, or Tech Documentation you can DM me on Linkedin or Instagram at id=acanubhav94.

Special credits to my team members: Smit and Anshika.