Create your own blockchain using Python (pt. 0)

Introduction

Guillaume Belanger
3 min readJul 13, 2021

I’ve been reading more and more about cryptocurrencies during the past months but at some point I felt like I needed to get my hands dirty. Like the old Chinese saying goes:

There’s only so much you can read about hammers, at some point you got to smash your fingernail.

I created a series of hands-on tutorials on how to create your own blockchain using Python. The intent is purely educative: by getting your hands dirty and developing your own blockchain you will understand at the lowest level how blockchain technologies work. At the end of this tutorial, the goal is to have a fully working blockchain network.

While this tutorial is meant to be a general overview of blockchain technologies, it is very much influenced by bitcoin. The main reason is that bitcoin is the easiest blockchain to get started with, both because there exists a ton of documentation on the subject (books, articles, youtube videos, etc.) and because most other blockchains are strongly influenced by bitcoin.

Finally, blockchain is first and foremost a technology and this tutorial will focus on this specifically. I will not make statement about its adoption, its price, its future, its social implications or anything else other than technology.

Source Code

All the code you will see in this tutorial is available here:

Each section of the tutorial also has its own git branch that can be accessed here:

  1. The basics
  2. Merkle tree
  3. Transactions and security
  4. Double-entry bookkeeping and UTXO’s
  5. Transaction scripts
  6. The network
  7. New block creation and Proof-of-Work
  8. Incentives and transaction fees
  9. A Distributed Network
  10. Publishing and testing

Requirements

All the examples and source code are done using Python 3.8. Some libraries are sometimes used to facilitate common tasks and the requirements for each section are stored in the requirements.txt file inside of each branch.

Create your own blockchain using Python

--

--

Guillaume Belanger

Guillaume is a software developer from Montreal who writes about bip bop stuff.