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

# Estimate Gas Costs

> Learn how to estimate gas costs for transactions using the Gasless SDK

One of the key features of the Gasless SDK is its ability to estimate gas costs before sending a transaction on-chain—across different gas payment methods.

Gas estimation is crucial for ensuring transactions are processed smoothly and efficiently. It helps developers and users avoid failed transactions due to underpayment and provides better transparency into the expected cost of execution, improving both reliability and user experience.

## Getting Started

<Steps>
  <Step title="Setup Smart Wallet Client">
    Quickly set up the Smart Wallet client as outlined in the How-To Guides.

    ```typescript theme={null}
    import { createGelatoSmartWalletClient, sponsored } from "@gelatonetwork/smartwallet";
    import { createWalletClient, createPublicClient, http } from "viem";
    import { gelato } from "@gelatonetwork/smartwallet/accounts";
    import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";

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

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

    const account = await gelato({
      owner: signer,
      client: publicClient,
    });

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

    const smartWalletClient = createGelatoSmartWalletClient(client);
    ```
  </Step>

  <Step title="Estimate Gas">
    Use `estimate` instead of `execute` when estimating gas for transactions with different gas payment methods.

    Note: When estimating gas for ERC-20 tokens, the results will be based on the token's decimals. Ensure you format the results accordingly. Learn how to use different gas payment methods [here](/smart-wallet-sdk/how-to-guides/allow-user-to-pay-with-erc20).

    ```typescript theme={null}
    const results = await smartWalletClient.estimate({
      payment: sponsored(apiKey),
      calls: [
        {
          to: "0xa8851f5f279eD47a292f09CA2b6D40736a51788E",
          data: "0xd09de08a",
          value: 0n
        }
      ]
    });

    console.log(`Estimated fee: ${formatEther(results.fee.amount)} ETH`);
    console.log(`Estimated gas: ${results.fee.gas} GAS`);
    ```
  </Step>

  <Step title="Estimate Gas for Multiple Transactions">
    You can also estimate gas for multiple transactions by adding them to the calls array:

    ```typescript theme={null}
    const results = await smartWalletClient.estimate({
      payment: sponsored(apiKey),
      calls: [
        {
          to: "0xa8851f5f279eD47a292f09CA2b6D40736a51788E",
          data: "0xd09de08a",
          value: 0n
        },
        {
          to: "0xa8851f5f279eD47a292f09CA2b6D40736a51788E",
          data: "0xd09de08a",
          value: 0n
        }
      ]
    });

    console.log(`Estimated fee: ${formatEther(results.fee.amount)} ETH`);
    console.log(`Estimated gas: ${results.fee.gas} GAS`);
    ```
  </Step>
</Steps>

## Additional Resources

* Check out the full example code for estimating gas for sponsored transactions [here](https://github.com/gelatodigital/smartwallet/blob/master/examples/estimates/src/index.ts).
