Gelato
  • Introduction
    • Gelato, The Web3 Cloud Platform
  • Rollup As A Service
    • Introduction
    • Rollup Stacks
      • Arbitrum Orbit
        • Run a Full Orbit Node
      • OP Stack
        • Run OP Node
    • Deploy your Rollup
    • Customization
      • Data Availability
        • Celestia
        • Avail
        • Eigen DA
      • Custom Gas Token
      • Marketplace
        • Gelato Services
        • Data Indexers
        • Block Explorers
        • Oracles
        • Bridges
        • Account Abstraction
        • On & Off-ramp
        • Community
        • Identity & KYC
        • Others
      • Verifier Node Package
    • Public Testnet
  • RPC Nodes
    • Introduction
    • Compute Units
    • Using RPC Nodes
    • Supported Networks
    • Pricing and Plans
    • FAQ
  • Web3 Services
    • Web3 Functions
      • Understanding Web3 Functions
        • Trigger Types
        • Typescript Function
        • Solidity Function
        • Automated Transactions
      • Security Considerations
      • Template & Use Cases
      • Quick Start
        • Writing Typescript Functions
          • Event Trigger
          • Private Typescript Functions
          • Callbacks
        • Test, Deploy & Run Typescript functions
        • Writing Solidity Functions
        • Test, Deploy & Run Solidity Functions
        • Initiate an Automated Transaction
      • Create a Web3 Function Task
        • Using the UI
        • Using the Safe App
        • Using a Smart Contract
        • Using the Automate SDK
      • Analytics & Monitoring
      • Supported Networks
      • Subscription & Payments
      • Legacy Automate Migration Guide
    • Relay
      • What is Relaying?
      • Security Considerations
        • ERC-2771 Delegatecall Vulnerability
      • Templates
      • Quick Start
        • Sponsored Calls
        • Non-Sponsored Calls
      • ERC-2771 (recommended)
        • SponsoredCallERC2771
        • CallWithSyncFeeERC2771
          • Relay Context Contracts ERC2771
      • Non-ERC-2771
        • SponsoredCall
        • CallWithSyncFee
          • Relay Context Contracts
      • Relay API
      • Gelato's Fee Oracle
      • Tracking your Relay Request
      • Supported Networks
      • Subscriptions and Payments
        • 1Balance & Relay
        • SyncFee Payment Tokens
        • Relay Pricing
      • ERC2771 Migration Guide
    • VRF
      • Understanding VRF
      • How does Gelato VRF Work?
      • Security Considerations
      • Template
      • Quick Start
      • Create a VRF Task
        • Create a Fallback VRF
        • Migrating from Chainlink VRF
      • Supported Networks
      • Pricing & Rate Limits
    • Oracles
      • Understanding Gelato Oracles
      • Quick Start
      • Data Providers
        • Stork
        • Choas Labs
      • Migrating from Chainlink Oracles
      • Available Price Feeds
      • Supported Networks
      • Pricing & Rate Limits
    • Account Abstraction
      • Understanding ERC4337
      • Introduction to Gelato Bundler
      • Templates & Examples
      • Quick Start
      • Sponsored UserOps
        • Using 1Balance
        • Using Zerodev Paymaster
      • Non-Sponsored UserOps
        • Pay with Native
        • Pay with ERC20
      • Supported Networks
      • Bundler API Endpoints
        • eth_sendUserOperation
        • eth_estimateUserOperationGas
        • eth_getUserOperationByHash
        • eth_getUserOperationReceipt
        • eth_supportedEntryPoints
        • eth_maxPriorityFeePerGas
        • eth_chainId
    • 1Balance
      • 1Balance Alerts
      • Subscription Plans
      • Subscription Notifications
      • USDC Addresses
    • AI Agents
    • Teams
  • GELATO DAO
    • DAO & Token (GEL)
    • GEL Token Contracts
    • Governance Process
  • Social Media
Powered by GitBook
On this page
  • Initial Setup
  • 1. Create Your ZeroDev Account
  • 2. Create a Project for a Specific Network
  • 3. Retrieve the Paymaster URL
  • Example Code
  • 1. Create an account using createKernelAccount from @zerodev/sdk
  • 2. Create paymaster client using createZeroDevPaymasterClient
  • 3. Create an Client using createKernelAccountClient adding Gelato Bundler RPC with Zerodev paymaster
  • 4. Send UserOperation using kernelClient
  • 5. Check UserOp status using Relay API
  1. Web3 Services
  2. Account Abstraction
  3. Non-Sponsored UserOps

Pay with ERC20

This page details the process of paying the gas of user operations (UserOps) using ERC20 tokens.

PreviousPay with NativeNextSupported Networks

Last updated 2 months ago

ERC20 token payments are currently restricted to testnets as part of our staging environment. For this functionality, please use staging Gelato Bundler RPC as bundler transport.

Zerodev ERC20 Paymaster currently supports USDC on Ethereum Mainnet, Polygon, Base, Optimism, and Arbitrum networks, including both their mainnet and testnet environments. Learn .

After reading this page:

  • You'll know how to pay gas for UserOps using ERC20 tokens.

  • You'll learn about how to use Zerodev Kernel and Safe as an smart account to pay gas.

  • You'll see some code which will help you send a Non-Sponsored UserOp within minutes.

Initial Setup

1. Create Your ZeroDev Account

Register on the to access the tools necessary for managing and sponsoring gas fees in your projects.

2. Create a Project for a Specific Network

After signing in, create a new project and choose the network you plan to operate on (e.g., Ethereum, Polygon). This ensures that all settings and configurations match your target chain.

3. Retrieve the Paymaster URL

Example Code

1. Create an account using createKernelAccount from @zerodev/sdk

const entryPoint = getEntryPoint("0.7");
const kernelVersion = KERNEL_V3_1;

const ecdsaValidator = await signerToEcdsaValidator(publicClient, {
    signer,
    entryPoint,
    kernelVersion,
});

const account = await createKernelAccount(publicClient, {
    plugins: {
      sudo: ecdsaValidator,
    },
    entryPoint,
    kernelVersion
});

2. Create paymaster client using createZeroDevPaymasterClient

const zerodevPaymaster = createZeroDevPaymasterClient({
    chain: baseSepolia,
    transport: http(PAYMASTER_RPC), // from Zerodev Dashboard
});

3. Create an Client using createKernelAccountClient adding Gelato Bundler RPC with Zerodev paymaster

When using the Gelato Bundler with a ZeroDev Paymaster, you need to specify a specialized gas estimation method when creating the kernelClient. The Paymaster, along with its paymasterContext, is required for paying gas in ERC20 tokens—be sure to include the specific token address in the paymasterContext.

const gasPrices = await bundlerClient.request<EthGetUserOperationGasPriceRpc>({
            method: "eth_getUserOperationGasPrice",
            params: [],
});
const maxFeePerGas = BigInt(gasPrices.maxFeePerGas),
const maxPriorityFeePerGas = BigInt(gasPrices.maxPriorityFeePerGas),
const kernelClient = createKernelAccountClient({
    account,
    chain,
    bundlerTransport: http(process.env.BUNDLER_RPC),
    paymaster: paymasterClient,
    paymasterContext: {
      token: gasTokenAddresses[sepolia.id]["USDC"], // Setting ERC-20 token for gas fees
    },
    // Custom gas estimation for integrating Gelato Bundler with the ZeroDev SDK
    userOperation: {
      estimateFeesPerGas: async ({ bundlerClient }) => {
        const gasPrices =
          await bundlerClient.request<EthGetUserOperationGasPriceRpc>({
            method: "eth_getUserOperationGasPrice",
            params: [],
          });
        return {
          maxFeePerGas: BigInt(gasPrices.maxFeePerGas),
          maxPriorityFeePerGas: BigInt(gasPrices.maxPriorityFeePerGas),
        };
      },
    },
  });

Gas Config Types

type GasPrices = {
  maxFeePerGas: string;
  maxPriorityFeePerGas: string;
};

type EthGetUserOperationGasPriceRpc = {
  ReturnType: GasPrices;
  Parameters: [];
};

4. Send UserOperation using kernelClient

You should encode your initial transaction to include an approval of the required amount of ERC20 tokens for the paymaster client.

console.log("Preparing calldata");
const callData = await account.encodeCalls([
      // Approving the paymaster to use ERC-20 tokens for gas
      await getERC20PaymasterApproveCall(paymasterClient, {
        gasToken: gasTokenAddresses[sepolia.id]["USDC"],
        approveAmount: parseEther("1"),
        entryPoint,
      }),
      {
        to: zeroAddress, // Dummy call (replace with actual transaction details)
        value: BigInt(0),
        data: "0x",
      },
]),

console.log("Sending user operation...");
const userOpHash = await kernelClient.sendUserOperation({ callData });
console.log("UserOp taskId:", userOpHash);

5. Check UserOp status using Relay API

Within your project’s dashboard, locate and copy the Paymaster URL. This endpoint is essential for integrating the sponsorship service into your application. If you want custom ERC20 tokens for gas fees checkout .

The userOpHash, when using the Gelato Bundler, is equivalent to the Task ID. This Task ID can be easily debugged through the Relay API, providing a streamlined method for troubleshooting and monitoring the status of transactions. Checkout .

Explore the complete example code that demonstrates how to sponsor UserOps using Zerodev Paymaster with the ZeroDev Kernel , as well as how to integrate with a Safe account .

here
here
here
here
more
ZeroDev dashboard