how to use web3j over infura to find exact gas price used for a successful transaction

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.

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 at 21:53