GithubHelp home page GithubHelp logo

alex992y / relay-examples-frontend-backend-v5 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gelatodigital/relay-examples-frontend-backend-v5

0.0 0.0 0.0 344 KB

Repo showcasing how to call the relay from a React UI as well as from node

JavaScript 0.72% TypeScript 87.09% CSS 8.39% HTML 3.80%

relay-examples-frontend-backend-v5's Introduction

Relay Examples

This project showcases the implementation of the relay sdk v5 with front end (React) and back end (node) examples. The relay sdk implements ethers v6 that introduces some minor breaking changes when instantiating the providers and creating the payload data. Please refer to the ethers migration guide for further information

Frontend examples

We are using React to showcase the relay-sdk integration

Please add the Gelat Relay sponsorsKey here

yarn start

The implementation code can be found here:

Backend/Node examples

Please copy .env.example to .env and add the GELATO_RELAY_API_KEY, PRIVATE_KEY and ALCHEMY_ID. Then you can run:

sponsoredCallERC2771

yarn testSponsoredCallERC2771

code can be found here and here the docs

sponsoredCall

yarn testSponsoredCall

code can be found here and here the docs

callWithSyncFee

yarn testCallWithSyncFee

code can be found here and here the docs

callWithSyncFeeERC2771

yarn testCallWithSyncFeeERC2771

code can be found here and here the docs

concurrentSponsoredCallERC2771

yarn testConcurrentSponsoredCallERC2771

code can be found here and here the docs

getSignatureDataERC2771 with sponsoredCallERC2771WithSignature

yarn testSponsoredCallERC2771WithSignature

code can be found here and here the docs

getDataToSignERC2771 with sponsoredCallERC2771WithSignature

yarn testSponsoredGetDataToSignERC2771

code can be found here and here the docs

getSignatureDataERC2771 with callWithSyncFeeERC2771WithSignature

yarn testCallWithSyncFeeERC2771WithSignature

code can be found here and here the docs

getDataToSignERC2771 with callWithSyncFeeERC2771WithSignature

yarn testCallWithSyncFeeGetDataToSignERC2771

code can be found here and here the [docs]( and here the docs )

Tracking your Relay Request

WebSocket Subscription

Docs can be found here

Relay-sdk Implementation

    relay.onTaskStatusUpdate((taskStatus: TransactionStatusResponse) => {
      console.log("Task status update", taskStatus);
      fetchStatusSocket(taskStatus, setMessage, setLoading);
    });

Websocket API

 const relayStatusWs = new WebSocket(
      "wss://api.gelato.digital/tasks/ws/status"
    );
      relayStatusWs.onopen = (event) => {
        relayStatusWs.send(
          JSON.stringify({
            action: "subscribe" as string,
            taskId: response.taskId,
          })
        );
        relayStatusWs.onmessage = (event) => {
          fetchStatusSocket(JSON.parse(event.data).payload, setMessage, setLoading);
        };
      }

Polling for Updates

Docs can be found here

code

let status = await relay.getTaskStatus(taskIdToQuery);`

Status

Docs can be found here

 let details = {
        txHash: status?.transactionHash || undefined,
        chainId: status?.chainId?.toString() || undefined,
        blockNumber: status?.blockNumber?.toString() || undefined,
        executionDate: status?.executionDate || undefined,
        creationnDate: status?.creationDate || undefined,
        taskState: (status?.taskState as TaskState) || undefined,
      };
      let body = ``;
      let header = ``;

      let txHash = details.txHash;

      switch (details.taskState!) {
        case TaskState.WaitingForConfirmation:
          header = `Transaction Relayed`;
          body = `Waiting for Confirmation`;
          break;
        case TaskState.Pending:
          header = `Transaction Relayed`;
          body = `Pending Status`;

          break;
        case TaskState.CheckPending:
          header = `Transaction Relayed`;
          body = `Simulating Transaction`;

          break;
        case TaskState.ExecPending:
          header = `Transaction Relayed`;
          body = `Pending Execution`;
          break;
        case TaskState.ExecSuccess:
          header = `Transaction Executed`;
          body = `Waiting to refresh...`;

          destroyFetchTask.next();
          setTimeout(() => {
            console.log("finish");
            setLoading(false);
          }, 2000);

          break;
        case TaskState.Cancelled:
          header = `Canceled`;
          body = `TxHash: ${details.txHash}`;
          destroyFetchTask.next();
          break;
        case TaskState.ExecReverted:
          header = `Reverted`;
          body = `TxHash: ${details.txHash}`;
          destroyFetchTask.next();
          break;
        case TaskState.NotFound:
          header = `Not Found`;
          body = `TxHash: ${details.txHash}`;
          destroyFetchTask.next();
          break;
        case TaskState.Blacklisted:
          header = `BlackListed`;
          body = `TxHash: ${details.txHash}`;
          destroyFetchTask.next();
          break;
        default:
          break;
      }

relay-examples-frontend-backend-v5's People

Contributors

donoso-eth avatar anirudhmakhana 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.