I am trying to calculate the dollar cost of ETH transactions using the following code:

response = requests.get('https://api.etherscan.io/api',params={'module':'account','action':'txlist','address':address,'startblock':'0','endblock':'99999999','sort':'desc','apikey':key})

As a result, I have the following data for the transactions:

['blockNumber', 'timeStamp', 'hash', 'nonce', 'blockHash',
       'transactionIndex', 'from', 'to', 'value', 'gas', 'gasPrice', 'isError',
       'txreceipt_status', 'input', 'contractAddress', 'cumulativeGasUsed',
       'gasUsed', 'confirmations', 'methodId', 'functionName'] 

Does anybody know how I might work those values to get the total gas cost in USD for that transaction? I know how to get ETH historical prices. Thank you for your help.

1 Answer 1


gasUsed * gasPrice should give you the cost in wei (10^18 wei = 1 ether). So you just need to get the ether price at timeStamp to get the price in whatever fiat you want.

  • What is the unit of gasUsed is it gwei?
    – alper
    Commented Dec 24, 2023 at 14:18
  • @alper it is the same as gas, a measure without unit. It is just a number.
    – Ismael
    Commented Dec 25, 2023 at 4:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.