DEV Community

Zohaib Sibte Hassan
Zohaib Sibte Hassan

Posted on

A blockchain for dummies

While crypto-currencies are having bad time financially these days, it obviously has inspired and spun up a lot of applications. Blockchain and proof-of-work are fundamental concepts for the buzz that surrounds crypto-currency. While I see many people discussing the applications and possibilities, the serious lack of understanding among common developers prompted me to do a "Blockchain for dummies" implementation. So here it is:

Here are the goals I've tried to achieve:

  • I wanted to implement it in most popular language, so I selected Javascript.
  • Wanted to show clear separation between proof-of-work and actual chain itself.
  • For proof-of-work I selected floating numbers and hex string matching. Rather than having random string generation or something complicated it allows a simpler implementation that won't irritate your eyes but still shows the difficulty you can achieve.
  • For blockchain I stored everything in memory again for simplicity.
  • No comments! If code can't explain itself I would call it useless.
  • Use everything builtin (no external packages), because you don't need anything else!

I would be more than happy to improve it based upon feedback. Let me know what you think!

Top comments (4)

e4emre profile image

I doubt anyone reading this will understand at all what a blockchain is. It's like asking what's a an apple? You answer by saying "it's a pomme-de-terre in English."
This code doesn't even implement a blockchain... you simply import a pre-made blockchain library.

Try something like:

mjb2kmn profile image
MN Mark

Thanks for this. I've only understood blockchain enough to have a general idea of how it works, this helps me understand it well enough to explain it to others.

Now I'm wondering how close this is to actual implementations; also why on earth people put their money into this...

zohaibility profile image
Zohaib Sibte Hassan

In terms of fundamental concept it should describe core concepts really well; however this is still far from being production ready. I've not implemented stuff like verify and syncing chains across the nodes. If you imagine this chain is distributed across machines around the world it's really hard for someone to do a fake entry in it without really doing a proof of work.

This is expensive for clients mining (or trying to add entry) however it's really cheap to verify it (just look at the proof and proof_claim); which leads to multiple applications including putting virtual currency in it.

leadegroot profile image
Lea de Groot

... have you just gotten us to mine blockchain for you?
Not very nice, but clever.