The user operation to calculate prefund for
Gas limit for the main execution call
Maximum total fee per gas unit
Paymaster contract address and data, "0x" if no paymaster is used
Gas for pre-verification operations
Gas limit for the verification phase
The required prefund amount in wei as a bigint
const prefund = getRequiredPrefundV6({
paymasterAndData: "0x", // No paymaster
callGasLimit: 100000n,
verificationGasLimit: 50000n,
preVerificationGas: 21000n,
maxFeePerGas: 1000000000n
});
const prefundWithPaymaster = getRequiredPrefundV6({
paymasterAndData: "0x123...", // Using paymaster
callGasLimit: 100000n,
verificationGasLimit: 50000n,
preVerificationGas: 21000n,
maxFeePerGas: 1000000000n
}); // Will be 3x higher due to paymaster multiplier
Calculates the required prefund amount for a user operation based on its gas parameters. The prefund amount is used to ensure the account has sufficient funds to cover the operation's gas costs. For operations using a paymaster, the gas requirements are multiplied by 3 to account for potential paymaster failures and refunds.