I want to sum the total amount of gas used in a block.

When I checked, used gas can be retrieved from the node using 'eth_getTransactionReceipt' and 'trace_block' functions.

However, when checking the total of the used gas of the block in the two functions, it was confirmed that the sum of the used gas obtained in each function(eth_getTransactionReceipt, trace_block) was different.

Compared to etherscan, it was equal to the total sum of used gas in receipt of each transaction.

Why is the total sum of used gas in trace_block different? In what cases is gas used other than trace in Ethereum?

1 Answer 1


To get the total amount of used gas for each block you can use the eth_getBlockByNumber method. This method is returning gasUsed value which is the total amount of used gas by all transactions in the particular block. To use this method you have to pass the block number.

  • I checked eth_getBlockByNumber function. But, there is not has gasUsed value. so I used eth_getTransactionReceipt and trace_block... eth.wiki/json-rpc/API
    – Minwoo
    Aug 23, 2021 at 2:57
  • There is gasUsed for sure, you need to test it. I'm using this method in my code and I can clearly see the gasUsed value for each block. Aug 23, 2021 at 5:49
  • Oh thanks for replying! Also I made a mistake..! However, the reason I was going to use gasUsed was to calculate the fee and burnt fee, so I needed gasUsed per tx rather than gasUsed of block..!
    – Minwoo
    Aug 29, 2021 at 18:34

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.