Simple functions for fetching current reasonable gas prices from the ETH Gas Station API.
See docs/
for full documentation.
Listed below are all exports from this package and links to their documentation.
- Async functions
fetchGasPriceData
=> Raw API data from ETH Gas Station.fetchGasPriceInWei
=> Convert ETH Gas Station data to base units by priority level.
- Sync functions
gasStationUnitsToGwei
=> Convert units used by ETH Gas Station to the more common gwei.gweiToWei
=> Convert gwei values to wei (base units).weiToGwei
=> Convert wei (base unit) values to gwei.
- Constants
ETH_GAS_STATION_API_URL
=> The ETH Gas Station API URL.ETH_GAS_STATION_PRIORITIES
=> Supported human-readable transaction priority levels.
- Types
EthGasStationApiResponse
=> Type definition for ETH Gas Station API response data.GasPriority
=> Type alias for supported priority levels (fast, average, etc).
# with yarn
yarn add @habsyr/gas-price-utils
# with npm
npm i --save @habsyr/gas-price-utils
- 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");
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(): 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(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(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(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(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.