0

Suppose, I have a database that stores all the student details in mysql. To confirm and seal any manipulation in the database I want to store the changes in the blockchain network as a transaction and using the hash of the transaction I want to get back the details of the transaction. Can anyone assist me in finding how can I do this?

1

The cheapest way to store hash of your data record in Ethereum blockchain is to treat hash as Ethereum address and send zero ether to it with no data attached. This requires hash to be at most 20 bytes wide. Such transaction, sent from your address, will be signed by your private key, so anybody will be able to check that these transactions were sent by you and not by somebody else.

Then you may store transaction details in MySQL indexed by transaction hash.

Here is how it may work:

  1. you want to update student with ID 123 and set value for groupID attribute to 456, i.e. execute the following MySQL query: UPDATE students SET gropuID=456 WHERE studentID=123
  2. encapsulate update details into, say, JSON, like this: {seqNo:4321,operation:'UPDATE',studentID:123,fields:{gropuID:456}}
  3. calculate hash of this JSON, i.e. keccak256: 0x41e717a9ca1cfbdfde8b524c7b9b1986a54696c4d9f1b9308bdada31e0bf8993
  4. get 20 last bytes from the hash: 0x7b9b1986a54696c4d9f1b9308bdada31e0bf8993
  5. send zero ether from your address (address known to belong to you) to this address, i.e. to 0x7b9b1986a54696c4d9f1b9308bdada31e0bf8993, with no data attached (this will cost you 21000 gas)
  6. obtain transaction hash, i.e. 0x1dbc4158799ea44f8d09e83940b3c50290b03b0f19093d4028bb7e8d067f5f95
  7. save JSON together with transaction hash into special MySQL table like this: INSERT INTO transactions (txHash, txDetails) VALUES ('0x1dbc4158799ea44f8d09e83940b3c50290b03b0f19093d4028bb7e8d067f5f95', '{seqNo:4321,operation:'UPDATE',studentID:123,fields:{gropuID:456}}'

Now this record is effectively signed with your private key and stored in blockchain, so anybody may verify that content of transactions table was not manipulated.

| improve this answer | |
  • I have used solidity to write different smart contracts. But what you are saying I am not getting it. Will you please give me a demo of code to execute and get a hint of it how will it work? – Partha Pratim Sarkar Choito Apr 27 '19 at 7:46
  • Added more details – Mikhail Vladimirov Apr 27 '19 at 10:09

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.