3

I am trying to use Etherscan gas tracker api to get gas prices. I figured out to use apis for the Ethereum mainnet, however I am having some problems with the testnets.

I have found a question and an answer that if I use api-ropsten for instance, I am supposed to get the fields for the testnet.(https://ethereum.stackexchange.com/q/73829) But I found this not working for gas tracker api.

https://api-rinkeby.etherscan.io/api?module=gastracker&action=gasoracle&apikey=XXXX

I have tried this, but it gave me same response as mainnet.

How can I get gas price of Ethereum testnets (ropsten, rinkeby ..)?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65

2 Answers2

2

It looks like the etherscan api for the rinkeby network is returning data from the wrong chain. I am able to observe the problem too. It unfortunately look like a bug on etherscan's side.

If you really need those gas price before etherscan fixes the issue, you could connect to a node provider like infura via JSON rpc but that might be too complicated for your use case.

Xavier Hamel
  • 546
  • 1
  • 9
  • Are you getting different values from `https://api.etherscan.io/api?module=gastracker&action=gasoracle` and `https://api-rinkeby.etherscan.io/api?module=gastracker&action=gasoracle`? I see same results, not only the gas prices but also the last block numbers are the same, which makes me think that they are same values(values for the mainnet, not rinkeby). – 김도영 Dara Jan 24 '22 at 01:11
  • You might be right, now that i have taken a deeper look into it the rinkeby endpoint seems to return the mainnet data like you mentionned. I'm sorry for the confusion i might have caused. Last time, I probably just look it too fast and got the results from 2 different blocks. – Xavier Hamel Jan 25 '22 at 03:06
0

Etherscan only maintains gas oracles for mainnet, no testnets are supported at the moment. the testnet links were not supposed to be accesible

An alternative to this is making an eth_gasPrice call to a testnet node to get the current gas price of the testnet network.

  • What is an example of the "call to a node" that you mention? – ryanwebjackson May 12 '23 at 22:58
  • 1
    Making a [JSON RPC](https://ethereum.org/en/developers/docs/apis/json-rpc/) request to an Ethereum testnet node to check the current gas price. If you'd like to use this in HTTP, feel free to use [eth_getCode](https://docs.etherscan.io/api-endpoints/geth-parity-proxy#eth_gasprice) on Etherscan's API – 0xV4L3NT1N3 May 16 '23 at 09:52