• Creates a gas estimator instance appropriate for the specified chain. Automatically selects the correct estimator implementation based on the chain type (e.g., Optimism, Arbitrum, Mantle, or standard EVM).

    Parameters

    • options: CreateGasEstimatorOptions

      Configuration options for the gas estimator

      Options for creating a gas estimator instance.

      • Optionalchain?: {
            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;
            };
        }

        Optional chain configuration to override defaults

      • chainId: number

        Chain ID of the target network

      • rpc: string | GasEstimatorRpcClient

        RPC endpoint URL or client instance

    Returns GasEstimator

    An instance of GasEstimator appropriate for the chain

    Error if the chain configuration is invalid

    // Using RPC URL
    const estimator = createGasEstimator({
    chainId: 1,
    rpc: "https://eth-mainnet.g.alchemy.com/v2/YOUR-API-KEY"
    });

    // Using custom chain config
    const estimator = createGasEstimator({
    chainId: 10,
    chain: {
    name: "Optimism",
    stack: ChainStack.Optimism,
    // ... other chain properties
    },
    rpc: rpcClient
    });