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

Gas estimation helps avoid failed transactions and provides transparency into expected costs.

## Implementations

<Tabs>
  <Tab title="Gelato Gasless SDK">
    <Steps>
      <Step title="Initialize Relayer Client">
        ```typescript theme={null}
        import { createGelatoEvmRelayerClient } from '@gelatocloud/gasless';
        import { createPublicClient, encodeFunctionData, formatUnits, http } from 'viem';
        import { baseSepolia } from 'viem/chains';

        const relayer = createGelatoEvmRelayerClient({
          apiKey: process.env.GELATO_API_KEY,
          testnet: true
        });

        const publicClient = createPublicClient({
          chain: baseSepolia,
          transport: http()
        });
        ```
      </Step>

      <Step title="Estimate Gas">
        ```typescript theme={null}
        const data = encodeFunctionData({
          abi: [{ type: 'function', name: 'increment', inputs: [], outputs: [] }],
          functionName: 'increment'
        });

        const gasEstimate = await publicClient.estimateGas({
          to: '0xE27C1359cf02B49acC6474311Bd79d1f10b1f8De',
          data
        });

        console.log('Estimated gas:', gasEstimate.toString());
        ```
      </Step>

      <Step title="Get Fee Data">
        Get current gas price:

        ```typescript theme={null}
        const feeData = await relayer.getFeeData({
          chainId: baseSepolia.id
        });

        console.log('Gas Price:', feeData.gasPrice.toString(), 'wei');
        ```
      </Step>
    </Steps>
  </Tab>

  <Tab title="With 7702 Smart Account">
    <Steps>
      <Step title="Create Smart Account">
        ```typescript theme={null}
        import {
          createGelatoSmartAccountClient,
          toGelatoSmartAccount,
        } from "@gelatocloud/gasless";
        import { createPublicClient, http, type Hex, formatEther } from "viem";
        import { privateKeyToAccount } from "viem/accounts";
        import { baseSepolia } from "viem/chains";

        const owner = privateKeyToAccount(process.env.PRIVATE_KEY as Hex);

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

        const account = toGelatoSmartAccount({
          client,
          owner,
        });

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

      <Step title="Get Fee Quote">
        ```typescript theme={null}
        const quote = await relayer.getFeeQuote({
          calls: [
            {
              to: "0xE27C1359cf02B49acC6474311Bd79d1f10b1f8De",
              data: "0xd09de08a",
            },
          ],
        });

        console.log(`Estimated fee: ${formatEther(quote.estimatedFee)} ETH`);
        ```
      </Step>

      <Step title="Estimate for Multiple Transactions">
        ```typescript theme={null}
        const quote = await relayer.getFeeQuote({
          calls: [
            {
              to: "0xE27C1359cf02B49acC6474311Bd79d1f10b1f8De",
              data: "0xd09de08a",
            },
            {
              to: "0xE27C1359cf02B49acC6474311Bd79d1f10b1f8De",
              data: "0xd09de08a",
            },
          ],
        });

        console.log(`Estimated fee: ${formatEther(quote.estimatedFee)} ETH`);
        ```
      </Step>
    </Steps>
  </Tab>

  <Tab title="Relay API Endpoints">
    Pass the API key in the `X-API-Key` header.

    <Steps>
      <Step title="Estimate Gas (Chain RPC)">
        ```typescript theme={null}
        const response = await fetch('https://sepolia.base.org', {
          method: 'POST',
          headers: { 'Content-Type': 'application/json' },
          body: JSON.stringify({
            jsonrpc: '2.0',
            id: 1,
            method: 'eth_estimateGas',
            params: [{
              to: '0xE27C1359cf02B49acC6474311Bd79d1f10b1f8De',
              data: '0xd09de08a'
            }]
          })
        });

        const result = await response.json();
        const gasEstimate = parseInt(result.result, 16);
        ```
      </Step>

      <Step title="Get Fee Data">
        ```typescript theme={null}
        const response = await fetch('https://api.gelato.cloud/rpc', {
          method: 'POST',
          headers: {
            'Content-Type': 'application/json',
            'X-API-Key': process.env.GELATO_API_KEY
          },
          body: JSON.stringify({
            jsonrpc: '2.0',
            id: 1,
            method: 'relayer_getFeeData',
            params: {
              chainId: '84532'
            }
          })
        });

        const data = await response.json();
        console.log('Gas Price:', data.result.gasPrice, 'wei');
        ```
      </Step>
    </Steps>
  </Tab>
</Tabs>

## Additional Resources

* [Sponsor Gas with Gas Tank](/gasless-with-relay/how-to-guides/sponsoredcalls/overview) - Sponsored transactions
* [Supported Networks](/gasless-with-relay/additional-resources/supported-networks) - Full list of supported chains
