1

Two questions, related:

  1. Is the getGasUsed() on the TransactionReceipt truly the actual gas used, not the gasLimit or the gas estimate? Looks like it but...
  2. Is the actual gas used obtainable ("readable") outside of the TransactionReceipt? Can you use the tx hash or other material to after-the-fact determine the actual gas used?

EDIT: Just came across this in the test drivers for web3j:

EthGetTransactionReceipt etxr = web3j.ethGetTransactionReceipt(txhash).send();
assertTrue(ethGetTransactionReceipt.getTransactionReceipt().isPresent());                   
TransactionReceipt TXr = etxr.getTransactionReceipt().get();

I tried it and it works. After the fact (like in a Filter or Flowable), when I get the TXhash, I can get the TXreceipt and thus the actual gas used.

Why isn't this more easily discoverable?

1 Answer 1

1
  1. Yes, the gasUsed on the transaction receipt is the true gas used by the transaction.
  2. The only (reasonable) way to get get used is to read the receipt.

Other, not ideal ways to do so are to (a) read all the OPCODES from the tx and add up their costs, or (b) read the gas used in the total block and subtract the gasUsed of all the other transactions in the block.

2
  • Asked and answered; thx. But it seems odd that the actual amount of gas used (and with a bit of stretch, the gas price) is not available after the fact. This means all transaction makers (should / must?) capture the TXreceipt in detail off chain in order to perform higher level analytics. Commented Sep 1, 2020 at 0:19
  • Wait, I don't know why I didn't get this until just now. If you say I can get total gas in the block and subtract gasUsed by all other transactions, does not imply that the transaction I seek is also in that set and is carrying gasUsed? Commented Sep 1, 2020 at 13:00

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.