How to Code a Blockchain in 6 Steps

Ari Cohen
6 min readMay 6, 2022

Build a quick and simple blockchain in Python

What exactly is a blockchain? The best way to understand it is to see one in action , or better yet, to build one. Essentially a blockchain is a way to store data with its history — and a blockchain can be built in any programming language.

I played around with coding a blockchain when I wrote this piece about it being the data innovation showing the value of data lineage. If you’re interested in the background of blockchain and what it has to do with Bitcoin then that’s a good place to start.

Ok, enough talk — here’s the code, step-by-step in Python. To keep it simple we’ll code the blockchain to print to the terminal and I’ll explain each step so you don’t need to know Python to follow along.

If you don’t have Python set up then you can run the steps in an online Python session → here

Step 1 / Put Some Data in a Block

The starting point for a blockchain is actually simple.

A blockchain has blocks like this:
[ ]
With data in them:
[ data ]

--

--

Ari Cohen
Ari Cohen

Written by Ari Cohen

The guy who thinks all life’s answers are in the metadata, hiding. When I do find answers, I share them here | Chief Data Officer

Responses (2)