Sponsoring Gas
With account abstraction, you can pay gas for users so they don't have to acquire native tokens in order to interact with your DApp.
When you sponsor gas through ZeroDev, there are two ways to pay for the gas:
-
Put down your 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.
-
Buy gas credits from us.
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
When setting up an account, you can specify a sponsorUserOperation
function when you create the account client.
The sponsorUserOperation
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:
import { http } from "viem"
import { ENTRYPOINT_ADDRESS_V07 } from "permissionless"
import { createZeroDevPaymasterClient, createKernelAccountClient } from "@zerodev/sdk"
const entryPoint = ENTRYPOINT_ADDRESS_V07
const kernelClient = createKernelAccountClient({
// other options...
middleware: {
sponsorUserOperation: async ({ userOperation }) => {
const zerodevPaymaster = createZeroDevPaymasterClient({
chain,
entryPoint,
// Get this RPC from ZeroDev dashboard
transport: http(PAYMASTER_RPC),
})
return zerodevPaymaster.sponsorUserOperation({
userOperation,
entryPoint,
})
}
}
})
Using other paymaster providers
If you want to use Pimlico paymasters, you can use these helper functions:
import { createPimlicoPaymasterClient } from "permissionless/clients/pimlico"
Then, simply replace createZeroDevPaymasterClient
with one of these functions, and make sure to use the corresponding paymaster RPC for these infra providers.