estimateUserOperationGas
Estimates the total gas cost for a user operation with one or more calls. Works for both single transactions and batch transactions. The estimation includes all gas components: call gas, verification gas, and pre-verification gas.
Usage
Parameters
Returns
Promise<bigint | null> - Returns the estimated gas cost in wei, or null if estimation fails.
The gas estimate includes:
- Call Gas Limit: Gas for executing the calls
- Verification Gas Limit: Gas for validating the UserOperation
- Pre-verification Gas: Fixed gas overhead
Examples
Single transaction
Batch transaction
Estimate before sending
With contract interaction
Notes
- Gas estimation creates a kernel client without sponsorship to get accurate unsponsored gas costs
- Returns
null if estimation fails (e.g., insufficient funds, invalid call)
- Batch transactions may save gas compared to individual transactions due to shared validation costs
- The actual gas used may differ slightly from the estimate
React
Show the gas estimate to the user before they confirm the transaction:
Last modified on September 21, 2026