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

# Sponsor Gas with Gas Tank

Gelato's Gas Tank is a powerful alternative to traditional onchain paymasters. It acts as a cross-chain gas tank, allowing you to sponsor gas fees across any supported EVM-compatible chain - using just a single balance.

Instead of maintaining balances on multiple chains, you only need to deposit funds in one place, and you're ready to sponsor gas anywhere.

<Tip>
  Important: When using Gelato Bundler for `Sponsoring` Transactions with `Gas
      Tank`, both `maxFeePerGas` and `maxPriorityFeePerGas` are set to `0`. This
  allows transaction fees to be accurately settled post-execution, rather than
  upfront via the EntryPoint.
</Tip>

## Implementations

<Tabs>
  <Tab title="Gelato Gasless SDK">
    <CodeGroup>
      ```bash npm theme={null}
      npm install @gelatocloud/gasless viem
      ```

      ```bash yarn theme={null}
      yarn add @gelatocloud/gasless viem
      ```

      ```bash pnpm theme={null}
      pnpm add @gelatocloud/gasless viem
      ```
    </CodeGroup>

    <Steps>
      <Step title="Create an API Key">
        Check out our [How-To Guide](/paymaster-&-bundler/how-to-guides/create-a-api-key) for detailed instructions on generating an API key.
      </Step>

      <Step title="Create Smart Account">
        ```typescript theme={null}
        import { createGelatoBundlerClient, toGelatoSmartAccount } from '@gelatocloud/gasless';
        import { createPublicClient, http } from 'viem';
        import { privateKeyToAccount } from "viem/accounts";
        import { baseSepolia } from "viem/chains";

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

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

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

      <Step title="Create Bundler Client">
        ```typescript theme={null}
        const bundler = await createGelatoBundlerClient({
          account,
          apiKey: process.env.GELATO_API_KEY,
          client,
          pollingInterval: 100
        });
        ```
      </Step>

      <Step title="Send UserOperation">
        ```typescript theme={null}
        const hash = await bundler.sendUserOperation({
          calls: [
            {
              data: '0xd09de08a',
              to: '0xE27C1359cf02B49acC6474311Bd79d1f10b1f8De'
            }
          ]
        });
        console.log(`User operation hash: ${hash}`);

        const { receipt } = await bundler.waitForUserOperationReceipt({ hash });
        console.log(`Transaction hash: ${receipt.transactionHash}`);
        ```
      </Step>
    </Steps>
  </Tab>

  <Tab title="Viem">
    <CodeGroup>
      ```bash npm theme={null}
      npm install viem
      ```

      ```bash yarn theme={null}
      yarn add viem
      ```

      ```bash pnpm theme={null}
      pnpm add viem
      ```
    </CodeGroup>

    <Steps>
      <Step title="Create an API Key">
        Check out our [How-To Guide](/paymaster-&-bundler/how-to-guides/create-a-api-key) for detailed instructions on generating an API key.
      </Step>

      <Step title="Create Bundler Client">
        Use `https://api.gelato.cloud` for both mainnets and testnets. Pass the API key in the `X-API-Key` header via `fetchOptions`.

        ```typescript theme={null}
        import { createPublicClient, http } from "viem";
        import { createBundlerClient } from "viem/account-abstraction";
        import { privateKeyToAccount } from "viem/accounts";
        import { baseSepolia } from "viem/chains";

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

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

        const bundlerClient = createBundlerClient({
          client: publicClient,
          transport: http(`https://api.gelato.cloud/rpc/84532?payment=sponsored`, {
            fetchOptions: {
              headers: {
                'X-API-Key': process.env.GELATO_API_KEY
              }
            }
          }),
        });
        ```
      </Step>

      <Step title="Send UserOperation">
        <Note>
          To use Gas Tank sponsorship efficiently, set `maxFeePerGas` and `maxPriorityFeePerGas` to `0n`. This allows transaction fees to be settled after execution via Gelato Gas Tank.
        </Note>

        ```typescript theme={null}
        const hash = await bundlerClient.sendUserOperation({
          account,
          calls: [
            {
              data: '0xd09de08a',
              to: '0xE27C1359cf02B49acC6474311Bd79d1f10b1f8De',
              value: 0n,
            }
          ],
          maxFeePerGas: 0n,
          maxPriorityFeePerGas: 0n,
        });
        console.log(`User operation hash: ${hash}`);

        const receipt = await bundlerClient.waitForUserOperationReceipt({ hash });
        console.log(`Transaction hash: ${receipt.receipt.transactionHash}`);
        ```
      </Step>
    </Steps>
  </Tab>

  <Tab title="Permissionless">
    <CodeGroup>
      ```bash npm theme={null}
      npm install permissionless viem
      ```

      ```bash yarn theme={null}
      yarn add permissionless viem
      ```

      ```bash pnpm theme={null}
      pnpm add permissionless viem
      ```
    </CodeGroup>

    <Steps>
      <Step title="Create an API Key">
        Check out our [How-To Guide](/paymaster-&-bundler/how-to-guides/create-a-api-key) for detailed instructions on generating an API key.
      </Step>

      <Step title="Create Smart Account">
        ```typescript theme={null}
        import { createSmartAccountClient } from "permissionless";
        import { createPublicClient, http } from "viem";
        import { createBundlerClient, toSoladySmartAccount } from "viem/account-abstraction";
        import { privateKeyToAccount } from "viem/accounts";
        import { baseSepolia } from "viem/chains";

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

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

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

      <Step title="Create Smart Account Client">
        Use `https://api.gelato.cloud` for both mainnets and testnets. Pass the API key in the `X-API-Key` header via `fetchOptions`.

        ```typescript theme={null}
        const smartClient = createSmartAccountClient({
          account,
          chain: baseSepolia,
          bundlerTransport: http(`https://api.gelato.cloud/rpc/84532?payment=sponsored`, {
            fetchOptions: {
              headers: {
                'X-API-Key': process.env.GELATO_API_KEY
              }
            }
          }),
        });
        ```
      </Step>

      <Step title="Send UserOperation">
        <Note>
          To use Gas Tank sponsorship efficiently, set `maxFeePerGas` and `maxPriorityFeePerGas` to `0n`. This allows transaction fees to be settled after execution via Gelato Gas Tank.
        </Note>

        ```typescript theme={null}
        const hash = await smartClient.sendUserOperation({
          account,
          calls: [
            {
              data: '0xd09de08a',
              to: '0xE27C1359cf02B49acC6474311Bd79d1f10b1f8De',
              value: 0n,
            }
          ],
          maxFeePerGas: 0n,
          maxPriorityFeePerGas: 0n,
        });
        console.log(`User operation hash: ${hash}`);

        const receipt = await smartClient.waitForUserOperationReceipt({ hash });
        console.log(`Transaction hash: ${receipt.receipt.transactionHash}`);
        ```
      </Step>
    </Steps>
  </Tab>

  <Tab title="API Endpoints">
    Use `https://api.gelato.cloud` for both mainnets and testnets. Pass the API key in the `X-API-Key` header.

    <Steps>
      <Step title="Create an API Key">
        Check out our [How-To Guide](/paymaster-&-bundler/how-to-guides/create-a-api-key) for detailed instructions on generating an API key.
      </Step>

      <Step title="Send UserOperation">
        <Note>
          To use Gas Tank sponsorship, ensure your UserOperation includes `maxFeePerGas` and `maxPriorityFeePerGas` set to `"0x0"`:

          ```json theme={null}
          {
            "sender": "0x...",
            "nonce": "0x...",
            "callData": "0x...",
            "maxFeePerGas": "0x0",
            "maxPriorityFeePerGas": "0x0",
            ...
          }
          ```
        </Note>

        ```typescript theme={null}
        const response = await fetch(
          `https://api.gelato.cloud/rpc/${chainId}?payment=sponsored`,
          {
            method: "POST",
            headers: {
              "Content-Type": "application/json",
              "X-API-Key": process.env.GELATO_API_KEY
            },
            body: JSON.stringify({
              jsonrpc: "2.0",
              method: "eth_sendUserOperation",
              params: [userOperation, entryPoint],
              id: 1,
            }),
          }
        );

        const data = await response.json();
        const userOpHash = data.result;
        ```
      </Step>

      <Step title="Estimate Gas (Optional)">
        ```typescript theme={null}
        const response = await fetch(
          `https://api.gelato.cloud/rpc/${chainId}`,
          {
            method: "POST",
            headers: {
              "Content-Type": "application/json",
              "X-API-Key": process.env.GELATO_API_KEY
            },
            body: JSON.stringify({
              jsonrpc: "2.0",
              method: "eth_estimateUserOperationGas",
              params: [userOperation, entryPoint],
              id: 1,
            }),
          }
        );

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

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

        const data = await response.json();
        const receipt = data.result;
        ```
      </Step>
    </Steps>

    ### Available Endpoints

    <Columns cols={2}>
      <Card title="eth_sendUserOperation" icon="send" href="/paymaster-&-bundler/bundler-api-endpoints/bundlers/eth_senduseroperation">
        Send a user operation to the bundler
      </Card>

      <Card title="eth_estimateUserOperationGas" icon="calculator" href="/paymaster-&-bundler/bundler-api-endpoints/bundlers/eth_estimateuseroperationgas">
        Estimate gas for a user operation
      </Card>

      <Card title="eth_getUserOperationReceipt" icon="receipt" href="/paymaster-&-bundler/bundler-api-endpoints/bundlers/eth_getuseroperationreceipt">
        Get receipt for a user operation
      </Card>

      <Card title="eth_getUserOperationByHash" icon="search" href="/paymaster-&-bundler/bundler-api-endpoints/bundlers/eth_getuseroperationbyhash">
        Get user operation by hash
      </Card>
    </Columns>
  </Tab>
</Tabs>
