Api reference
Estimate Gas
Estimate gas costs for operations before execution.
Estimate gas costs for operations before execution.
Endpoint
POST /estimateGasDescription
Estimates the gas costs for operations before actually executing them. This endpoint returns the encoded UserOperation and gas estimates that can be used with the execute encoded endpoint.
Request Body
Same as Execute Operation endpoint.
Response
{
"status": 1,
"gas": 21000,
"userOps": [
{
"encodedUserOp": "0x...",
"userOpHash": "0x..."
}
],
"error": null
}Response Fields
status(integer): The status code (0 - failed, 1 - success)gas(integer): The estimated gas amountuserOps(array): Array of encoded UserOperationserror(string, nullable): Error message if estimation failed
Example Request
See Execute Operation for request examples.
Use Cases
- Gas optimization: Estimate gas before execution to optimize costs
- User experience: Show users estimated gas costs before confirming transactions
- Batch operations: Estimate gas for multiple operations
- Pre-execution validation: Verify operations will succeed before execution
Best Practices
- Always estimate first: Estimate gas before execution for better user experience
- Handle estimation failures: Check for errors in the response
- Use encoded operations: Use the encoded UserOperations from this endpoint with execute encoded
- Monitor gas trends: Track gas estimates over time for optimization
Related Endpoints
- Execute Operation - Execute operations directly
- Execute Encoded - Execute using encoded UserOperations from this endpoint
💡 Tip: Use this endpoint to get encoded UserOperations that can be executed later. This is useful for separating gas estimation from execution.