Skip to content

Using Gelato Relay, we relay your user's transactions on-chain, enabling secure gasless transactions for an ultra smooth UX for your app

Notifications You must be signed in to change notification settings

gelatodigital/how-tos-5-6-7-8-relay-intro-methods

Repository files navigation

How To #5-6-7-8 on Gelato: Relay Methods

Introduction to Gelato Relay

Using Gelato Relay, we relay your user's transactions on-chain, enabling secure gasless transactions for an ultra smooth UX for your app. This allows for a variety of new web3 experiences, as the user can now pay by only signing a message, or their transaction costs can be sponsored by the developer. As long as the gas costs are covered in one of the multiple payment methods that Gelato supports, we handle the rest reliably, quickly and securely.

Video Walkthrough

The Gelato Relay SDK provides developers with various methods to interact with Gelato's infrastructure. Below are four essential SDK methods:

ERC2771 MEthods

sponsoredCallERC2771

This method executes a function on behalf of the user, allowing them to submit tasks without holding any ETH in their wallets. It utilizes the EIP-2771 standard for meta transactions, enabling gasless transactions for users, and leverages Gelato 1balance for payment.

Video Walkthrough

callWithSyncFeeERC2771

Combining the features of callWithSyncFee and EIP-2771 meta transactions, this method provides gasless transaction capabilities. The target contract assumes responsibility for transferring the fee to Gelato's fee collector during transaction execution.

Video Walkthrough

NON ERC2771 MEthods

Video Walkthrough

sponsoredCall

Similar to sponsoredCallERC2771, this method enables gasless transactions using a different approach, suitable for environments where you have your own authentication logic. Also making use of Gelato 1balance.

callWithSyncFee

When using callWithSyncFee relay method the target contract assumes responsibility for transferring the fee to Gelato's fee collector during transaction execution.

Backend/Node examples

Important

"@gelatonetwork/relay-sdk": "^5.5.0",

Environment Setup

Please copy .env.example to .env and add the following variables:

  • GELATO_RELAY_API_KEY
  • PRIVATE_KEY
  • ALCHEMY_ID

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;
}

Gelato Relay Contracts on Arbitrum Blueberry

Contract Name Blueberry GelatoScout Link
CounterFeeCollector Link
CounterFeeCollectorERC2771 Link
CounterRelayContext Link
CounterRelayContextERC2771 Link
OneBalanceCounterERC2771 Link
OneBalanceSimpleCounter Link

About

Using Gelato Relay, we relay your user's transactions on-chain, enabling secure gasless transactions for an ultra smooth UX for your app

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published