diff --git a/CHANGELOG.md b/CHANGELOG.md index 23675d30..608f504b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # 0.1.1 (Not released) +- Add `etherscan.GasPrice` function to return last block gas price [[GH-182](https://github.com/umbracle/ethgo/issues/182)] - Add `4byte` package and cli [[GH-178](https://github.com/umbracle/ethgo/issues/178)] - Install and use `ethers.js` spec tests for wallet private key decoding [[GH-177](https://github.com/umbracle/ethgo/issues/177)] - Add `GetLogs` function Etherscan to return logs by filter [[GH-170](https://github.com/umbracle/ethgo/issues/170)] diff --git a/etherscan/etherscan.go b/etherscan/etherscan.go index 2f159f33..13086b4a 100644 --- a/etherscan/etherscan.go +++ b/etherscan/etherscan.go @@ -148,6 +148,20 @@ func (e *Etherscan) GetContractCode(addr ethgo.Address) (*ContractCode, error) { return out[0], nil } +func (e *Etherscan) GasPrice() (uint64, error) { + var out struct { + LastBlock string `json:"LastBlock"` + } + if err := e.Query("gastracker", "gasoracle", &out, map[string]string{}); err != nil { + return 0, err + } + num, err := strconv.Atoi(out.LastBlock) + if err != nil { + return 0, err + } + return uint64(num), nil +} + func (e *Etherscan) GetLogs(filter *ethgo.LogFilter) ([]*ethgo.Log, error) { if len(filter.Address) == 0 { return nil, fmt.Errorf("an address to filter is required") diff --git a/etherscan/etherscan_test.go b/etherscan/etherscan_test.go index a8d1762e..fa5c1e09 100644 --- a/etherscan/etherscan_test.go +++ b/etherscan/etherscan_test.go @@ -56,3 +56,11 @@ func TestGetLogs(t *testing.T) { assert.NoError(t, err) assert.NotEmpty(t, logs) } + +func TestGasPrice(t *testing.T) { + e := testEtherscanMainnet(t) + + gas, err := e.GasPrice() + assert.NoError(t, err) + assert.NotZero(t, gas) +} diff --git a/website/pages/integrations/etherscan.mdx b/website/pages/integrations/etherscan.mdx index 0da8ff4e..b95d436d 100644 --- a/website/pages/integrations/etherscan.mdx +++ b/website/pages/integrations/etherscan.mdx @@ -94,3 +94,11 @@ Input: Output: - `logs` : List of logs that match the filter. + +## GasPrice + +GasPrice returns the gas price of the latest block. + +Output: + +- `gasPrice` (`uint64`): Gas price of the latest block.