3

I'm a total newbie to blockchain and just started with it a week ago. I have already deployed a private Ethereum blockchain and want to use it to ensure document integrity which means that I'll be storing MD5 checksums on the blockchain to check at a later point in time.

Now I understand that a blockchain is not for storing data and one should use OP_RETURN to store such information if desired. This brings me to my question i.e. How do I create such a transaction and add the document's hash to it in OP_RETURN using:

  1. A web3.eth object
  2. Nethereum

Any and all help will be appreciated.

Syed
  • 153
  • 5
  • I'm voting to close this question as off-topic because You should only ask practical, answerable questions based on actual problems that you face. Chatty, open-ended questions diminish the usefulness of our site and push other questions off the front page. And Reddit might be a good place for chatty questions. – niksmac Mar 02 '17 at 14:37
  • @niksmac Since when has a questioning starting with "How do I..." being called a chatty question? I'd appreciate if you could actually point me to a resource where the statement for creating such a transaction is mentioned. – Syed Mar 02 '17 at 14:45
  • This is more of an architecture design oriented question, just like how to use promises in javascript. Nice edit there http://ethereum.stackexchange.com/posts/12672/revisions – niksmac Mar 02 '17 at 14:49
  • @niksmac Well, your comment still doesn't answer my question. How is such a transaction written using web3.eth or Nethereum? – Syed Mar 02 '17 at 15:02
  • 1
    Welcome to the community! http://ethereum.stackexchange.com/questions/1547/how-to-replicate-bitcoins-op-return-functionality-on-ethereum may help and please also check http://ethereum.stackexchange.com/help – eth Mar 02 '17 at 15:14
  • @Syed What is this OP_RETURN? @eth thanks for the update. – niksmac Mar 02 '17 at 15:21
  • OP_RETURN is from the Bitcoin world - this isn't an Ethereum thing... (You could copy its functionality using a contract, but that's probably a different question entirely.) – Richard Horrocks Mar 02 '17 at 17:29
  • 1
    Ha, in fact: https://ethereum.stackexchange.com/questions/1547/how-to-replicate-bitcoins-op-return-functionality-on-ethereum – Richard Horrocks Mar 02 '17 at 17:30

3 Answers3

2

In ethereum there is no script opcodes so there is no op_return (like in Bitcoin). However you could store data in a similar way by using :

eth.sendTransaction({from:eth.accounts[0],to:eth.accounts[1],value:web3.toWei(1‌​00,'finney'),data:web3.toHex('My Message')})
Badr Bellaj
  • 18,780
  • 4
  • 58
  • 75
  • thanks, this was helpful. I've been able to add the data this way and will now give Mikko's approach a try. Is it safe to say that the best way to do this would be using Mikko's Smart contract approach below? – Syed Mar 06 '17 at 09:33
  • it is not about safety but about how do you intend to desing your app if you want to use a smart contract so use it otherwise just send transactions containing your hash. you have the choice – Badr Bellaj Mar 06 '17 at 12:54
2

Smart contracts can store any data, including document hashes

contract MyHashRegistry {

    mapping (uint => uint) hashes:

    function storeHash(uint documentId, uint hash) {
        hashes[documentId] = hash;
    }
}

It seems that you do not have yet relevant experience in Ethereum to build your own things, so jumping into conclusion instead of understanding all the steps in between is an issue here. I suggest taking a learning path. You need to

  • Learn Solidity programming language

  • Create a smart contract

  • Learn how to interact with smarts contracts from your computer (web3.js, web3.py)

Mikko Ohtamaa
  • 22,269
  • 6
  • 62
  • 127
  • 1
    thanks, I've been able to add the transaction with the way Badr prescribed above but I believe Smart contracts would be the proper way to do it. Will follow the learning path you suggested. – Syed Mar 06 '17 at 09:36
2

Thought it might be helpful to add the code here for posting the transaction using Nethereum:

var txCount = await web3.Eth.Transactions.GetTransactionCount.SendRequestAsync(senderAddress);
var encoded = web3.OfflineTransactionSigning.SignTransaction(myPrivateKey, receiverAddress, 
                amount: 0, 
                nonce: txCount.Value, 
                gasPrice: 1,
                gasLimit: 100000,
                data: myHexData);

txId = await web3.Eth.Transactions.SendRawTransaction.SendRequestAsync(encoded);
Syed
  • 153
  • 5