Learn how to set up gas-less transactions with thirdweb.
Gasless Transactions 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: 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/...",
},
},
}}
>
{/* 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/...",
},
},
});