Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

EVM Paymaster

The Openfort EVM Paymaster enables you to sponsor gas fees for your users' transactions on EVM-compatible chains. By integrating with the Openfort Paymaster, you can provide seamless, gasless experiences where users don't need to hold native tokens to interact with your application.

Overview

A Paymaster works by:

  1. Receiving a UserOperation from your application
  2. Validating it against your sponsorship rules
  3. Signing the operation with the paymaster's key
  4. Returning the signature for inclusion in the UserOperation

When the UserOperation is executed on-chain, the paymaster contract verifies the signature and pays for the gas on behalf of the user.

Getting Started

To use the Paymaster, make JSON-RPC requests to:

https://api.openfort.io/rpc/{chainId}

Replace {chainId} with the appropriate chain ID. Include your Openfort publishable key in the Authorization header:

Authorization: Bearer YOUR_OPENFORT_PUBLISHABLE_KEY

Get your public key from the Openfort Dashboard.

Available Endpoints

MethodDescription
pm_sponsorUserOperationSponsor a UserOperation
pm_validateSponsorshipPoliciesValidate against sponsorship policies
pm_supportedEntryPointsList supported EntryPoints

Quick Example

This example shows how to use the Openfort Paymaster with viem's createPaymasterClient:

import { createPublicClient, http } from 'viem'
import { sepolia } from 'viem/chains'
import { privateKeyToAccount } from 'viem/accounts'
import {
  createBundlerClient,
  createPaymasterClient,
  toCoinbaseSmartAccount
} from 'viem/account-abstraction'
 
// Create a public client for reading blockchain state
const client = createPublicClient({
  chain: sepolia,
  transport: http(),
})
 
// Create the paymaster client with Openfort
const paymasterClient = createPaymasterClient({
  transport: http('https://api.openfort.io/rpc/11155111', {
    fetchOptions: {
      headers: {
        'Authorization': 'Bearer YOUR_OPENFORT_PUBLISHABLE_KEY',
      },
    },
  }),
})
 
// Create a smart account (using Coinbase Smart Account as an example)
const owner = privateKeyToAccount(process.env.PRIVATE_KEY)
const account = await toCoinbaseSmartAccount({
  client,
  owners: [owner],
  version: '1.1',
})
 
// Create a bundler client that uses the paymaster for gas sponsorship
const bundlerClient = createBundlerClient({
  account,
  paymaster: paymasterClient,
  client,
  paymasterContext: {
    policyId: 'YOUR_POLICY_ID_HERE'
  },
  transport: http('https://api.openfort.io/rpc/11155111', {
    fetchOptions: {
      headers: {
        'Authorization': 'Bearer YOUR_OPENFORT_PUBLISHABLE_KEY',
      },
    },
  }),
})
 
// Send a sponsored UserOperation
const hash = await bundlerClient.sendUserOperation({
  calls: [{
    to: '0xcb98643b8786950F0461f3B0edf99D88F274574D',
    value: 0n,
    data: '0x1234',
  }],
})
 
const receipt = await bundlerClient.waitForUserOperationReceipt({ hash })
console.log('UserOperationReceipt:', receipt)

The paymasterContext object accepts policyId to specify which sponsorship policy to use for gas sponsorship.

Sponsorship Policies

Sponsorship policies allow you to define rules for when transactions should be sponsored. You can configure policies in the Openfort Dashboard to:

  • Limit sponsorship to specific contract interactions
  • Set spending caps per user or time period
  • Restrict sponsorship to specific chains
  • Define custom criteria based on transaction parameters

Learn more about configuring Sponsor Rules.

Validity Window

Sponsored UserOperations have a 10-minute validity window during which they must be submitted to the blockchain. After this window expires, unused gas allocations are released.

This time limit prevents potential abuse scenarios where accumulated UserOperations could drain the paymaster's funds.

Next Steps

Copyright © 2023-present Alamas Labs, Inc