Skip to main content

Get Your API Key

Create API Key

Get started by creating an API key from the Gelato App

Example for sponsored UserOperation using Gelato Account

1

Create Account

Set up the owner wallet and create a Gelato smart account:
import { createGelatoBundlerClient, sponsored, toGelatoSmartAccount } from "@gelatocloud/gasless";
import { createPublicClient, http, type Hex } from "viem";
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
import { baseSepolia } from "viem/chains";

const owner = privateKeyToAccount((process.env.PRIVATE_KEY ?? generatePrivateKey()) as Hex);

const client = createPublicClient({
  chain: baseSepolia,
  transport: http()
});

const account = await toGelatoSmartAccount({
  client,
  owner
});
2

Create Bundler Client

Initialize the Gelato bundler client with your account and payment method:
const bundler = await createGelatoBundlerClient({
  account,
  apiKey: process.env.GELATO_API_KEY,
  client,
  payment: sponsored(),
  pollingInterval: 100
});
3

Send UserOperation

Send a UserOperation and wait for the transaction receipt:
const hash = await bundler.sendUserOperation({
  calls: [
    {
      data: '0xd09de08a',
      to: '0xE27C1359cf02B49acC6474311Bd79d1f10b1f8De'
    }
  ]
});

console.log(`User operation hash: ${hash}`);

const { receipt } = await bundler.waitForUserOperationReceipt({ hash });
console.log(`Transaction hash: ${receipt.transactionHash}`);