Gelato Smart Wallet Integration Guide
Gas fees are one of the biggest barriers to blockchain adoption. Users often need to hold native tokens just to pay for transaction fees, creating friction in onboarding and limiting the types of applications that can be built. Gelato Smart Wallet solves this problem by enabling gasless transactions on Flow EVM through sponsored transactions.
With Gelato Smart Wallet, you can:
- Eliminate gas fees for your users by sponsoring their transactions
- Improve user experience with seamless onboarding that doesn't require users to hold FLOW tokens
- Support EIP-7702 for enhanced smart wallet functionality
- Scale your dApp by removing the cost barrier for user interactions
- Leverage Flow's low gas costs to provide affordable sponsored transactions
This tutorial will guide you through setting up Gelato Smart Wallet to enable gasless transactions on Flow EVM. You'll learn how to configure the necessary API keys, fund your sponsorship account, and implement gasless transaction functionality in your applications.
This tutorial focuses on EIP-7702 implementation with Gelato Smart Wallet on Flow EVM. EIP-7702 provides a streamlined experience for users by maintaining the same address as their EOA while adding smart wallet capabilities, enabling enhanced features like gasless transactions and improved user experience.
Objectives
After completing this guide, you'll be able to:
- Configure a Gelato Smart Wallet account with proper API keys and funding setup
- Implement gasless transaction functionality using the Gelato Smart Wallet SDK
- Estimate and execute sponsored transactions on Flow EVM
- Integrate EIP-7702 features for enhanced user experience
- Troubleshoot common issues with Gelato Smart Wallet integration
Prerequisites of using Gelato Smart Wallet
You need to set up the following 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.
You'll need to add more information for your smart contracts at a later date.
When set to a specific contract instead of Any contract
, the API keys will only allow sponsored transactions for calls to the designated methods within the ABI of that contract.
Step 3. Deposit Funds into 1Balance
To use Gelato for sponsored transactions, you need to deposit funds into 1Balance according to your target environment:
- Mainnets: Deposit USDC.
- Testnets: Deposit Sepolia ETH.
Click the 1Balance
tab to deposit .001
Sepolia ETH testnet funds.
If you need to fund your account, you can use one of the following third-party faucets:
Step 4. Create/Obtain an API Key
After creating the Relay App, navigate to its dashboard to locate your Sponsor API Key.
This key links your Gelato setup with 1Balance for gas sponsorship.
Copy the API key to your clipboard.
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.
You can find the examples in the Gelato Smart Wallet SDK repository.
Step 1. Install all relevant dependencies
- pnpm
- bun
- yarn
- npm
_10pnpm add @gelatonetwork/smartwallet viem
_10bun add @gelatonetwork/smartwallet viem
_10yarn add @gelatonetwork/smartwallet viem
_10npm install @gelatonetwork/smartwallet viem
Step 2. Setup Smart Wallet Account
Import required dependencies:
_11import { createGelatoSmartWalletClient, sponsored } from "@gelatonetwork/smartwallet";_11import { gelato } from "@gelatonetwork/smartwallet/accounts";_11import { createWalletClient, createPublicClient, http, type Hex } from "viem";_11import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";_11import { flowTestnet } from "viem/chains";_11_11// Create a public client for the Flow Testnet_11const 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_10const privateKey = (process.env.PRIVATE_KEY ?? generatePrivateKey()) as Hex;_10const owner = privateKeyToAccount(privateKey);_10_10// Wrap the EOA account into a Gelato Smart account_10const account = await gelato({_10 owner,_10 client: publicClient,_10});
Then you need to create a standard viem wallet client with the Gelato Smart Account.
_10const 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.
_10const sponsorApiKey = process.env.SPONSOR_API_KEY;_10if (!sponsorApiKey) {_10 throw new Error("SPONSOR_API_KEY is not set");_10}_10_10const 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.
_13const response = await swc.estimate({_13 payment: sponsored(sponsorApiKey),_13 calls: [_13 {_13 to: "0xa8851f5f279eD47a292f09CA2b6D40736a51788E",_13 data: "0xd09de08a",_13 value: 0n_13 }_13 ]_13});_13_13console.log(`Estimated fee: ${formatEther(BigInt(response.fee.amount))} FLOW`);_13console.log(`Estimated gas: ${JSON.stringify(response.gas)} GAS`);
To send a gasless transaction, you can use the execute
method.
_14const results = await smartWalletClient.execute({_14 payment : sponsored(sponsorApiKey),_14 calls: [_14 {_14 to: "0xa8851f5f279eD47a292f09CA2b6D40736a51788E",_14 data: "0xd09de08a",_14 value: 0n_14 }_14 ]_14});_14_14console.log("userOp hash:", results?.id);_14const txHash = await results?.wait();_14console.log("transaction hash",txHash);
Or you can use prepare
+ send
to send a gasless transaction.
_27const 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_27const results = await swc.send({_27 preparedCalls_27});_27_27// You can listen for events from the Gelato Smart Wallet client_27results.on("submitted", (status: GelatoTaskStatus) => {_27 console.log(`Transaction submitted: ${status.transactionHash}`);_27});_27results.on("success", async (status: GelatoTaskStatus) => {_27 console.log(`Transaction successful: ${status.transactionHash}`);_27});_27results.on("error", (error: Error) => {_27 console.error(`Transaction failed: ${error.message}`);_27});
Conclusion
In this tutorial, you successfully integrated Gelato Smart Wallet to enable gasless transactions on Flow EVM. You learned how to set up the necessary infrastructure, configure API keys, fund sponsorship accounts, and implement gasless transaction functionality in your applications. The implementation demonstrates how Flow's low gas costs combined with Gelato's sponsored transaction infrastructure can create seamless user experiences that eliminate the friction of gas fees.
Now that you have completed the tutorial, you should be able to:
- Configure a Gelato Smart Wallet account with proper API keys and funding setup
- Implement gasless transaction functionality using the Gelato Smart Wallet SDK
- Estimate and execute sponsored transactions on Flow EVM
- Integrate EIP-7702 features for enhanced user experience
- Troubleshoot common issues with Gelato Smart Wallet integration
The combination of Flow's efficient gas pricing and Gelato's sponsored transaction infrastructure opens up new possibilities for building user-friendly dApps. By eliminating the need for users to hold native tokens for gas fees, you can create onboarding experiences that rival traditional Web2 applications while maintaining the security and transparency of blockchain technology.