Interface for gas estimation implementations. Provides methods for estimating gas costs for user operations across different chains.

class CustomGasEstimator implements GasEstimator {
chain: SupportedChain;
entryPoints: EntryPoints;
simulationLimits: SimulationLimits;

async estimateUserOperationGas(params: EstimateUserOperationGasParams) {
// Custom implementation
}

async estimatePreVerificationGas(userOperation: UserOperation) {
// Custom implementation
}
}
interface GasEstimator {
    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;
        };
    };
    entryPoints: EntryPoints;
    estimatePreVerificationGas: (
        userOperation: UserOperation,
        baseFeePerGas: bigint,
    ) => Promise<bigint>;
    estimateUserOperationGas: (
        params: EstimateUserOperationGasParams,
    ) => Promise<EstimateUserOperationGasResult>;
    simulationLimits: SimulationLimits;
}

Implemented by

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 chain configuration this estimator is for

entryPoints: EntryPoints

Map of EntryPoint contract instances by version

estimatePreVerificationGas: (
    userOperation: UserOperation,
    baseFeePerGas: bigint,
) => Promise<bigint>

Estimates pre-verification gas for a user operation. This includes costs for calldata and fixed overheads.

Type declaration

    • (userOperation: UserOperation, baseFeePerGas: bigint): Promise<bigint>
    • Parameters

      • userOperation: UserOperation

        The user operation to estimate for

      • baseFeePerGas: bigint

        Optional base fee per gas (required for some chains)

      Returns Promise<bigint>

      The estimated pre-verification gas as a bigint

const preVerificationGas = await estimator.estimatePreVerificationGas(
userOperation,
1000000000n // optional baseFeePerGas
);
estimateUserOperationGas: (
    params: EstimateUserOperationGasParams,
) => Promise<EstimateUserOperationGasResult>

Estimates all gas parameters for a user operation.

Type declaration

Error if simulation or estimation fails

const estimate = await estimator.estimateUserOperationGas({
unEstimatedUserOperation: {
sender: "0x123...",
nonce: 1n,
// ... other fields without gas parameters
},
baseFeePerGas: 1000000000n
});
simulationLimits: SimulationLimits

Gas limits used during simulation