Learn About Blockchains By Building One

What do we curious Hackaday scribes do when we want to learn about something? First port of call: search the web.

When that something is blockchain technology and we’re looking for an explanation that expands our cursory overview into a more fundamental understanding of the basic principles, there is a problem. It seems that to most people blockchains equate to one thing: cryptocurrencies, and since cryptocurrencies mean MONEY, they then descend into a cultish frenzy surrounded by a little cloud of flying dollar signs. Finding [Daniel van Flymen]’s explanation of the fundamentals of a blockchain in terms of the creation of a simple example chain using Python was thus a breath of fresh air, and provided the required education. Even if he does start the piece by assuming that the reader is yet another cryptocurrency wonk.

We start by creating a simple class to hold all the Python functions, then we are shown a single block. In his example it’s a JSON object, and it contains the payload in the form of a transaction record along with the required proof-of-work and hash. We’re then taken through a very simple proof-of-work algorithm, before being shown how the whole can be implemented as very simple endpoints.

You are not going to launch a cryptocurrency using this code, and indeed that wasn’t our purpose in seeking it out. But if you are curious about the mechanics of a blockchain and are equally tired of evangelists of The Blockchain who claim it will cure all ills but can’t explain it in layman’s terms, then this relatively simple example is for you.

The wrong way to build a blockchain image: Jenny List. #FarmLife.

27 thoughts on “Learn About Blockchains By Building One

  1. One other thing I’m noticing with blockchain is how people think it could be used in all other possible use-cases. Personally I think blockchain itself is not the solution, but the principles thereof (integrity et al) could be implemented within the solutions that -do- fit in the idea.

    Why someone would consider replacing a MySQL database with one beats me, but that’s the question I was raised and prompted my investigation in blockchain. I’d say keep it to contract and currency management only.

    1. The beauty of blockchain is precisely the fact that you don’t need a central DB and you don’t have o trust any of the nodes in the network (i.e., assuming noone runs +50% of the nodes). This is the innovation the technology offers.

      I don’t see the point of playing with a toy blockchain when it would be pretty easy to set up a test ethereum blockchain on your local host to play with.

      1. I’m sure it would be easy to set up an Etherium chain. But the point here isn’t to have a chain as such, but to have the principles explained at a very basic level. So while it’s entirely fair to call it a toy, it is pretty useful in that one respect.

      2. “The beauty of blockchain is precisely the fact that you don’t need a central DB and you don’t have o trust any of the nodes in the network (i.e., assuming noone runs +50% of the nodes). This is the innovation the technology offers.”

        well there in lies the problem, most places where a database is needed there is one entity which controls more than 50% of the nodes. Take health records from a country with universal health-care (it was an example Ive heard where people wanted to use block chain) this makes no sense as the government would want control over every node in that block chain network due to the security and privacy issues, which then negates any of the benefits of the block chain in the first place. Yes you could distribute the block chain across many nodes on their network but then you would need to add extra layers of security on each of those nodes making sure that if one was compromised the attacker couldn’t easily get into another. this then raises the IT costs and it becomes a cost benefit analysis.

        The ideas that are constantly put forth for the uses of the block chain are great and i enjoy the enthusiasm but it seems that no one does a cost benefit analysis before suggesting an idea. But thats a feature of the world we live in where everyone wants to be the first to capitalize on an idea they will rush in on any latest technology without doing a simple feasibility study.

        1. It has never been adequately explained to me precisely how these “private blockchains” will work. Cryptocurrencies rely on the fact that many people and organisations are willing to give CPU time to preserve the integrity of the blockchain, because there’s money in it for them. Without that, you don’t have the “many eyes”.

          (As an aside, I do wonder what the carbon footprint of cryptocurrencies is.)

        2. Actually, I find this really interesting what you say and reflecting something I was also recently thinking about. I mean who ‘really’ cares about currency’s ? But the concept of a ‘distributed database’ is worth billions more.

          Nor, exactly, am I saying it is the ‘best’ concept, but I was arguing about this topic with my sister the other day– Take something ‘simple’ like Javascript, and its rise rather has moved substantially more and more processing ‘off-line’ to the client, away from the data-center. I think only in a ‘dumb way’ has this been for the sake of the ‘client experience’. I mean Javascript can never be ‘proprietary’, but the back end engine of inputs/outputs can. It is rather a matter of ‘off loading’ the computation time.

          At the same time, I am not (exactly) sure this would be a ‘great’ future (Or why am I paying my own compute time to sustain *your* general database ? I think I would be expected to be compensated accordingly.) *But*, this might provide us with a future where (well until those quantum computers are built), we can trust in our personal data without fear of being ‘hacked’.

    1. I was actually talking to someone about this just this past Tuesday. Basically, how does a git repository differ from a blockchain. I may write up a more extensive blog post on this, but some of the more interesting differences that came up (or I thought of after):
      1) A git commit is a hash of the entire state of the filesystem tree, whereas a block in the block chain is a hash of the transactions for that current block. In a block chain, say bitcoin, you have to run through all transactions for a particular address to see if it has enough money to do the current transaction (if the current transaction is a spend). This would be like git storing diffs of every file on commit and having to run through those diffs when checking out a different branch.
      2) Proof of work is very different. Git isn’t a computationally expensive model, by design. This has ramifications for who can “commit” in each system. For blockchain, it’s “who has enough power or is lucky”. For Git, anyone can commit, but only certain people can usually push to remote repo.
      3) Consensus (and access control) is done for most teams by a remote repository in git. That means there’s essentially a social contract in place. For git, violating that social contract either means angry coworkers or your code never gets deployed which usually also leads to angry coworkers. For bitcoin, not following the social contract means others won’t accept your blocks and you’ll be forked out of the system.
      4) Forks (branches) are encouraged in git and made painless. This is because they can be merged back in. In git, a commit can have 0-n parents, but in block chains you have either 0 or 1. I’d be interested in what “merging” would look like for a block chain.

      I feel like there was one more point that was related to block size or something, but I can’t recall the nuances of it.

      1. I see why the confusion would be there though. The main difference is just that python allows single quoted strings (or variables) for keys and values, whereas JSON allows only double quoted strings and no variables. Another minute detail here is that python allows a comma after the last element in a list/dictionary (useful for line by line diffs), but JSON does not.

  2. We have laid the groundwork with blockchain to do the next major task: an internet connected neural network. There are millions of computers working for the blockchain, we should take the opportunity now to develop some neural network software and do some science on a grand scale! We could create the first sentient internet. Each computer can run several hundred neurons easily, and multiply that by the millions that are out there. Let’s do this!

    1. cloud computing isn’t new, we’ve been doing it since 1999 with seti@home and folding@home etc..
      in the case of crypto miners, these are devices (ASIC’s) dedicated to a single task, they are useless at other than the proof of work algorithm they were designed to run.

      1. You are referring to ASICS doing mining and other tasks. I am referring to running a giant neural network, possibly the largest ever. Yes it’s cloud computing, just that it’s contributing to a powerful field of research for AI advancement. The largest neural network is a few billion nodes, while the human brain contains several trillion. This is just one small isolated cluster. If we could borrow a little computation time on all these computer nodes (when idle), we could create a “dynamic cloud neural network” , or DCNN. Imagine several trillion nodes being simulated across several million nodes.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s