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 paying gas fees with native tokens using Viem in ERC-4337 Standard, 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 Bundler Client
Create a
BundlerClient
with the account and publicClient and pass the apiKey
as query parameter to the transport option. Learn more about Bundler Client here.5
Send a UserOperation
Send a
UserOperation
with the bundlerClient
and the account
.Using Bundler API Endpoints
This is the standard method where users pay gas fees directly using their native tokens (like ETH, MATIC, etc.). To use this method, follow these steps:1
Create a API Key
Check out our How-To Guide for detailed instructions on generating a API key.
2
Keep Paymaster Fields Empty
Do not include any paymaster-related fields in the UserOperation parameters. This ensures the transaction is treated as a self-sponsored native token payment.
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
can be fetched frometh_estimateUserOperationGas
API Endpoint.
Check out the required parameters for paying gas with native tokens in the following scenarios: