Set Up Gasless Transactions with OpenZeppelin Defender
⚠️ Warning: This guide currently uses v4 of the Connect SDK. For v5 (latest) code snippets, please check out our documentation while this guide is being updated. ⚠️
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.
- Sign up for OpenZeppelin Defender
- 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
- 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.
- 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.
- Copy the Webhook URI from the Autotask dashboard.
- 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
},
},
});
Have questions? Join our Discord!