0
votes

In the last few weeks, I tried to code my own Blockchain, just to understand the whole concept better. You can find my code here: https://github.com/Snixells/js-blockchain .
I already implemented that the Blockchain + Transactions are created through nodeJs arrays and JSON. The problem I am working on right now is that the data does not get saved. I want to run the whole blockchain on a (maybe) express server and access it by a RESTful API. Because of that, I need a way to store the Blockchain somewhere. I also have already some ideas but none of them seems like a good one.

  1. I could save the whole chain as a JSON file and always when needed open that and afterwards save it. But that won't scale at all later
  2. I thought about saving each block as a single JSON file, but I think that wouldn't work that great either.
  3. I could use any kind of database, like RethinkDB or MongoDB but that conflicts with the whole idea of Blockchain being the database itself.

I would love to hear some answers, for example, what frameworks and so on I could use. Or maybe any ideas on how to store the database at all. Thanks for your help :)

1
point 1 and 2 are not immune to 3, infact, they are pretty much the same exept you are storing the data differently - you need to have a place to store the blockchain, but it's not decentralized if there is only 1 node, but you have to start somewhere. medium.com/@brendanrius/… - George
so i don't see anything wrong with storing the data in a database, it's just not really a decentralized block chain without lots of nodes (i.e. a network each has a copy of the blockchain). - George
just append the new blocks to a single file, "almost JSON". you can then use standard file access commands to serve chunks of the large ledger file, like the tail for example. append-only is fast to record. - dandavis
and you are correct storing a json file on your server wont be scaleable so I would use a database instead. you would need to link each block though - George
Okay, thanks for your fast answers. I'll try to implement with a database and also by saving the blockchain in json file using append only! Although I would prefer to save the data in a different way...If you get any additional ideas please tell me! - Snixells

1 Answers

0
votes

Update:
I tried out rethinkDB and it seems to be a great choice because you can just simply store json objects in that database. It's perfect for what I need!