Search code examples
ethereumblockchainsmartcontractsweb3js

How to read information from ethereum transaction using transactionHash in web3?


Say I had updated a variable x as(x=10) inside the smart contract. I stored the transactionHash. Then I again changed the value of x=20 then I'll get a new transaction hash. So is there any way using the transactionHash of the earlier updation(x=10) with which I can see the what value of x it was?


Solution

  • There are two ways to get output from the smart contracts

    • You read the state directly using the smart contract ABI and calls

    • The transaction contains Solidity events which you can parse from the transaction logs

    For both cases the support has to be written to the smart contract and in this question the smart contract code itself is missing, so it is not possible to tell exactly how to do it.

    Generally, nodes do not support reading historical state. They support reading historical event logs though, so if you need to access the data over time series then you need to write your smart contract so that it emits events.