Documentation
¶
Overview ¶
Package gas provides a client for the ETH Gas Station API and convenience functions.
It includes type aliases for each priority level supported by ETH Gas Station, functions to get the lastest price from the API, and a closure that can be used to cache results for a user-defined period of time.
Index ¶
Constants ¶
const ( // GasPriorityFast is the recommended gas price for a transaction to be mined in less than 2 minutes. GasPriorityFast = GasPriority("fast") // GasPriorityFastest is the recommended gas price for a transaction to be mined in less than 30 seconds. GasPriorityFastest = GasPriority("fastest") // GasPrioritySafeLow is the recommended cheapest gas price for a transaction to be mined in less than 30 minutes. GasPrioritySafeLow = GasPriority("safeLow") // GasPriorityAverage is the recommended average gas price for a transaction to be mined in less than 5 minutes. GasPriorityAverage = GasPriority("average") )
const ETHGasStationURL = "https://ethgasstation.info/json/ethgasAPI.json"
ETHGasStationURL is the API URL for the ETH Gas Station API.
More information available at https://ethgasstation.info
Variables ¶
This section is empty.
Functions ¶
func SuggestFastGasPrice ¶
SuggestFastGasPrice is a helper method that calls SuggestGasPrice with GasPriorityFast
It always makes a new call to the ETH Gas Station API. Use NewGasPriceSuggester to leverage cached results.
func SuggestGasPrice ¶
func SuggestGasPrice(priority GasPriority) (*big.Int, error)
SuggestGasPrice returns a suggested gas price value in wei (base units) for timely transaction execution. It always makes a new call to the ETH Gas Station API. Use NewGasPriceSuggester to leverage cached results.
The returned price depends on the priority specified, and supports all priorities supported by the ETH Gas Station API.
Types ¶
type GasPriceSuggester ¶
type GasPriceSuggester func(GasPriority) (*big.Int, error)
GasPriceSuggester is type alias for a function that returns a reccomended gas price in base units for a given priority level.
func NewGasPriceSuggester ¶
func NewGasPriceSuggester(maxResultAge time.Duration) (GasPriceSuggester, error)
NewGasPriceSuggester returns a function that can be used to either load a new gas price response, or use a cached response if it is within the age range defined by maxResultAge.
The returned function loads from the cache or pulls a new response if the stored result is older than maxResultAge.
type GasPriority ¶
type GasPriority string
GasPriority is a type alias for a string, with supported priorities included in this package.