Create Account
import { createGelatoBundlerClient, 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 });
Create Bundler Client
const bundler = await createGelatoBundlerClient({ account, apiKey: process.env.GELATO_API_KEY, client, pollingInterval: 100 });
Send UserOperation
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}`);