How to make a blockchain in python under 15lines of code

Advaith S
2 min readFeb 2, 2022

This blog is going to be help you make a blockchain in the easiest way without the complications of the other tutorials

What:

But first we need to understand what a blockchain is… Imagine a blockchain as a set of boxes that store information and all the boxes are connected like so

Now keeping the info as it is would not be safe so it will be encoded in a format that cannot be decoded. And each box knows the code of the previous box

but if even a small change is there in the boxes information the the code will fully change

So if the first box info change to 234khkj then the next box will have to change its info about the previous box which in turn changes the code of itself changing the code of the next box and so on which will cause an error so the change will be declared illegal and will be cancelled

so this means a box cannot change its info once created so for some new data a new box will be made and a new box can only be made by a valid source that is checked and and approved by all the other boxes. But anyone can change the boxes data with a loop code and get some new code in their box illegally, that is where something called proof of work census comes in to play… think of it as a infinite number of boxes made in our code of the blockchain and this will slow down the process of hacking the blockchain massively. Now think of the boxes as Blocks and the connection as the Chain this is basically wut a Blockchain is.

How:

Making a blockchain is relatively easy with the help of a python package called BlCh

so lets start-

First-

install the package

$pip install blch

Second-

Import necessary modules in a python file

Third-

add blockchain and database in a function

The database contains the information that can be any string

Fourth-

Mine the blocks

Fifth-

Get the blocks!!!!

Thats All!!!!!

You have a blockchain in just 15 lines of code!!

Thank you!!!

please clap..

--

--