Meta-transaction Relayer
You may want to sponsor the gas for your user's transactions using a meta-transaction relayer.
Engine allows you to create meta-transaction relayer endpoints that you can use from your client-side application.
It supports the following standard meta-transaction formats:
In this guide, we're going to setup a meta-transaction relayer with Engine and use it to sponsor gas fees for users' client-side transactions.
Step 1: Create a meta-transaction relayer endpoint
First, we need to create a new meta-transaction relayer endpoint with Engine.
You can do this from the Explorer
tab on your Engine dashboard by navigating to the POST - /relayer/create
endpoint.
Here, you'll need to specify:
- The
chain
your relayer will function on. - The
backendWalletAddress
of the Engine backend wallet you want to use to sponsor funds for your user. - The
allowedContracts
that the endpoint can forward transactions to. - Optionally, the
name
of your relayer - Optionally, the
allowedForwarders
the relayer is allowed to forward transactions with
Once you create the endpoint, you'll get back a uuid
which is the unique ID of your relayer endpoint.
With this ID, you're meta-transaction relayer endpoint will be at POST - /relayer/{relayerId}
.
Step 2: Use your relayer endpoint to sponsor transactions
Now that we've setup our endpoint, we can use it to sponsor transactions for our users using the @thirdweb-dev/react
package on the client-side.
All we need to do is setup the SDK to be aware of our meta-transaction relayer endpoint using the ThirdwebProvider
, and it will attempt to send all transactions through the endpoint.
In the following snippet, we setup the ThirdwebProvider
, and additionally specify the sdkOptions.gasless.engine.relayerUrl
parameter to enable meta-transaction relaying.
And we'll need to add a ConnectWallet
button into our app to allow our user's to connect their wallets - this button is highly customizable, for more you can read into the details of using the ConnectWallet button.
Now, when we send a transaction to a contract from the user's connected wallet, it will be forwarded through our meta-transaction relayer and sponsored by the Engine backend wallet instead of forcing the user to spend funds.
Using this simple flow, you can use Engine as a meta-transaction relayer to sponsor funds for your users!
The last point to note - the SDK and Engine will automatically detect what type of meta-transaction method (EIP-2771, EIP-2612, etc.) is appropriate to use based on your contract, and will handle the details under the hood.