How to Estimate the Gas Limits for a User Operation
To estimate the gas limits for a user operation, you need to use your Pimlico API key and make a JSON-RPC request as follows:
import { ethers } from "ethers"
const pimlicoApiKey = "YOUR_PIMLICO_API_KEY_HERE"
const chain = "sepolia" // find the list of supported chains at https://docs.pimlico.io/reference/bundler
const pimlicoEndpoint = `https://api.pimlico.io/v1/${chain}/rpc?apikey=${pimlicoApiKey}`
const userOperation = ...
const entryPoint = "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789"
const pimlicoProvider = new ethers.providers.StaticJsonRpcProvider(pimlicoEndpoint)
const estimationResult = await pimlicoProvider.send(
"eth_estimateUserOperationGas",
[userOperation, entryPoint]
)
const preVerificationGas = estimationResult.preVerificationGas
const verificationGasLimit = estimationResult.verificationGasLimit
const callGasLimit = estimationResult.callGasLimit