This tutorial introduces Python developers, of any programming skill level, to blockchain. You’ll discover exactly what a blockchain is by implementing a public blockchain from scratch and by building a simple application to leverage it.

You’ll be able to create endpoints for different functions of the blockchain using the Flask microframework, and then run the scripts on multiple machines to create a decentralized network. You’ll also see how to build a simple user interface that interacts with the blockchain and stores information for any use case, such as peer-to-peer payments, chatting, or e-commerce.

Python is an easy programming language to understand, so that’s why I’ve chosen it for this tutorial. As you progress through this tutorial, you’ll implement a public blockchain and see it in action. The code for a complete sample application, written using pure Python, is available on GitHub.

Get the code.

Now, to understand blockchain from the ground up, let’s walk through it together.

Prerequisites

  • Basic programming knowledge of Python
  • Knowledge of REST-APIs
  • Familiarity with the Flask microframework (not mandatory, but nice to have)

Background

In 2008, a whitepaper titled Bitcoin: A Peer-to-Peer Electronic Cash System was released by an individual (or maybe a group) named Satoshi Nakamoto. The paper combined several cryptographic techniques and a peer-to-peer network to transfer payments without the involvement of any central authority (like a bank). A cryptocurrency named Bitcoin was born. Apart from Bitcoin, that same paper introduced a distributed system of storing data (now popularly known as “blockchain”), which had far wider applicability than just payments or cryptocurrencies.

Since then, blockchain has attracted interest across nearly every industry. Blockchain is now the underlying technology behind fully digital cryptocurrencies like Bitcoin, distributed computing technologies like Ethereum, and open source frameworks like Hyperledger Fabric, on which the IBM Blockchain Platform is built.

What is “blockchain”?

Blockchain is a way of storing digital data. The data can literally be anything. For Bitcoin, it’s the transactions (logs of transfers of Bitcoin from one account to another), but it can even be files; it doesn’t matter. The data is stored in the form of blocks, which are linked (or chained) together using cryptographic hashes — hence the name “blockchain.”

All of the magic lies in the way this data is stored and added to the blockchain. A blockchain is essentially a linked list that contains ordered data, with a few constraints such as:

  • Blocks can’t be modified once added; in other words, it is append only.
  • There are specific rules for appending data to it.
  • Its architecture is distributed.

Enforcing these constraints yields the following benefits:

  • Immutability and durability of data
  • No single point of control or failure
  • A verifiable audit trail of the order in which data was added

So, how can these constraints achieve these characteristics? We’ll get more into that as we implement this blockchain. Let’s get started.

#python #blockchain #cryptocurenncy #bitcoin

Develop a Blockchain Application from scratch in Python
8.55 GEEK