Import Dependencies
import { createGelatoSmartAccountClient, toGelatoSmartAccount, } from "@gelatocloud/gasless"; import { createPublicClient, http, type Hex, encodeFunctionData } from "viem"; import { generatePrivateKey, privateKeyToAccount } from "viem/accounts"; import { baseSepolia } from "viem/chains";
Setup Smart Account
const owner = privateKeyToAccount( (process.env.PRIVATE_KEY ?? generatePrivateKey()) as Hex ); const client = createPublicClient({ chain: baseSepolia, transport: http(), }); const account = toGelatoSmartAccount({ client, owner, });
Create Relayer Client
Paymaster & Bundler > API Keys
const relayer = await createGelatoSmartAccountClient({ account, apiKey: process.env.GELATO_API_KEY, });
Batch Multiple Transactions
calls
const receipt = await relayer.sendTransactionSync({ calls: [ { to: "<token-address>", data: encodeFunctionData({ abi: tokenAbi, functionName: "approve", args: [targetContractAddress, amount], }), }, { to: "<target-contract-address>", data: encodeFunctionData({ abi: targetContractAbi, functionName: "stake", args: [amount], }), }, { to: "<target-contract-address>", data: encodeFunctionData({ abi: targetContractAbi, functionName: "claimRewards", args: [], }), }, ], }); console.log(`Transaction hash: ${receipt.transactionHash}`);