[Ethereum] How to trace state of transactions in ethereum

blockchaingo-ethereumsolidity

I have a smart contract of Student Registration. The state changes in the following manner:

  1. When Student enters the credential in the form, the state is OPEN.
  2. When college registers the student against its credentials, state is REGISTERED.
  3. When payment of fee is done, state becomes PAID.

Here, after every action, i.e registration or payment, i receive a transaction hash of the transaction. How can i trace all the states of this process with transaction hash only. This is also called as Audit trail. How can i accomplish this in solidity or ethereum?

Best Answer

In the contract code itself you should have already placed 'events' at each point where you wish to track state changes. Then, you would use a web3.js filter to watch for the events on your calendar (sorry, I don't have a link to that code, but it would most likely involve the use of this RPC function: https://github.com/ethereum/wiki/blob/master/JSON-RPC.md#eth_newfilter).

If you don't have events already built into your smart contract, you could pull down transactions from a block explorer such as http://etherscan.io using their API functionality, but then you would have to post process and be careful to account for in-error transactions and internal transactions.

Related Topic