> ## 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

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

<Steps>
  <Step title="Import Dependencies">
    ```typescript theme={null}
    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";
    ```
  </Step>

  <Step title="Setup Smart Account">
    ```typescript theme={null}
    const owner = privateKeyToAccount(
      (process.env.PRIVATE_KEY ?? generatePrivateKey()) as Hex
    );

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

    const account = toGelatoSmartAccount({
      client,
      owner,
    });
    ```
  </Step>

  <Step title="Create Relayer Client">
    To create an API Key, visit the [Gelato App](https://app.gelato.cloud/) and navigate to `Paymaster & Bundler > API Keys`.

    ```typescript theme={null}
    const relayer = await createGelatoSmartAccountClient({
      account,
      apiKey: process.env.GELATO_API_KEY,
    });
    ```
  </Step>

  <Step title="Batch Multiple Transactions">
    Add multiple operations to the `calls` array:

    ```typescript theme={null}
    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}`);
    ```
  </Step>
</Steps>
