A paymaster kit is a code module that lets your application pay gas fees on behalf of users. In the ERC-4337 ecosystem, it acts as a sponsor, not a bank. Users keep their assets; the paymaster simply covers the transaction costs to make the experience frictionless.
When a user interacts with a smart account, the paymaster kit intercepts the operation. It verifies the request, covers the gas cost, and submits the transaction to the bundler. This allows users to pay fees in ERC-20 tokens like USDC instead of holding native tokens like ETH.
1
User initiates a transaction
The user signs a user operation (UserOp) through their smart account, requesting a specific action on the dApp.
2
Paymaster kit validates
The paymaster kit checks if the request meets your sponsorship rules, such as valid signatures or token balances.
3
Kit pays the gas
The paymaster submits the UserOp to the mempool, covering the gas fees so the user pays nothing upfront.
This separation of duties is critical. The paymaster kit handles the logistics of gas payment, while the smart account handles the authorization. This architecture enables gasless onboarding and token-based fee payments without exposing private keys to third parties.
Choose your sponsorship model
Deciding between full gas sponsorship and ERC-20 fee payment sets the foundation for your paymaster kit. This choice dictates how you configure your smart contracts, manage user onboarding, and handle backend costs. Alchemy defines ERC-4337 paymasters as tools that enable dapps to sponsor user operations or allow users to pay for gas in ERC-20 tokens and stablecoins.
Full Gas Sponsorship
With full sponsorship, your platform covers all gas costs for the user. This approach removes friction during onboarding, making it ideal for first-time users or high-value actions where you want to eliminate hesitation. You pay the network fees directly, which simplifies the user experience but requires your backend to manage fiat-to-crypto conversions and maintain a gas reserve.
ERC-20 Fee Payment
ERC-20 payment allows users to pay transaction fees using their own token balance, such as USDC or DAI. This model shifts the cost burden to the user, reducing your operational expenses while keeping them within the ecosystem. Users must hold the specific supported token, which adds a layer of complexity but ensures you are not subsidizing every transaction.
Comparison of Models
Use this comparison to evaluate which model fits your specific use case.
Feature
Full Sponsorship
ERC-20 Payment
Gas Cost
Paid by platform
Paid by user
User Friction
Low (no token needed)
Medium (needs token balance)
Implementation
Simple backend logic
Requires token approval flow
Best For
Onboarding & marketing
Established user bases
Implementation Considerations
Your choice impacts the complexity of your paymaster contract. Full sponsorship requires robust monitoring of gas prices and budget limits to prevent abuse. ERC-20 payment requires handling token approvals and ensuring the user has sufficient balance before signing. Both models can be combined in a single kit to offer flexibility, allowing users to choose their preferred payment method at runtime.
As an Amazon Associate, we may earn from qualifying purchases.
Integrate the paymaster kit
This section guides you through connecting your backend infrastructure to a smart account provider. We will use the Safe Protocol Kit as the reference implementation, as it provides a robust abstraction for ERC-4337 account factories and bundlers. You can adapt these steps to other providers like MetaMask Smart Accounts by swapping the specific SDK imports, but the configuration logic remains identical.
1
Install the required SDKs
Begin by installing the core packages in your project directory. You need the Safe Provider SDK to manage the smart account instance and the Paymaster SDK to handle sponsorship logic. For a TypeScript environment, run the following command to add the necessary dependencies:
Ensure your project is configured to target ES2020 or higher, as the SDK relies on modern JavaScript features like BigInt and optional chaining. Verify the installation by importing the SafeProvider in a test file to catch any version mismatches early.
2
Configure the Safe Provider
Initialize the provider with your RPC endpoint and the Safe singleton address. The provider acts as the bridge between your application and the blockchain, handling signature aggregation and transaction execution. Create a configuration object that includes the chain ID and the specific Safe version you intend to support.
This step establishes the read-only connection to the network. You will later attach a signer to this provider to execute transactions on behalf of the user.
3
Deploy the Paymaster contract
You must deploy a custom Paymaster contract to your target chain. This contract holds the funds (ETH or ERC-20 tokens) used to sponsor user transactions. Use Hardhat or Foundry to compile and deploy the contract, ensuring you have sufficient native token balance in the deployed address.
For ERC-20 sponsorship, the contract must approve the bundler to spend your tokens. After deployment, record the contract address and the ABI for use in the next step. Do not use testnet tokens for production integration; verify the contract interaction on a block explorer first.
4
Link the Paymaster to the Safe Account
Connect the deployed Paymaster contract to your Safe Protocol Kit instance. This configuration tells the smart account which Paymaster to call during transaction execution. You must pass the Paymaster address and the specific mode (e.g., StakeAware or ERC20) to the kit configuration.
Once linked, the Safe Kit will automatically include the Paymaster data in the user’s transaction request. Test this connection by attempting a small transaction; if successful, the gas fees will be deducted from your Paymaster contract, not the user’s wallet.
Yes. MetaMask supports ERC-4337 paymasters. You will need to use the MetaMask SDK to initialize the smart account and configure the paymaster address in the user session options.
The transaction will fail with a 'Paymaster deposit exceeded' error. You must monitor your Paymaster contract balance and refill it automatically using a backend script or a dedicated funding service.
Fund and test the paymaster
Before deploying to mainnet, you must ensure the paymaster contract holds sufficient funds to cover user operations and that it correctly processes them on a testnet. This section walks you through funding the contract and verifying sponsorship logic using the eth_sendUserOperation flow.
1
Fund the paymaster contract
Transfer native testnet tokens (ETH on Sepolia or Holesky) directly to your paymaster contract address. Most ERC-4337 paymasters require a minimum balance to initiate sponsorship. If your paymaster supports ERC-20 gas payments, you must also approve and transfer the specific token (e.g., USDC) to the contract. Use a faucet for testnet ETH or bridge funds from your development wallet. Verify the balance using a block explorer or a simple balanceOf call if your contract implements it.
2
Verify contract balance
Confirm that the contract holds enough funds to cover the estimated gas cost of a typical user operation. A single user operation on Sepolia typically costs less than $0.01 in gas, but you should fund the contract with at least 0.01–0.05 ETH to allow for multiple test transactions. If your paymaster uses a strict balance check, an insufficient balance will cause the user operation to fail with a PaymasterAndData error.
3
Test user operations on testnet
Use a bundler (such as the Alchemy Bundler or a local node) to submit a test user operation via eth_sendUserOperation. Ensure the paymasterAndData field is correctly encoded with your contract address and any necessary sponsorship parameters. Monitor the transaction in the bundler’s response and on a block explorer. A successful sponsorship will show the gas fees paid by the paymaster contract rather than the user’s wallet.
4
Confirm gas refund logic
If your paymaster charges users in ERC-20 tokens or implements a post-operation refund mechanism, verify that the balance changes are correct. Check the user’s token balance and the paymaster’s token balance before and after the transaction. Ensure that the gas refund logic does not leave the contract in a state where it cannot cover future operations.
5
Review bundler and node logs
Check the bundler and node logs for any errors or warnings related to the paymaster. Look for UserOperation reverted messages that indicate the paymaster rejected the operation due to invalid signatures, insufficient funds, or failed validation. Resolve any issues before proceeding to mainnet deployment.
A paymaster is someone appointed by a group of buyers, sellers, investors or lenders to receive, hold, and dispense funds, commissions, fees, salaries (remuneration) or other trade, loan, or sales proceeds within the private sector or public sector.
The Paymaster ensures due diligence, ensures the transaction is legitimate, and makes sure to carry out the transaction safely and effectively. A Paymaster is often an attorney because attorneys have the ability to use an Attorney Trust Account, also known as “IOLTA Trust Account.”
Paymasters need not be attorneys. Nevertheless, attorneys frequently serve in the role of Paymaster because they use an attorney trust account or a dedicated fiduciary account to receive and to manage transaction funds.
Frequently asked: what to check next
Confirm compatibility, account access, power, network, firmware, and the official app or control path before changing settings. Most setup failures start with one missing prerequisite.
Test it from every path you expect to use: the physical device, the app, and any automation or connected service. A setup is not finished until the real daily workflow works.
Undo the last change, restart the smallest affected piece, and retry once. If the same step still fails, save the exact error and move to official support or a known troubleshooting path.
No comments yet. Be the first to share your thoughts!