Giter Site home page Giter Site logo

gelato-relay's Introduction

Example of Relaying Meta-Transactions Using Gelato

Demo code for relaying meta-transactions using Gelato using the client API.

This project consists of a sample names registry contract that accepts registrations for names either directly or via a meta-transaction, along with a client Dapp, plus the meta-transaction relayer implementation.

Environment

Expected .env file in the project root:

  • RELAY_API_KEY: Gelato Relay API key.

To get the Realy keys you will need to sign up to 1Balance. See more information here

Run the code

Once you set up the .env file you need to install the dependencies yarn install

Then start the next app yarn dev

It will start a webpage at localhost:3000 and a backend that is used for APIs.

Warning if using Gelato SDK

Gelato comes with an SDK but it's meant to be used directly from the front end as relayWithSponsoredCallERC2771 needs a provider that can sign the transaction, as the wallet in most cases would be the user signing off-chain with Metamask this would have to go on the front end. But if we do that, we would expose our API KEY and an attacker may use your API KEY to relay their transactions.

import { GelatoRelaySDK } from "@gelatonetwork/relay-sdk";

const counter = "0x...";
const abi = ["function increment()"];
const provider = new ethers.providers.Web3Provider(window.ethereum);
const signer = provider.getSigner();
const user = signer.getAddress();

const contract = new ethers.Contract(counter, abi, signer);
const { payload } = await contract.populateTransaction.increment();

const relayRequest = {
  chainId: provider.network.chainId;
  target: counter;
  data: payload;
  user: user;
};

const apiKey = "stracciatella";

// Get user signature and send relay request to Gelato Relay
const relayResponse =
  await GelatoRelaySDK.relayWithSponsoredCallERC2771(relayRequest, provider, apiKey);

console.log(relayResponse);`

As we need to use this in the backend we ended up using the Gelato API instead.

Take into account that Gelato does not use the value field when relaying transactions so we can't relay ETH transfers.

Example addresses are sometimes wrong in gelato docs, trusted forwarder used by the SDK is 0xBf175FCC7086b4f9bd59d5EAE8eA67b8f940DE0d, but the deployed example contracts are pointing to the wrong address so we had to deploy new ones https://github.com/Think-and-Dev/gelato-relay-contract. In case you are getting errors that don't make much sense try reaching out to their discord

Highlights

The most important parts are:

More info

This code is based on [Gelato examples which make use of gelato sdk and relayers on the Goerli network. Functionality is supported across any of Gelato's supported chains -- simply modify the code.

gelato-relay's People

Contributors

hperezrodal avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.