Documentation Index
Fetch the complete documentation index at: https://docs.gelato.cloud/llms.txt
Use this file to discover all available pages before exploring further.
Batching transactions combines multiple operations into a single transaction. Instead of staking tokens and claiming rewards separately, users can perform both in one transaction.
Getting Started
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
To create an API Key, visit the Gelato App and navigate to Paymaster & Bundler > API Keys.const relayer = await createGelatoSmartAccountClient({
account,
apiKey: process.env.GELATO_API_KEY,
});
Batch Multiple Transactions
Add multiple operations to the calls array: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}`);