getTransaction vs getTransactionReceipt

What is the difference between two methods web3.eth.getTransaction and web3.eth.getTransactionReceipt in the web3 library? I tried to read this documentation but the difference is not clear to me.

1 Answer

The receipt is available only for mined transactions. But because of this, it includes a few more properties:

  • status - successful or reverted
  • gasUsed - amount of gas used by this tx alone
  • cumulativeGasUsed - amount of gas used by this tx and its internal transactions
  • logs - list of event logs that the transaction produced

The 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.

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like