Best Practices/Recommendations:
- We recommend users to rely on the exact values returned by the
eth_getUserOperationGasPrice
endpoint rather than applying buffers, as the values provided by our bundler are designed to handle gas price volatility effectively. - When sending multiple UserOps back-to-back, querying the nonce from different providers may cause inconsistencies and stale nonces. For high-throughput use cases, we recommend:
- Using parallel nonces so ordering doesn’t matter.
- Managing nonces internally (query once, then increment locally for subsequent UserOps).
Using Viem
To start sponsoring transactions or paying gas fees with ERC-20 tokens with onchain paymasters using Viem, follow these steps:1
Create a API Key
Check out our How-To Guide for detailed instructions on generating a API key.
2
Import Dependencies
3
Setup Smart Account
Any smart account that implements viem’s
Account
type can be used here.
Check out other available smart accounts here.4
Create a Paymaster Client
Create a
PaymasterClient
with Paymaster URL. Learn more about Paymaster Client here.5
Create a Bundler Client
Create a
BundlerClient
with the account, paymasterClient and publicClient and pass the apiKey
as query parameter to the transport option. Learn more about Bundler Client here.6
Send a UserOperation
Send a
UserOperation
with the bundlerClient
and the account
.Using Bundler API Endpoints
This is the standard method of sponsoring gas or paying gas fees with ERC-20 tokens using onchain paymasters. To use features like gas sponsorship, ERC-20 token payments, or other custom payment methods via onchain paymasters, follow these steps:1
Create a API Key
Check out our How-To Guide for detailed instructions on generating a API key.
2
Include Paymaster Fields
You must pass all required paymaster-related fields such as
paymaster
, paymasterData
etc. along with the standard UserOperation parameters.3
Set `sponsored` query parameter to `false` or don't include it
When calling Gelato API endpoints, make sure to include the
apiKey
and sponsored
set to false
as a query parameter.Your Bundler URL will look like this:4
Fetch Gas Parameters from Gelato APIs
Use the following endpoints to retrieve gas-related values:
maxFeePerGas
andmaxPriorityFeePerGas
can be fetched frometh_getUserOperationGasPrice
API Endpoint.callGasLimit
,verificationGasLimit
,preVerificationGas
&paymasterVerificationGasLimit
can be fetched frometh_estimateUserOperationGas
API Endpoint.
Check out the required parameters for on-chain paymasters in the following scenarios:
- Sponsored gas payments
- ERC-20 gas payments