Skip to main content

Gelato Smart Wallet Integration Guide

You can use Gelato Smart Wallet to enable gasless transactions on Flow EVM. It supports features like: EIP-7702 or ERC-4337 depending on the wallet you use.

Prerequisites of using Gelato Smart Wallet

You need to setup all the followings in the Gelato App to create a Gelato Sponsor API Key.

Step 1. Create Your Gelato Account

Sign up on the Gelato App to establish an account. This account is the foundation for setting up relay tasks and managing gas sponsorships.

Step 2. Create a Relay App

Within your Gelato account, create a new Relay App with the Flow EVM network.
For Testnet, you can first allow Any contract to call your relay app.

Create a Relay App

note

You can add more smart contract information and its associated chain information later in this App.
When set to a specific contract instead of Any contract, the API keys will only allow gasless transactions for calls to the designated methods within the ABI of the contract.

Step 3. Create/Obtain a Sponsor API Key

After creating the relay app, navigate to its dashboard to locate your Sponsor API Key.

Create a Sponsor API Key

This key links your Gelato setup with 1Balance for gas sponsorship.

Step 4. Deposit Funds into 1Balance

To use Gelato sponsoring transactions, you need to deposit funds into 1Balance according to your target environment:

  • Mainnets: Deposit USDC.
  • Testnets: Deposit Sepolia ETH.

Here we use Sepolia ETH as the gas fee for Testnet‘s gasless transactions.

Deposit Funds into 1Balance

Here are some third party Sepolia ETH faucets you can use:

Send Gasless Transactions for your users

After you have created a Sponsor API Key and deposited funds into 1Balance, you can use gasless transactions features for your users.
With the Gelato Smart Wallet SDK, developers can easily set up sponsored transactions for their applications in just a few simple steps, enabling seamless onboarding and interaction without requiring users to hold native tokens.

note

You can find the examples in the Gelato Smart Wallet SDK repository.

Step 1. Install all relevant dependencies


_10
pnpm add @gelatodigital/smartwallet viem

Step 2. Setup Smart Wallet Account

Import required dependencies:


_11
import { createGelatoSmartWalletClient, sponsored } from "@gelatonetwork/smartwallet";
_11
import { gelato } from "@gelatonetwork/smartwallet/accounts";
_11
import { createWalletClient, createPublicClient, http, type Hex } from "viem";
_11
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
_11
import { flowTestnet } from "viem/chains";
_11
_11
// Create a public client for the Flow Testnet
_11
const publicClient = createPublicClient({
_11
chain: flowTestnet,
_11
transport: http(),
_11
});

You can set up a Smart Account as per your needs.
Once you create the gelato account, the Gelato Smart Account address will be the same as your EOA, enabling EIP-7702 features.


_10
// Prepare a normal EOA account
_10
const privateKey = (process.env.PRIVATE_KEY ?? generatePrivateKey()) as Hex;
_10
const owner = privateKeyToAccount(privateKey);
_10
_10
// Wrap the EOA account into a Gelato Smart account
_10
const account = await gelato({
_10
owner,
_10
client: publicClient,
_10
});

Then you need to create a standard viem wallet client with the Gelato Smart Account.


_10
const client = createWalletClient({
_10
account,
_10
chain: flowTestnet,
_10
transport: http()
_10
});

Once you have a standard viem wallet client, you can wrap it into a Gelato Smart Wallet client with the sponsor API key.


_10
const sponsorApiKey = process.env.SPONSOR_API_KEY;
_10
if (!sponsorApiKey) {
_10
throw new Error("SPONSOR_API_KEY is not set");
_10
}
_10
_10
const swc = await createGelatoSmartWalletClient(client, {
_10
apiKey: sponsorApiKey
_10
});

Step 3. Estimate or Send a Gasless Transaction

Now you can estimate or send a gasless transaction with the Gelato Smart Wallet client.

To estimate the fee and gas for a gasless transaction, you can use the estimate method.


_13
const response = await swc.estimate({
_13
payment: sponsored(sponsorApiKey),
_13
calls: [
_13
{
_13
to: "0xa8851f5f279eD47a292f09CA2b6D40736a51788E",
_13
data: "0xd09de08a",
_13
value: 0n
_13
}
_13
]
_13
});
_13
_13
console.log(`Estimated fee: ${formatEther(BigInt(response.fee.amount))} FLOW`);
_13
console.log(`Estimated gas: ${JSON.stringify(response.gas)} GAS`);

To send a gasless transaction, you can use the execute method.


_14
const results = await smartWalletClient.execute({
_14
payment : sponsored(sponsorApiKey),
_14
calls: [
_14
{
_14
to: "0xa8851f5f279eD47a292f09CA2b6D40736a51788E",
_14
data: "0xd09de08a",
_14
value: 0n
_14
}
_14
]
_14
});
_14
_14
console.log("userOp hash:", results?.id);
_14
const txHash = await results?.wait();
_14
console.log("transaction hash",txHash);

Or you can use prepare + send to send a gasless transaction.


_27
const preparedCalls = await swc.prepare({
_27
payment: sponsored(sponsorApiKey),
_27
calls: [
_27
{
_27
to: "0xa8851f5f279eD47a292f09CA2b6D40736a51788E",
_27
data: "0xd09de08a",
_27
value: 0n
_27
}
_27
]
_27
});
_27
_27
// Other actions can be performed here
_27
_27
const results = await swc.send({
_27
preparedCalls
_27
});
_27
_27
// You can listen for events from the Gelato Smart Wallet client
_27
results.on("submitted", (status: GelatoTaskStatus) => {
_27
console.log(`Transaction submitted: ${status.transactionHash}`);
_27
});
_27
results.on("success", async (status: GelatoTaskStatus) => {
_27
console.log(`Transaction successful: ${status.transactionHash}`);
_27
});
_27
results.on("error", (error: Error) => {
_27
console.error(`Transaction failed: ${error.message}`);
_27
});


Conclusion

So far, you’ve learned how to send sponsored EIP-7702 transactions using a Gelato Smart Wallet on Flow EVM.