What is the difference between two methods web3.eth.getTransaction
and web3.eth.getTransactionReceipt
in the web3 library? I tried to read this documentation https://web3js.readthedocs.io/en/v1.2.0/web3-eth.html#gettransactionreceipt but the difference is not clear to me.
The receipt is available only for mined transactions. But because of this, it includes a few more properties:
status
- successful or revertedgasUsed
- amount of gas used by this tx alonecumulativeGasUsed
- amount of gas used by this tx and its internal transactionslogs
- list of event logs that the transaction producedThe regular getTransaction
allows you to get details (such as from
, to
, data
and value
) for transactions that are not yet mined. Possible use case: You got only the transactionHash
from an external source and need to find out the recipient and don't know whether the transaction has been mined yet.
So they both can be used in different cases.