# Gas sponsorship

Whether you're building an app, gas sponsorship allows you to create seamless user experiences by controlling how transaction fees are handled.

## Fee sponsorship overview

A fee sponsorship is at the heart of how Openfort handles transaction fees. It serves as your control center for managing how and when your application sponsors users' gas fees.

Start by visiting the [Fee sponsorships tab](https://dashboard.openfort.io/policies) in your dashboard and clicking **Add fee sponsorship**. From there, pick a **Sponsorship mode**:

* **App pays** — your project covers gas fees so users transact for free.
* **User pays** — users pay gas in a token you choose, instead of the native gas token.

## Fee sponsorship policies

Fee sponsorship policies define when and how transactions receive gas sponsorship. Policies are enforced using the [Policy Engine](/docs/configuration/policies), which provides criteria-based controls such as:

* Restricting sponsorship to specific contract interactions or function calls
* Setting value caps and gas spending limits
* Restricting sponsored transactions to specific chains
* Filtering by recipient address (allowlist/denylist)

### Policy scopes

Fee sponsorship policies support two scopes:

| Scope | Behavior | `policyId` required? |
|-------|----------|----------------------|
| `project` | Applies to **all** transactions in the project automatically. The system discovers matching project-scoped policies in priority order. | No |
| `transaction` | Applies only when the `policyId` is explicitly passed in the request. Uses strict validation — if the policy's rules don't match, the transaction is rejected. | Yes |

:::tip
Use **project** scope for broad sponsorship rules (e.g., sponsor all transactions under 1 ETH). Use **transaction** scope when you need explicit control over which policy applies to each request.
:::

### Sponsorship operations

Fee sponsorship policies use dedicated operation names:

| Operation | Description |
|-----------|-------------|
| `sponsorEvmTransaction` | Sponsor an EVM UserOperation |
| `sponsorSolTransaction` | Sponsor a Solana transaction |

:::info
These are different from backend wallet operations (`signEvmTransaction`, `sendEvmTransaction`, etc.) which are used for [backend wallet policies](/docs/configuration/policies).
:::

Learn more about setting up [policies](/docs/configuration/policies) and [policy rules](/docs/configuration/policies/rules-reference).

## Sponsoring gas fees

When it comes to sponsoring gas fees, you have two sponsorship modes available:

* **App pays** — your project covers the cost, either with [balance credit](#pay-with-credit-card) or an [external paymaster](#using-external-paymasters).
* **User pays** — the end user covers the cost in a token you choose: an [ERC-20 token](/docs/configuration/gas-erc20) on EVM chains, or an SPL token on Solana.

:::tip\[Runnable examples]
See the complete runnable examples for [fee sponsorship](https://github.com/openfort-xyz/openfort-node/tree/main/examples/fee-sponsorship) in the Node SDK repository.
:::

### Pay with credit card

Add [balance credit](https://dashboard.openfort.io/settings/project/billing) to your account. When you choose this method, gas costs are automatically deducted from your balance as transactions occur. This is required for `livemode` operations.

## Using external paymasters

Openfort supports integration with external paymasters for custom gas sponsorship requirements.

:::info
When using an external paymaster, the only supported `strategy` is `pay_for_user`.
:::

You can set up an external paymaster either through the dashboard or via the API.

<MultiOptionDisplay
  options={[
{ id: 'api', label: 'API' },
{ id: 'dashboard', label: 'Dashboard' },
]}
/>

<span id="dashboard" className="hidden [&>*]:mb-6!">
  <div align="center">
    <img alt="Using external paymasters" src="https://www.openfort.io/images/blog/policy_addional_options_35e7b3096b.png" />
  </div>
</span>

<span id="api" className="hidden [&>*]:mb-6!">
  :::code-group

  ```bash [command-line]
  # Create the paymaster object
  curl https://api.openfort.io/v1/paymasters \
    -H "Authorization: Bearer $YOUR_SECRET_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "address": "0x7d526b7e99fbf52850a183...",
      "url": "YOUR_PAYMASTER_URL"
    }'

  # Create a fee sponsorship linking the paymaster to a policy
  curl -X POST https://api.openfort.io/v2/fee-sponsorship \
    -H "Authorization: Bearer $YOUR_SECRET_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "External Paymaster Sponsorship",
      "strategy": { "sponsorSchema": "pay_for_user" },
      "paymaster": "pay_...",
      "policyId": "ply_..."
    }'
  ```

  ```ts [server.ts]
  import Openfort from '@openfort/openfort-node';
  const openfort = new Openfort(YOUR_SECRET_KEY);

  // Create a fee sponsorship linking the paymaster to a policy
  const sponsorship = await openfort.feeSponsorship.create({
    name: 'External Paymaster Sponsorship',
    strategy: { sponsorSchema: 'pay_for_user' },
    paymaster: 'pay_...',
    policyId: 'ply_...',
  })
  ```

  :::
</span>

With these fundamentals in place, you're ready to start managing gas fees for your users.
