3

I'm currently trying to find practical examples for the usage of a blockchain, instead of a typical database like MySQL. I understand that the big advantage of a blockchain is the high security of data not being compromised.

But how can I imagine accessing or searching for a specific record in the blockchain?

Let's say, in a company we use a blockchain for saving all employee payrolls? How could one look up all payrolls for a specific employee?

3

You can access blockchain data like the way you access normal data in any MVC where you fetch data from database ,manipulate it in backend and display the result in front end. Incase of blockchain,what ayou need to understand is it is nothing but a decentralized database where transactions occor dynamically and the data is distibuted among all the nodes.

So to explain how the data is actually fetched from blockchain what i do is ,Crawl each block in the blockchain and store the data in your preferred data base like Mysql or Mongo

You can crawl blocks using simple rpc like getblockhash "n" which will give you hash of "n" block, which looks like

eee7f58d111ef0b25f7f6e8703d80ab6b51ca957170daea949e93e6467906889

and for the above hash do:

getblock eee7f58d111ef0b25f7f6e8703d80ab6b51ca957170daea949e93e6467906889 

will gives you the content of the block which looks like

{
    "hash" : "eee7f58d111ef0b25f7f6e8703d80ab6b51ca957170daea949e93e6467906889",
    "confirmations" : 176023,
    "size" : 261,
    "height" : 0,
    "version" : 1,
    "merkleroot" : "695191c2e8f8fddc75331a38d658ab07672970b09981ad77c29c4b0b17580941",
    "tx" : [
        "695191c2e8f8fddc75331a38d658ab07672970b09981ad77c29c4b0b17580941"
    ],
    "time" : 1518520240,
    "nonce" : 2084635057,
    "bits" : "1e0ffff0",
    "difficulty" : 0.00024414,
    "nextblockhash" : "1bb4a4c35103a363ad63bf59bf7fa45c06babcfa8d848ceeb7e4958f9a9f660e"
}

Now every key value of above output replicates some important concept which cannot be ignored. But fow now lets just focus on "tx", the array of tx are the list of transaction that has been minned in the n th block, and now you can crawl each and evry transaction given in tx array using rpc getrawtransaction to know the detail of transaction

and i store the details in Mongo db so and keep track of my applications user their addresses and transactions they have done.

So this is a simple approach by which i access data from blockcahin

1

I'm currently trying to find practical examples for the usage of a blockchain, instead of a typical database like MySQL. I understand that the big advantage of a blockchain is the high security of data not being compromised.

That's a meaningless question. A blockchain is not a replacement for a database; it is a mechanism for multiple parties which are already running their own databases to make sure they all end up in the same state.

For example, in Bitcoin, that database is the UTXO set, which maintains for every unspent coin the amount and owner. Every Bitcoin full node has its own copy of that UTXO set. It can be stored in any kind of database engine - the most common ones using a specialized LevelDB instance. The blockchain consists of a list of authenticated updates to that database. You never search the blockchain itself, as that would be like going through all your bank statements to find your balance. Instead, you just look at the balance itself.

In the case of Bitcoin, that database is a very simple key-value store, as that is sufficient for verifying transactions. It is highly specialized, and does not maintain any indexes beyond what is necessary for validating things. But in theory, it could instead be backed by MySQL - allowing you to issue queries against your own UTXO set.

Let's say, in a company we use a blockchain for saving all employee payrolls? How could one look up all payrolls for a specific employee?

That would be ridiculous. The problem a blockchain solves is consistency while permitting multiple independent and distrusting parties to make updates which may conflict with each other ("double spends" in Bitcoin's case). If you have a single party (the employer) who must approve updates to the database anyway (or a collection of identifiable parties who trust each other to some extent) much more efficient technologies exist.

0

One possible simple implementation of this would be by making an Ethereum smart contract. You could easily store employee information in a mapping of their ethereum address to whatever information. You can fetch the stored information in javascript. The contract could be written so only the employee could view his data.

  • So a smart contract can have his own storage? – Felix Jan 18 '18 at 21:25
  • Yes, but writing is very expensive (you will need to pay ethereum gas), so I would not recommend to actually do this, but it's the easiest implementation that I can think of. Reading data is not expensive though. – Cedric Martens Jan 18 '18 at 21:30

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.