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.
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/.