Skip to content

[feature] Smart Gas Price #44

@roynalnaruto

Description

@roynalnaruto

At present, DigixDAO platform uses a hard-coded value of 10 gwei for the default gas price.

We would like to integrate Ethgasstation API to:

  1. Provide user-friendly clickable options for gas price
  2. Provide time estimate for the transaction to be mined

Details

  • Fetch gas price data from the Ethgasstation API
    • fill up the default options with gas price and estimated time
  • Transaction Fee
transaction fee = gas limit * gas price

Note: the gas limit can be found out from the txData object (refer)

gasLimit = txData.gas

API

Endpoint: https://ethgasstation.info/json/ethgasAPI.json

Note:

  • To convert the gas price values to gwei unit, divide them by 10
  • The wait times are in minutes. Please convert them to hours and minutes and seconds
    • 0.4 would be 24 seconds
    • 1.3 would be 1 minutes 18 seconds
    • 61.5 would be 1 hours 1 minutes 30 seconds

If sample response is:

{
	"fast": 40.0,
	"fastest": 60.0,
	"safeLow": 10.0,
	"average": 10.0,
	"block_time": 12.534883720930232,
	"blockNum": 8243182,
	"speed": 0.8315751882176169,
	"safeLowWait": 3.6,
	"avgWait": 3.6,
	"fastWait": 0.5,
	"fastestWait": 0.4
}

Then:

  • Gas price for fast transaction is 4 gwei
  • Gas price for fastest transaction is 6 gwei
  • Gas price for safeLow transaction is 1 gwei
  • Gas price for average transaction is 1 gwei
  • Estimated time for fast transaction is 30 seconds
  • Estimated time for fastest transaction is 24 seconds
  • Estimated time for safeLow transaction is 3 minutes 36 seconds
  • Estimated time for average transaction is 3 minutes 36 seconds

Design

SmartGasPrice01
SmartGasPrice02

Behaviour

If response is the json response from the API call

  • Default state
    • fast option is selected
    • Gas price is response.fast/10
    • Estimated wait time is format(response.fastWait)
    • The slider under advanced section is set to the gas price value
    • The Transaction Fee is set to txData.gas * gasPrice
  • Clicking on any option (safe low/average/fast/fastest) will
    • Deselect the previously selected option
    • Select the clicked option
    • Update the gas price as per response
    • Update the estimated wait time response
    • Update the slider under advanced section, set it to the gas price value
    • Update the Transaction Fee based on the newly selected gasPrice
  • Moving the slider under advanced section will
    • Deselect all the gas price options (safe low, average, fast, fastest)
    • Update the gas price as per slider value
    • Remove the estimated wait time for transaction (we show this only in the case of selected options from the API)
    • Update the Transaction Fee based on the newly selected gasPrice

Note: If the Ethgasstation API is down and returns null values:

  • Deselect all options
  • Set the slider and gas price to a default value of 10 gwei

Metadata

Metadata

Assignees

No one assigned

    Labels

    bountyThis issue has a bounty associated with it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions