npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

entry-point-gas-estimations

v1.0.2

Published

A package to estimate callGasLimit, verificationGasLimit and preVerificationGas for a given userOperation.

Downloads

209

Readme

entry-point-gas-estimations

A package to estimate callGasLimit, verificationGasLimit and preVerificationGas for a given userOperation.

Installation

First, install the required packages for initializing the gas estimator client


npm i entry-point-gas-estimations

yarn add entry-point-gas-estimations

Integration

import { createGasEstimator } from "entry-point-gas-estimations";

// Creating a general gas estimator client
const gasEstimator = createGasEstimator({
  rpcUrl,
});

// L2s have a different way of calculating the preVerificationGas
// which requires creating network-specific gas estimator clients

// Optimism Stack Networks
const optimismGasEstimator = createOptimismGasEstimator({
  rpcUrl,
});

// Arbitrum Networks
const arbitrumGasEstimator = createArbitrumGasEstimator({
  rpcUrl,
});

// Mantle Networks
const mantleGasEstimator = createMantleGasEstimator({
  rpcUrl,
});

// Scroll Networks
const scrollGasEstimator = createScrollGasEstimator({
  rpcUrl,
});

// Morph Networks
const morphGasEstimator = createMorphGasEstimator({
  rpcUrl,
});

Parameters

  • rpcUrl(string, required): RPC Url of the network

returns

Methods

estimateUserOperationGas

This method is used to estimate gas for the userOp. It returns estimates for preVerificationGas, verificationGasLimit, and callGasLimit for a given UserOperation. It requires passing a semi-valid/ dummy signature in userOp (e.g. a signature of the correct length and format).

Usage

const estimateUserOperationGasResponse: EstimateUserOperationGas = await gasEstimator.estimateUserOperationGas({
  userOperation,
  supportsEthCallStateOverride,
  supportsEthCallByteCodeOverride,
  stateOverrideSet
  baseFeePerGas
});

Parameters

  • userOperation(UserOperation, required): userOperation to calculate gas estimates for.
  • stateOverrideSet(StateOverrideSet): optional state override set for estimating gas for a userOperation under different blockchain states.
  • supportsEthCallStateOverride (boolean): optional param, default set to true, set to false if eth_call does not support state overrides
  • supportsEthCallByteCodeOverride (boolean): optional param, default set to true, set to false if eth_call does not give correct response to bytecode overrides
  • baseFeePerGas (bigint): optional param, but required for Optimism based networks

returns

  • estimateUserOperationGasResponse(Promise<EstimateUserOperationGas>): It returns an object containing the following gas limits.

    type EstimateUserOperationGas = {
      callGasLimit: bigint;
      verificationGasLimit: bigint;
      preVerificationGas: bigint;
      validAfter: number;
      validUntil: number;
    };

estimateVerificationGasLimit

This method is used to estimate the verificationGasLimit for a given userOperation.

Usage

const verificationGasLimitResponse: EstimateVerificationGasLimit =
  await gasEstimator.estimateVerificationGasLimit({
    userOperation,
    supportsEthCallStateOverride,
    supportsEthCallByteCodeOverride,
    stateOverrideSet,
  });

Parameters

  • userOperation(UserOperation, required): userOperation to calculate gas estimates for.
  • stateOverrideSet(StateOverrideSet): optional state override set for estimating gas for a userOperation under different blockchain states.
  • supportsEthCallStateOverride (boolean): optional param, default set to true, set to false if eth_call does not support state overrides
  • supportsEthCallByteCodeOverride (boolean): optional param, default set to true, set to false if eth_call does not give correct response to bytecode overrides

returns

  • verificationGasLimitResponse(Promise<EstimateVerificationGasLimit>): It returns an object containing the verificationGasLimit, validUntil and validAfter values

    type EstimateVerificationGasLimit = {
      verificationGasLimit: bigint;
      validAfter: number;
      validUntil: number;
    };

estimateCallGasLimit

This method is used to estimate the callGasLimit for a given userOperation.

Usage

const callGasLimitResponse = await gasEstimator.estimateCallGasLimit({
  userOperation,
  supportsEthCallStateOverride,
  supportsEthCallByteCodeOverride,
  stateOverrideSet,
});

Parameters

  • userOperation(UserOperation, required): userOperation to calculate gas estimates for.
  • stateOverrideSet(StateOverrideSet): optional state override set for estimating gas for a userOperation under different blockchain states.
  • supportsEthCallStateOverride (boolean): optional param, default set to true, set to false if eth_call does not support state overrides
  • supportsEthCallByteCodeOverride (boolean): optional param, default set to true, set to false if eth_call does not give correct response to bytecode overrides

returns

  • callGasLimitResponse(Promise<EstimateCallGasLimit>): It returns an object containing the callGasLimit value

    type EstimateCallGasLimit = {
      callGasLimit: bigint;
    };

calculatePreVerificationGas

This method is used to estimate the preVerificationGas for a given userOperation. The exact implementation of this method is network dependent hence make sure to use network specefic gas estimator clients

Usage

const preVerficationGasResponse =
  await gasEstimator.calculatePreVerificationGas({
    userOperation,
    baseFeePerGas,
  });

Parameters

  • userOperation(UserOperation, required): userOperation to calculate gas estimates for.
  • baseFeePerGas (bigint): optional param, but required for Optimism based networks

returns

  • preVerificationGasResponse(Promise<CalculatePreVerificationGas>) : It returns an object containing the preVerficationGas value

    type CalculatePreVerificationGas = {
      preVerificationGas: bigint;
    };