# Sponsoring Gas (/smart-accounts/sponsor-gas/evm)

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



When you sponsor gas through ZeroDev, there are two ways to pay for the gas:

<Cards>
  <Card icon="creditCard" title="Credit card">
    We front the gas for your users, and then at the end of the billing cycle (once a month) we charge your credit card.
  </Card>

  <Card icon="gas" title="Gas credits">
    Buy gas credits from us.
  </Card>
</Cards>

## Setting up gas sponsoring policies [#setting-up-gas-sponsoring-policies]

To avoid over-spending gas on sponsoring, you must set up gas-sponsoring policies.  Sign up on the ZeroDev dashboard if you haven't already, then [set up gas policies](/api-and-toolings/infrastructure/gas-policies).

Note that you MUST set up a gas policy to begin sponsoring.  Without setting up a gas policy, there won't be any gas sponsored.

## API [#api]

<Callout type="info">
  Impatient?  Check out [complete examples here](https://github.com/zerodevapp/zerodev-examples/blob/main/create-account/main.ts).
</Callout>

When [setting up an account](/onboarding/create-a-smart-account), you can specify a `getPaymasterData` function in `paymaster` when you [create the account client](/onboarding/create-a-smart-account#create-an-account-client).

The `getPaymasterData` function essentially takes a UserOp and then returns a UserOp with the `paymasterAndData` field set.  For example, if you are using the ZeroDev paymaster, use the `createZeroDevPaymasterClient` helper function:

```typescript
import { http } from "viem"
import { createZeroDevPaymasterClient, createKernelAccountClient } from "@zerodev/sdk"
import { getEntryPoint } from "@zerodev/sdk/constants"

const entryPoint = getEntryPoint("0.7")

const paymasterClient = createZeroDevPaymasterClient({
  chain,
  // Get this RPC from ZeroDev dashboard
  transport: http(ZERODEV_RPC),
})

const kernelClient = createKernelAccountClient({
  paymaster: {
    getPaymasterData: (userOperation) => {
      return paymasterClient.sponsorUserOperation({
        userOperation,
      })
    }
  }

  // other args...
})
```

### What happens when you reach the sponsorship limit? [#what-happens-when-you-reach-the-sponsorship-limit]

If you have reached the sponsorship limit, either because of the [policies](/api-and-toolings/infrastructure/gas-policies) you set up or because you have reached an account-level limit, sending UserOp will fail.

If, instead of failing, you want the UserOp to proceed but use the user's own native tokens (e.g. ETH), then you can set up your `paymaster` middleware like this:

```ts
import { GetPaymasterDataReturnType } from "viem/account-abstraction"

const kernelClient = createKernelAccountClient({
  // other args...

  paymaster: {
    getPaymasterData: async (userOperation) => {
      try {
        return await paymasterClient.sponsorUserOperation({ userOperation })
      } catch (error) {
        return {} as GetPaymasterDataReturnType
      }
    },
  },
})
```

## UltraRelay [#ultrarelay]

UltraRelay is a new relay solution that functions as a combination of ERC-4337 bundlers and paymasters, as a single entity.  UltraRelay is significantly more efficient than regular ERC-4337 bundlers and paymasters.  In our benchmarks, UltraRelay achieves:

* 30% less gas than ERC-4337 bundlers
* 20% lower latency than ERC-4337 bundlers

This makes UltraRelay the best solution for gas sponsorship.

### API [#api-1]

To use UltraRelay, simply update your `createKernelAccountClient` config as follows:

* Append `?provider=ULTRA_RELAY` to your ZeroDev RPC.
* (optional) Do NOT set the [paymaster middleware](#api), which will save you some latency.
* (optional) Set a no-op gas estimation middleware, which will save you even more latency.

Here's how it looks like in code:

```ts
const kernelClient = createKernelAccountClient({
  account,
  chain,
  bundlerTransport: http(ZERODEV_RPC+`?provider=ULTRA_RELAY`),
  userOperation: {
    estimateFeesPerGas: async ({ bundlerClient }) => {
      return {
        maxFeePerGas: BigInt(0),
        maxPriorityFeePerGas: BigInt(0),
      }
    },
  },
})
```

### Supported networks [#supported-networks]

UltraRelay is being gradually rolled out to all networks.  It currently supports:

* Base
* Arbitrum
* Optimism
* HyperEVM
* Polynomial
* Abstract
* ZkSync
* Base Sepolia
* Holesky

Feel free to [contact us](https://t.me/derek_chiang) if you want us to deploy UltraRelay for your network.
