Skip to content
This repository has been archived by the owner on Feb 21, 2020. It is now read-only.

A module for advising default gas prices, by analyzing recent successful transactions.

Notifications You must be signed in to change notification settings

MetaMask/eth-gas-price-suggestor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Eth Gas Price Suggestor

A module for getting the current average gas price of ethereum transactions.

Installation

npm install eth-gas-price-suggestor -S

Example Usage

const Eth = require('ethjs');
const provider = new Eth.HttpProvider('https://mainnet.infura.io');
const BlockTracker = require('eth-block-tracker')
const Suggestor = require('eth-gas-price-suggestor')

const blockTracker = new BlockTracker({ provider })
blockTracker.start()

const suggestor = new Suggestor({
 blockTracker,
 historyLength: 10, // number of blocks to average, default 20.
 defaultPrice: 20000000000, // In case of network error. Default 20 gwei.
})

setInterval(async function() {
  try {
    const suggested = await suggestor.currentAverage()
    console.log('CURRENT SUGGESTION in GWEI: ' + Eth.fromWei(suggested, 'gwei'))
  } catch (e) {
    console.log('failed: ', e)
  }
}, 10000)

About

A module for advising default gas prices, by analyzing recent successful transactions.

Resources

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published