import { encodeFunctionData, parseAbi } from "viem";
async function estimateGas(
client: any,
operations: Array<{
target: string;
data?: string;
value?: bigint;
}>
) {
try {
const estimation = await client.estimateUserOperationGas({
uo: operations.map(op => ({
target: op.target,
data: op.data || "0x",
value: op.value || 0n
}))
});
console.log("Gas Estimation:");
console.log("- Call Gas Limit:", estimation.callGasLimit);
console.log("- Verification Gas Limit:", estimation.verificationGasLimit);
console.log("- Pre-verification Gas:", estimation.preVerificationGas);
const totalGas = BigInt(estimation.callGasLimit) +
BigInt(estimation.verificationGasLimit) +
BigInt(estimation.preVerificationGas);
console.log("Total Gas:", totalGas.toString());
return estimation;
} catch (error) {
console.error("Gas estimation failed:", error);
throw error;
}
}