7

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?

Rahul Sharma
  • 1,303
  • 2
  • 16
  • 24
  • Do you need it to be the transaction hash only, or can you use events? Events are the clean and recommended way of implementing something like this – Tjaden Hess Dec 08 '16 at 19:18
  • @TjadenHess I see. Are you saying that we keep the logs out of chain? Say and external db? – niksmac Dec 09 '16 at 04:45
  • 1
    The logs are part of the chain, you can always fetch the past ones directly from your client. It may be helpful to store a database for faster lookups, but events are logged and stored as part of the consensus protocol – Tjaden Hess Dec 09 '16 at 05:04
  • It is a good practice that accepting the answer as correct if it helped you resolved the issue. That is the whole point of SE none of the answers for your questions are marked as correct. FYI, if youre not aware of it. – niksmac Dec 23 '16 at 02:53

1 Answers1

6

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.

Thomas Jay Rush
  • 9,943
  • 4
  • 31
  • 72