Set Up Gasless Transactions with OpenZeppelin Defender

Set Up Gasless Transactions with OpenZeppelin Defender - thirdweb Guides

In this guide, we'll show you how to set up gasless transactions, which use a relayer to forward transactions, allowing you to cover the gas costs of transactions for your users.

Relayers can be self-managed or run using various service providers:

Using OpenZeppelin Defender

To set up gasless transactions using OpenZeppelin Defender, we need to set up an
Autotask and a
Relay.

  1. Sign up for OpenZeppelin Defender
  2. Create a Relayer in the Dashboard by clicking "Add first Relayer" while in the Relay tab.
  • Name: your desired name for the Relayer
  • Network: the network that you want the relayer to operate in, learn more about networks
  1. Deposit funds into the Relayer by copying the relayer address, and transferring the funds native to the network to this address. e.g. MATIC if you chose the Polygon network.
  2. Create an Autotask in the Dashboard under Autotask.
  • Name: your desired name for the Autotask.
  • Trigger: set to Webhook
  • Connect to a relayer: Select the Relayer you just created.
  • Code: Remove the autofilled code, copy the code from our GitHub and paste it in the Code box.
  1. Copy the Webhook URI from the Autotask dashboard.
  2. Paste the Webhook URI into the SDK constructor options.

For example:

React SDK:

import { ChainId, ThirdwebProvider } from "@thirdweb-dev/react";

<ThirdwebProvider
  desiredChainId={ChainId.Mumbai}
  sdkOptions={{
    gasless: {
      openzeppelin: {
        relayerUrl: "https://api.defender.openzeppelin.com/autotasks/...",
        useEOAForwarder: true
      },
    },
  }}
>
  {/* Your App Here */}
</ThirdwebProvider>;

or, TypeScript SDK:

import { ThirdwebSDK } from "@thirdweb-dev/sdk";

new ThirdwebSDK(signerOrProvider, {
  gasless: {
    openzeppelin: {
      relayerUrl: "https://api.defender.openzeppelin.com/autotasks/...",
        useEOAForwarder: true
    },
  },
});

Check the code on GitHub.

Have questions? Join our Discord!