Base implementation of gas estimation for EVM-compatible chains. Provides methods for estimating gas costs for user operations including verification, execution, and pre-verification gas.

GasEstimator

const estimator = new EVMGasEstimator(
chain,
rpcClient,
{
[EntryPointVersion.v060]: entryPointV6,
[EntryPointVersion.v070]: entryPointV7
}
);

const gasEstimate = await estimator.estimateUserOperationGas({
unEstimatedUserOperation,
baseFeePerGas: 1000000000n
});

Hierarchy (View Summary)

Implements

Constructors

  • Creates a new EVMGasEstimator instance

    Parameters

    • chain: {
          chainId: number;
          eip1559: boolean;
          entryPoints?: {
              v060?: { address: string };
              v070?: {
                  address: string;
                  state?: { deposits: Record<string, { stateKey: string }> };
              };
          };
          isTestnet: boolean;
          name: string;
          nativeCurrency?: string;
          paymasters: {
              v060?: Record<string, { dummyPaymasterAndData: string; type: string }>;
              v070?: Record<
                  string,
                  { dummyPaymasterData: string; postOpGasLimit: bigint; type: string },
              >;
          };
          simulation?: {
              callGasLimit: bigint;
              preVerificationGas: bigint;
              verificationGasLimit: bigint;
          };
          smartAccountSupport: { nexus: boolean; smartAccountsV2: boolean };
          stack: ChainStack;
          stateOverrideSupport: {
              balance: boolean;
              bytecode: boolean;
              stateDiff: boolean;
          };
      }

      The SupportedChain to estimate gas for

    • rpcClient: GasEstimatorRpcClient

      The RPC client for making blockchain requests

    • entryPoints: EntryPoints

      Map of EntryPointVersion to their contract instances

    • simulationLimits: SimulationLimits = ...

      Optional gas limits for simulation, defaults to predefined constants

    Returns EVMGasEstimator

Properties

chain: {
    chainId: number;
    eip1559: boolean;
    entryPoints?: {
        v060?: { address: string };
        v070?: {
            address: string;
            state?: { deposits: Record<string, { stateKey: string }> };
        };
    };
    isTestnet: boolean;
    name: string;
    nativeCurrency?: string;
    paymasters: {
        v060?: Record<string, { dummyPaymasterAndData: string; type: string }>;
        v070?: Record<
            string,
            { dummyPaymasterData: string; postOpGasLimit: bigint; type: string },
        >;
    };
    simulation?: {
        callGasLimit: bigint;
        preVerificationGas: bigint;
        verificationGasLimit: bigint;
    };
    smartAccountSupport: { nexus: boolean; smartAccountsV2: boolean };
    stack: ChainStack;
    stateOverrideSupport: {
        balance: boolean;
        bytecode: boolean;
        stateDiff: boolean;
    };
}

The SupportedChain to estimate gas for

entryPoints: EntryPoints

Map of EntryPointVersion to their contract instances

The RPC client for making blockchain requests

simulationLimits: SimulationLimits = ...

Optional gas limits for simulation, defaults to predefined constants

Methods

  • Estimates pre-verification gas for a user operation. Calculates gas costs for calldata and fixed overheads.

    Parameters

    Returns Promise<bigint>

    The estimated pre-verification gas as a bigint

    const preVerificationGas = await estimator.estimatePreVerificationGas(
    userOperation,
    1000000000n
    );
  • Internal

    Estimates verification and call gas limits from execution results.

    Parameters

    Returns {
        callGasLimit: bigint;
        validAfter: number;
        validUntil: number;
        verificationGasLimit: bigint;
    }

    Object containing gas limits and validity window

  • Internal

    Uses binary search to estimate gas limits for deployed accounts.

    Parameters

    • userOperation: {
          callData: `0x${string}`;
          callGasLimit: bigint;
          initCode: `0x${string}`;
          maxFeePerGas: bigint;
          maxPriorityFeePerGas: bigint;
          nonce: bigint;
          paymasterAndData: `0x${string}`;
          preVerificationGas: bigint;
          sender: `0x${string}`;
          signature: `0x${string}`;
          verificationGasLimit: bigint;
      }

      The user operation to estimate for

      • callData: `0x${string}`
      • callGasLimit: bigint

        Gas limit for the main execution call

      • initCode: `0x${string}`
      • maxFeePerGas: bigint

        Maximum total fee per gas unit

      • maxPriorityFeePerGas: bigint

        Maximum priority fee per gas unit

      • nonce: bigint

        Account nonce

      • paymasterAndData: `0x${string}`
      • preVerificationGas: bigint

        Gas overhead for pre-verification operations

      • sender: `0x${string}`
      • signature: `0x${string}`
      • verificationGasLimit: bigint

        Gas limit for the verification phase

    • baseFeePerGas: bigint

      Current base fee per gas

    • options: EstimateUserOperationGasOptions

      Estimation options

    • OptionalstateOverrides: StateOverrideSet

      Optional state overrides

    Returns Promise<EstimateUserOperationGasResult>

    Gas estimation results

    Error if binary search fails