-
-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from avislash/feature/gas_tracker
Free Gas Tracker Endpoints
- Loading branch information
Showing
3 changed files
with
124 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright (c) 2022 Avi Misra | ||
* | ||
* Use of this work is governed by a MIT License. | ||
* You may find a license copy in project root. | ||
*/ | ||
|
||
package etherscan | ||
|
||
import "time" | ||
|
||
// GasEstiamte gets estiamted confirmation time (in seconds) at the given gas price | ||
func (c *Client) GasEstimate(gasPrice int) (confirmationTimeInSec time.Duration, err error) { | ||
params := M{"gasPrice": gasPrice} | ||
var confTime string | ||
err = c.call("gastracker", "gasestimate", params, &confTime) | ||
if err != nil { | ||
return | ||
} | ||
return time.ParseDuration(confTime + "s") | ||
} | ||
|
||
// GasOracle gets suggested gas prices (in Gwei) | ||
func (c *Client) GasOracle() (gasPrices GasPrices, err error) { | ||
err = c.call("gastracker", "gasoracle", M{}, &gasPrices) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (c) 2018 LI Zhennan | ||
* | ||
* Use of this work is governed by a MIT License. | ||
* You may find a license copy in project root. | ||
*/ | ||
|
||
package etherscan | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
//GasEstiamte generates dynamic data. Best we can do is ensure all fields are populated | ||
func TestClient_GasEstimate(t *testing.T) { | ||
_, err := api.GasEstimate(20000000) | ||
noError(t, err, "api.GasEstimate") | ||
} | ||
|
||
//GasOracle generates dynamic data. Best we can do is ensure all fields are populated | ||
func TestClient_GasOracle(t *testing.T) { | ||
gasPrice, err := api.GasOracle() | ||
noError(t, err, "api.GasOrcale") | ||
|
||
if 0 == len(gasPrice.GasUsedRatio) { | ||
t.Errorf("gasPrice.GasUsedRatio empty") | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters