Gas Price Oracle library for Ethereum dApps
Go to file
2021-11-16 01:51:22 +10:00
.github/workflows remove tslint (using eslint now) 2020-10-19 15:02:47 +03:00
src fix: default values 2021-11-16 01:51:22 +10:00
tests fix: update oracles 2021-11-15 16:31:41 +10:00
.editiorconfig init 2020-05-27 18:52:57 +03:00
.eslintrc.js remove tslint (using eslint now) 2020-10-19 15:02:47 +03:00
.gitignore init 2020-05-27 18:52:57 +03:00
.prettierrc remove tslint (using eslint now) 2020-10-19 15:02:47 +03:00
LICENSE Create LICENSE 2020-06-03 14:11:01 -07:00
package.json fix: default values 2021-11-16 01:51:22 +10:00
README.md fix: update oracles 2021-11-15 16:31:41 +10:00
tsconfig.json remove tslint (using eslint now) 2020-10-19 15:02:47 +03:00
yarn.lock Bump axios from 0.19.2 to 0.21.2 2021-11-15 16:38:05 +10:00

Gas Price Oracle library for Ethereum dApps GitHub Workflow Status npm

A library that has a collection of onchain and offchain gas price oracle URLs

Supported networks

Ethereum Mainnet

Current offchain list:

Current onchain list:

Binance Smart Chain

Current offchain list:

xDAI Chain

Current offchain list:

Polygon (Matic) Network

Current offchain list:

Arbitrum One

Current offchain list:

Avalanche Mainnet

Current offchain list:

Installation

npm i gas-price-oracle

Import

const { GasPriceOracle } = require('gas-price-oracle');

Usage

Basic

const options = {
  chainId: 1,
  defaultRpc: 'https://api.mycryptoapi.com/eth',
  timeout: 10000,
  defaultFallbackGasPrices: {
    instant: 28,
    fast: 22,
    standard: 17,
    low: 11,
  },
};
const oracle = new GasPriceOracle(options);
// optional fallbackGasPrices
const fallbackGasPrices = {
  instant: 70,
  fast: 31,
  standard: 20,
  low: 7,
};
oracle.gasPrices(fallbackGasPrices).then(gasPrices => {
  console.log(gasPrices); // { instant: 50, fast: 21, standard: 10, low: 3 }
});

The gasPrices method also accepts median argument (true) by default. For more details see below. Under the hood it's a combination of fetchMedianGasPriceOffChain(fetchGasPricesOffChain) and fetchGasPricesOnChain methods.

Offchain oracles only

const oracle = new GasPriceOracle();

oracle.fetchGasPricesOffChain().then(gasPrices => {
  console.log(gasPrices); // { instant: 50, fast: 21, standard: 10, low: 3 }
});

Offchain oracles only (get median price)

const oracle = new GasPriceOracle();

oracle.fetchMedianGasPriceOffChain().then(gasPrices => {
  console.log(gasPrices); // { instant: 50, fast: 21, standard: 10, low: 3 }
});

it returns the median gas price of all the oracles configured.

Custom RPC URL for onchain oracles

const defaultRpc = 'https://mainnet.infura.io/v3/<API_KEY>';
const oracle = new GasPriceOracle({ defaultRpc });

oracle.fetchGasPricesOnChain().then(gasPrices => {
  console.log(gasPrices); // 21
});