# Sponsor gas

> Choose a gas sponsorship integration path for your smart wallet application.

> For the complete documentation index, see [llms.txt](/docs/llms.txt).

Gas fees are a significant barrier to entry for new users. With Gas Sponsorship, you can eliminate this friction by covering transaction costs for your users.

## How it works

When you request gas sponsorship using a configured policy, the policy engine determines if that transaction is eligible for sponsorship.
If eligible, the Gas Manager pays for the gas fee upfront when the transaction is sent. The Gas Manager records the sponsored cost
and bills in fiat.

## Prerequisites

* API key from your [dashboard](https://dashboard.alchemy.com/apps)
* [A gas sponsorship policy](https://dashboard.alchemy.com/gas-manager/policy/create).

## Implementation

<Tabs>
  <Tab title="JavaScript" language="typescript">
    <Info>`@alchemy/wallet-apis` (v5.x.x) is currently in beta but is the recommended replacement for `@account-kit/wallet-client` (v4.x.x). If you run into any issues, please [reach out](mailto:support@alchemy.com).</Info>

Use the `paymaster` capability on the smart wallet client [`sendCalls`](/docs/wallets/reference/wallet-apis/functions/sendCalls) or [`prepareCalls`](/docs/wallets/reference/wallet-apis/functions/prepareCalls) actions.

<CodeBlocks>

```ts title="sendCalls.ts"
import { client, config } from "./client.ts";

try {
  // Send a sponsored transaction
  const { id } = await client.sendCalls({
    capabilities: {
      paymaster: {
        policyId: config.policyId,
      },
    },
    calls: [
      {
        to: "0x0000000000000000000000000000000000000000",
        value: BigInt(0),
        data: "0x",
      },
    ],
  });

  console.log(id);
} catch (error) {
  console.error(error);
}
```

```ts title="client.ts"
import type { Hex } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { arbitrumSepolia } from "viem/chains";
import { createSmartWalletClient, alchemyWalletTransport } from "@alchemy/wallet-apis";

export const config = {
  policyId: "YOUR_POLICY_ID",
};

export const client = createSmartWalletClient({
  transport: alchemyWalletTransport({
    apiKey: "YOUR_API_KEY",
  }),
  chain: arbitrumSepolia,
  signer: privateKeyToAccount("0xYOUR_PRIVATE_KEY" as const),
});
```

</CodeBlocks>

  </Tab>

  <Tab title="API" language="bash">
    See the [`wallet_prepareCalls` API
reference](/docs/wallets/api/smart-wallets/wallet-api-endpoints/wallet-api-endpoints/wallet-prepare-calls)
for full descriptions of the parameters used in the following example.

<Steps>
  <Step title="Prepare calls">
    Prepare calls using the `paymasterService` capability. Use your owner address directly as the `from` field to enable [EIP-7702](/docs/wallets/transactions/using-eip-7702) by default.
```bash
curl --request POST \
  --url https://api.g.alchemy.com/v2/$ALCHEMY_API_KEY \
  --header 'accept: application/json' \
  --data '
{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "wallet_prepareCalls",
  "params": [
    {
      "capabilities": {
        "paymasterService": {
          "policyId": "'$ALCHEMY_POLICY_ID'"
        }
      },
      "calls": [
        {
          "to": "0x0000000000000000000000000000000000000000"
        }
      ],
      "from": "'$SIGNER_ADDRESS'",
      "chainId": "'$CHAIN_ID_HEX'"
    }
  ]
}'
```
  </Step>
  <Step title="Sign & send">
    Sign the returned signature request and send using `wallet_sendPreparedCalls`. If the account hasn't been delegated yet, you'll also need to sign the 7702 authorization. See [Send Transactions](/docs/wallets/transactions/send-transactions) for a complete example.
  </Step>
</Steps>

  </Tab>
</Tabs>

<Accordion title="Using @account-kit/wallet-client (v4.x.x)?">
The examples on this page use `@alchemy/wallet-apis` (v5.x.x). If you're using `@account-kit/wallet-client` (v4.x.x), the client setup looks like this:

```ts title="client.ts (v4.x.x)"
import { LocalAccountSigner } from "@aa-sdk/core";
import { createSmartWalletClient } from "@account-kit/wallet-client";
import { alchemy, sepolia } from "@account-kit/infra";

const signer = LocalAccountSigner.privateKeyToAccountSigner("0xYOUR_PRIVATE_KEY" as const);

export const client = createSmartWalletClient({
  transport: alchemy({ apiKey: "YOUR_API_KEY" }),
  chain: sepolia,
  signer,
  account: signer.address, // can also be passed per action as `from` or `account`
  // Optional: sponsor gas for your users (see "Sponsor gas" guide)
  policyId: "YOUR_POLICY_ID", 
});
```

Key v4.x.x differences:
* **Account address** must be specified on the client or per action (`from` or `account`). In v5.x.x, the client automatically uses the owner's address as the account address via [EIP-7702](/docs/wallets/transactions/using-eip-7702).
* **Chain imports** come directly from `@account-kit/infra` instead of `viem/chains`.
* **Numeric values** use hex strings: `value: "0x0"` instead of `value: BigInt(0)`.
* In v4.x.x, the **paymaster capability** on `prepareCalls` or `sendCalls` is called `paymasterService` instead of `paymaster`, or you can set the `policyId` directly on the client.
* **Owners** use `LocalAccountSigner` / `WalletClientSigner` from `@aa-sdk/core`. In v5.x.x, a viem `LocalAccount` or `WalletClient` is used directly.

See the [full migration guide](/docs/wallets/resources/migration-v5) for a complete cheat sheet.
</Accordion>


## Advanced

<Accordion title="Usage with prepare calls">
  Gas sponsorship also works with the prepare calls methods in the various frameworks. Usage of the capability is the same as when using send calls. Use prepare calls if you want to inspect the prepared call before prompting for signature.

  <Tabs>
    <Tab title="JavaScript" language="typescript">
      See the [`prepareCalls` SDK reference](/docs/wallets/reference/wallet-apis/functions/prepareCalls) for full parameter descriptions.
    </Tab>

    <Tab title="API" language="bash">
      See the [`wallet_prepareCalls` API
      reference](/docs/wallets/api/smart-wallets/wallet-api-endpoints/wallet-api-endpoints/wallet-prepare-calls)
    </Tab>
  </Tabs>
</Accordion>

<Accordion title="Multiple policy IDs">
  You can configure multiple policy IDs for use in gas sponsorship. The
  backend chooses the first policy ID where the transaction is eligible
  for sponsorship. Pass an array of policy IDs instead of a
  single policy ID to the sponsor gas capability. See the [`wallet_prepareCalls`
  API
  parameters](https://www.alchemy.com/docs/wallets/api-reference/smart-wallets/wallet-api-endpoints/wallet-api-endpoints/wallet-prepare-calls)
  for reference to the `paymasterService.policyIds` parameter.
</Accordion>

## Next steps

Build more:

* [Pay gas with any token](/docs/wallets/transactions/pay-gas-with-any-token)

Troubleshooting:

* [Gas manager errors](/docs/reference/gas-manager-errors)