Blockchain is arguably one of the most significant and disruptive technologies that came into existence since the inception of the Internet. It’s the core technology behind Bitcoin and other crypto-currencies that drew a lot of attention in the last few years. As its core, a blockchain is a distributed database that allows direct transactions between two parties without the need mining 1 bitcoin equals a central authority. This simple yet powerful concept has great implications for various institutions such as banks, governments and marketplaces, just to name a few.
Any business or organization that relies on a centralized database as a core competitive advantage can potentially be disrupted by blockchain technology. Putting aside all the hype around the price of Bitcoin and other cryptocurrencies, the goal of this blog post is to give you a practical introduction to blockchain technology. Sections 1 and 2 cover some core concepts behind blockchain, while section 3 shows how to implement a blockchain using Python. We will also implement 2 web applications to make it easy for end users to interact with our blockchain. Please note that I’m using Bitcoin here as a medium for explaning the more general technology of “Blockchain”, and most of the concepts described in this post are applicable to other blockchain use cases and crypto-currencies.
Below is an animated gif of the two web apps that we will build in section 3. A Crash Course in Blockchain It all started with a white paper released in 2008 by an unknown person or entity using the name Satoshi Nakamoto. If Alice and Bob use digital money, then the problem gets more complicated. Digital money is in digital form and can be easily duplicated. Bob by email for example, Bob cannot know for sure if Alice has deleted her copy of the file. Alice, Bob and all other participants in the network. This third party is responsible for managing a centralized ledger that keeps track of and validates all the transactions in the network.
The drawback of this solution is that for the system to function, it requires trust in a centralized third party. Bitcoin: A Decentralized Solution for the Double-Spending Problem To solve the double-spending problem, Satoshi proposed a public ledger, i. Bitcoin’s blockchain to keep track of all transactions in the network. Any computer with an internet connection can download a full copy of the blockchain. Cryptographic: Cryptography is used to make sure that the sender owns the bitcoin that she’s trying to send, and to decide how the transactions are added to the blockchain. Immutable: The blockchain can be changed in append only fashion. In other words, transactions can only be added to the blockchain but cannot be deleted or modified.
A special type of participants in the network called miners compete on searching for the solution to a cryptographic puzzle that will allow them to add a block of transactions to Bitcoin’s blockchain. For a person to send or receive bitcoins, she needs to create a bitcoin wallet. A bitcoin wallet stores 2 pieces of information: A private key and a public key. The private key is a secret number that allows the owner to send bitcoin to another user, or spend bitcoins on services that accept them as payment method. The public key is a number that is needed to receive bitcoins. Step 2: Create a bitcoin transaction. Step 3: Broadcast the transaction to Bitcoin’s network.
Once Alice creates the bitcoin transaction, she needs to broadcast this transaction to the entire Bitcoin’s network. Bitcoin’s Blockchain containing the details of the transaction. Step 5: Broadcast the blockchain change to all miners. Once the transaction is confirmed, the miner should broadcast the blockchain change to all miners to make sure that their copies of the blockchain are all in sync.
A Technical Deep Dive on Blockchain The goal of this section is to go deeper into the technical building blocks that power the blockchain. We will cover public key cryptography, hashing functions, mining and security of the blockchain. Public Key Cryptography Public-key cryptography, or asymmetrical cryptography, is any cryptographic system that uses pairs of keys: public keys which may be disseminated widely, and private keys which are known only to the owner. This accomplishes two functions: authentication, where the public key verifies a holder of the paired private key sent the message, and encryption, where only the paired private key holder can decrypt the message encrypted with the public key.
In the case of Bitcoin, ECDSA algorithm is used to generate Bitcoin wallets. Bitcoin address is the wallet’s public key. I recommend this article, if you’re interested in the complete technical details of Bitcoin wallets. To send or receive BTCs, a user starts by generating a wallet which contains a pair of private and public keys. If Alice wants to send Bob some BTCs, she creates a transaction in which she enters both her and Bob’s public keys, and the amount of BTCs she wants to send.
She then sign the transaction using her private key. Hashing Functions and Mining All Bitcoin transactions are grouped in files called blocks. Bitcoin adds a new block of transactions every 10 minutes. Once a new block is added to the blockchain, it becomes immutable and can’t be deleted or modified. For a block to be accepted by the blockchain, it needs to be “mined”.