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
So a smart contract can have his own storage? – Felix – 2018-01-18T21:25:13.020
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 – 2018-01-18T21:30:28.833