Best Practices/Recommendations:
- We recommend users to rely on the exact values returned by the
eth_getUserOperationGasPriceendpoint rather than applying buffers, as the values provided by our bundler are designed to handle gas price volatility effectively. - In case you want to estimate gas cost with some state overrides such as balance, code, etc., you can check our state override section.
eth_estimateUserOperationGas endpoint with our bundler:
- Using Viem - Recommended for developers using the Viem library
- Using Bundler API Endpoints - Use this approach if you have all your user operation values ready for estimation
Using Viem
To start estimating gas 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 Bundler Client
Create a
BundlerClient with the account and publicClient and pass the apiKey and sponsored set to true as query parameter to the transport option.If using other payment methods, set sponsored to false or omit it. Learn more about Bundler Client here.5
Estimate Gas
Estimate gas for a
UserOperation with the bundlerClient and the account.In case of sponsorship with Gas Tank, eth_getUserOperationGasPrice endpoint will return maxFeePerGas and maxPriorityFeePerGas as 0.Using Bundler API Endpoints
To start estimating gas directly with Bundler API Endpoints, follow these steps:1
Create a API Key
Check out our How-To Guide for detailed instructions on generating a API key.
2
Set `sponsored` query parameter to `true`
When calling Gelato API endpoints, make sure to include the
apiKey and sponsored set to true as a query parameter.Your Bundler URL will look like this:3
Configure the UserOperation Parameters
- Set
maxFeePerGasandmaxPriorityFeePerGasto0(0x0). - Leave all paymaster-related fields empty (i.e
paymaster,paymasterData,paymasterPostOpGasLimit,paymasterVerificationGasLimit).
Check out the required parameters for estimating gas in the following scenarios: