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
| Parameter | Type | Description |
|---|---|---|
calls | BatchCall[] | Array of calls to execute (single or multiple) |
calls[].to | Hex | The recipient address for this call |
calls[].value | bigint | The value to send in wei for this call |
calls[].data | Hex (optional) | The transaction data for this call |
walletAccount | EvmWalletAccount | The wallet account that will execute the operation |
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
nullif 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
Related functions
- sendUserOperation - Send a user operation (single or batch)
- canSponsorUserOperation - Check if operation can be sponsored
- createKernelClientForWalletAccount - Create a ZeroDev Kernel client
- isGasSponsorshipError - Check if an error is a gas sponsorship error