Learning to code a blockchain

in #education7 years ago

tl;dr: learn to code a tiny blockchain

I’ve pulled together some good resources from around the web to show you how to code a basic blockchain using only a few lines of code.

This piece also follows on nicely from my previous piece about learning to code. I think learning to code by making a blockchain would also be a good idea. The tutorials here are great if you already know how to code but may be too tricky if you know nothing about coding.

One other piece of advice is that while there is a feel good feeling from copying and pasting the code your level of learning is not as great as writing it yourself. There is definitely something to learn from reading the code, running it, and tweaking it; however, more can be learnt from trying to code it from scratch. Of course, it all takes time.



Python Blockchain In Less Than 50 Lines of Python

One of my favourite articles from 2017 is the one where you learn to write a simple blockchain in under 50 lines of code. The first part of the tutorial (only 47 lines of code) shows you how to make a chain of blocks. It doesn’t include network functionality or a consensus mechanism; however, both pieces of functionality appear in part 2 which arguably makes it a proper cryptocurrency.

From these tutorials you will see that there is a recipe for building a simple blockchain:

1. Define the block structure (in code).
2. Create the code for the genesis block.
3. Create the code that adds the next block in the chain.
4. Create some simple code which pulls the above pieces together.

The more advanced stuff, while necessary for making a proper public permissionless blockchain, isn’t really need to demonstrate the most fundamental building block of the technology.

Part 1: Let’s Build the Tiniest Blockchain

Part 2: Let’s Make the Tiniest Blockchain Bigger

Alternative python blockchain tutorial

A lot of good articles were written in 2017 and it is not possible to mention them all but I did think this alternative piece was worth including here. The end result is similar to that of part 2 above.

Learn Blockchains by Building One



JavaScript blockchain in 200 lines of code.

Another gem from 2017 is this micro blockchain written in JS. While that might sound like an odd choice it is worth remembering that JS is a fairly ubiquitous language which runs in any modern browser. That means there is a lot less hassle testing and running the code. It might not be the quickest, but it shouldn’t be too difficult to learn!

Learning about blockchain by coding a simple one will help to greatly improve one’s understanding. There is a little bit more complexity in this piece than the first turorial which I shared above.

A blockchain in 200 lines of code.

The author also goes into greater depth with his more fully-fleshed out blockchain example on GitHub (it is also arguablly a full cryptocurrency): https://lhartikk.github.io/. There is a lot of depth here and lot of good information to people learn about the lower level technical components of a blockchain and also how to code one.



Hope that was informative and helpful for some people looking to pick up or improve their understanding of blockchain technology and their programming skills.

Comments and suggestions welcome below!

Sort:  

.

awesome sp power bola

Coin Marketplace

STEEM 0.18
TRX 0.13
JST 0.028
BTC 64450.12
ETH 3153.87
USDT 1.00
SBD 2.52