my goal is to compute the cost of gas for a successful tx. I get a callback when a transaction succeeds and i retrieve gasUsed with transactionReceipt.getGasUsed(). Now I need to know the exact gas price that was used for this tx.

It does not seem like gasprice is stored in txreceipt. the gas price (obtained with transfer.requestCurrentGasPrice()) is in some other place where tx is signed but at that time we would not know the actual gas that will be used. so i wait for txreceipt to find the actual gas used but i then ran into the issue of not knowing gas price that was used.

1 Answer 1


One option would be to call web3.eth.getTransactionByHash() using the transaction hash once you've received your callback.

The returned data includes:

gas: QUANTITY - gas provided by the sender.
gasPrice: QUANTITY - gas price provided by the sender in Wei.
  • The question says web3j, however there are similar methods, like web3j.ethGetTransactionByHashetc
    – comodoro
    Jan 8, 2019 at 21:53

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.