Skip to content

dabit3/gasless-transactions-example

Repository files navigation

Gasless transactions via relayer example

This is a basic example project showing how to implement gasless meta-transactions via a Biconomy relayer and ERC2771Context.

Project setup

  1. Clone the repo
git clone [email protected]:dabit3/gasless-transactions-example.git
  1. Install dependencies
cd gasless-transactions-example

npm install

# or

yarn
  1. Configure PRIVATE_KEY and INFURA_ENDPOINT environment variables in hardhat.config.js.

Also if you are deploying to a network other than Polygon, you can configure that information in hardhat.config.js.

  1. Compile the project
npx hardhat compile
  1. Deploy the smart contract
npx hardhat run scripts/deploy.js --network polygon
  1. Update the greeterAddress in pages/index.js

Biconomy integration

  1. Create an account on Biconomy

  2. Create a new app. Choose the network you'd like to use (I deployed to Polygon).

  3. Enter the smart contact address and ABI (ABI located at artifacts/contracts/Greeter/Greeter.sol/Greeter.json)

Biconomy setup

  1. In Dapp APIs, add the setGreeting function

  2. Create a .env.local file in the Next.js project and add the Biconomy API Key:

NEXT_PUBLIC_BICONOMY_API_KEY=your-api-key
  1. Run the app
npm start

TLDR for implementing in existing app

  1. Update contract to inherit from ERC2771Context
pragma solidity ^0.8.9;

import "@openzeppelin/contracts/metatx/ERC2771Context.sol";

contract Greeter is ERC2771Context {}
  1. msg.sender -> _msgSender() - (though this contract does not use msg.sender)

  2. Configure Biconomy app with contract address and methods you'd like to use

  3. Update client-side code to use Biconomy SDKs

About

Example of Gasless Transactions with Biconomy

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published