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

@habsyr/gas-price-utils

v0.1.1

Published

Utility functions for fetching current Ethereum gas prices and performing conversions.

Downloads

3

Readme

Gas Price Utilities

Simple functions for fetching current reasonable gas prices from the ETH Gas Station API.

See docs/ for full documentation.

Index

Listed below are all exports from this package and links to their documentation.

Usage

Install

# with yarn
yarn add @habsyr/gas-price-utils

# with npm
npm i --save @habsyr/gas-price-utils

Add to your project

  • ES6 and TypeScript:
    import {
        ETH_GAS_STATION_API_URL,
        ETH_GAS_STATION_PRIORITIES,
    
        fetchGasPriceData,
        fetchGasPriceInWei,
    
        gasStationUnitsToGwei,
        gweiToWei,
        weiToGwei,
    } from "@habsyr/gas-price-utils";
  • CommonJS and ES5, etc:
    const {
        ETH_GAS_STATION_API_URL,
        ETH_GAS_STATION_PRIORITIES,
    
        fetchGasPriceData,
        fetchGasPriceInWei,
      
        gasStationUnitsToGwei,
        gweiToWei,
        weiToGwei,
    } = require("@habsyr/gas-price-utils");

Functions

Primary exports of this package (see the docs/ folder for documentation for all exports) used to fetch gas price data from the ETH Gas Station API and perform conversions.

fetchGasPriceData

fetchGasPriceData(): Promise‹EthGasStationApiResponse

Defined in utils.ts:44

Fetch the current gas price data from ETH Gas Station.

This function returns the object directly from the API, in the format described in their official docs.

Returns: Promise‹EthGasStationApiResponse

A promise that resolves to the raw ETH gas station API data.


fetchGasPriceInWei

fetchGasPriceInWei(priority: GasPriority): Promise‹BigNumber›

Defined in utils.ts:27

Fetch a current gas price from ETH Gas Station in base units for a given priority.

This function returns a BigNumber with the gas price corresponding to the specified priority level in ETH base units (wei).

To use gwei value, convert with the weiToGwei method.

Parameters:

Name | Type | Default | ------ | ------ | ------ | priority | GasPriority | "fast" |

Returns: Promise‹BigNumber›

A promise that resolves to a BigNumber with gas price in wei.


gasStationUnitsToGwei

gasStationUnitsToGwei(fromValue: string | number | BigNumber): BigNumber

Defined in utils.ts:84

Convert a value in the units used by ETH Gas Station (gwei times 10) to the more common gwei (1e9 wei) unit.

Parameters:

Name | Type | Description | ------ | ------ | ------ | fromValue | string | number | BigNumber | The value from ETH Gas Station API to convert. |

Returns: BigNumber

The same value as a BigNumber in units of gwei (1e9 wei).


gweiToWei

gweiToWei(gweiValue: string | number | BigNumber): BigNumber

Defined in utils.ts:59

Convert a value in gwei (1e9 wei) units to wei (base units).

Parameters:

Name | Type | Description | ------ | ------ | ------ | gweiValue | string | number | BigNumber | A positive gwei value as a string, number or BigNumber. |

Returns: BigNumber

The value in wei as a BigNumber.


weiToGwei

weiToGwei(weiValue: string | number | BigNumber): BigNumber

Defined in utils.ts:71

Convert a value in wei (base units) to gwei (1e9 wei).

Parameters:

Name | Type | Description | ------ | ------ | ------ | weiValue | string | number | BigNumber | A positive wei value as a string, number or BigNumber. |

Returns: BigNumber

The value in wei as a BigNumber.