commands/update.js
function getGasPrice(toWei) {
  return axios.get("https://ethgasstation.info/json/ethgasAPI.json").then(response => {
    //ethgasstation returns 10x the actual average for some odd reason
    let actualAverage = response.data.average / 10
    winston.debug(`gas price actualAverage: ${actualAverage}`)

    //We want to just add a bit more than average to be speedy
    let safeAmount = actualAverage + 0.1
    winston.debug(`gas price safeAmount: ${safeAmount}`)

    //We want to round to the tenthousandth precision
    let rounded = Math.round(safeAmount * 10000) / 10000
    winston.debug(`gas price rounded: ${rounded}`)

    //Lets save the gas price in wei, rather than gwei, since that is how web3 expects it.
    let wei = toWei(`${rounded}`, 'gwei')
    winston.debug(`gas price wei: ${wei}`)

    return parseInt(wei)
  })
}
function getGasPrice(toWei) {
  return axios.get("https://ethgasstation.info/json/ethgasAPI.json").then(response => {
    //ethgasstation returns 10x the actual average for some odd reason
    let actualAverage = response.data.average / 10
    winston.debug(`gas price actualAverage: ${actualAverage}`)

    //We want to just add a bit more than average to be speedy
    let safeAmount = actualAverage + 0.1
    winston.debug(`gas price safeAmount: ${safeAmount}`)

    //We want to round to the tenthousandth precision
    let rounded = Math.round(safeAmount * 10000) / 10000
    winston.debug(`gas price rounded: ${rounded}`)

    //Lets save the gas price in wei, rather than gwei, since that is how web3 expects it.
    let wei = toWei(`${rounded}`, 'gwei')
    winston.debug(`gas price wei: ${wei}`)

    return parseInt(wei)
  })
}
function getGasPrice ( toWei ) { return axios . get ( "https://ethgasstation.info/json/ethgasAPI.json" ) . then ( response => { //ethgasstation returns 10x the actual average for some odd reason let actualAverage = response . data . average / 10 winston . debug ( ` ${ actualAverage } ` ) //We want to just add a bit more than average to be speedy let safeAmount = actualAverage + 0.1 winston . debug ( ` ${ safeAmount } ` ) //We want to round to the tenthousandth precision let rounded = Math . round ( safeAmount * 10000 ) / 10000 winston . debug ( ` ${ rounded } ` ) //Lets save the gas price in wei, rather than gwei, since that is how web3 expects it. let wei = toWei ( ` ${ rounded } ` , 'gwei' ) winston . debug ( ` ${ wei } ` ) return parseInt ( wei ) } ) }
This function is way more verbose than needed on purpose The logic is not easy to understand when done as a one-liner Returns the gas price in wei
This function is way more verbose than needed on purpose The logic is not easy to understand when done as a one - liner Returns the gas price in wei