1

I am looking to convert gas fee info from this api end point: into dollars (calculating taxes).

The endpoint gives 'gas', 'gasPrice' and 'gasUsed' values that I'm sure would be enough, but I can't quite work it out.

Promila Ghosh
  • 389
  • 4
  • 12
PeteG
  • 421
  • 3
  • 17

1 Answers1

3

You can calculate the price in dollars using the following formula:

usdPrice = gasUsed * gasPrice * ethToUsd

You can take the first two parameters (gasUsed and gasPrice) from etherscan. To get the current conversion rate between ETH and USD (ethToUsd) you need to query some exchange API, e.g., https://min-api.cryptocompare.com/.

Rafał Leszko
  • 4,939
  • 10
  • 19