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.

8
  • 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
    Commented Mar 2, 2017 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
    Commented Mar 2, 2017 at 14:45
  • This is more of an architecture design oriented question, just like how to use promises in javascript. Nice edit there ethereum.stackexchange.com/posts/12672/revisions
    – niksmac
    Commented Mar 2, 2017 at 14:49
  • 1
    Welcome to the community! ethereum.stackexchange.com/questions/1547/… may help and please also check ethereum.stackexchange.com/help
    – eth
    Commented Mar 2, 2017 at 15:14
  • 1
    Ha, in fact: ethereum.stackexchange.com/questions/1547/… Commented Mar 2, 2017 at 17:30

3 Answers 3

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')})
2
  • 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
    Commented Mar 6, 2017 at 9: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
    Commented Mar 6, 2017 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)

1
  • 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
    Commented Mar 6, 2017 at 9: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);
0

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