Advanced Blockchain Development - Imran Bashir - E-Book

Advanced Blockchain Development E-Book

Imran Bashir

0,0
43,19 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Explore distributed ledger technology, decentralization, and smart contracts and develop real-time decentralized applications with Ethereum and Solidity


Key Features:


Get to grips with the underlying technical principles and implementations of blockchainBuild powerful applications using Ethereum to secure transactions and create smart contractsGain advanced insights into cryptography and cryptocurrencies


Book Description:


Blockchain technology is a distributed ledger with applications in industries such as finance, government, and media. This Learning Path is your guide to building blockchain networks using Ethereum, JavaScript, and Solidity. You will get started by understanding the technical foundations of blockchain technology, including distributed systems, cryptography and how this digital ledger keeps data secure. Further into the chapters, you’ll gain insights into developing applications using Ethereum and Hyperledger. As you build on your knowledge of Ether security, mining , smart contracts, and Solidity, you’ll learn how to create robust and secure applications that run exactly as programmed without being affected by fraud, censorship, or third-party interference. Toward the concluding chapters, you’ll explore how blockchain solutions can be implemented in applications such as IoT apps, in addition to its use in currencies. The Learning Path will also highlight how you can increase blockchain scalability and even discusses the future scope of this fascinating and powerful technology. By the end of this Learning Path, you'll be equipped with the skills you need to tackle pain points encountered in the blockchain life cycle and confidently design and deploy decentralized applications.


This Learning Path includes content from the following Packt products:


Mastering Blockchain - Second Edition by Imran BashirBuilding Blockchain Projects by Narayan Prusty


What you will learn:


Understand why decentralized applications are importantDiscover the mechanisms behind bitcoin and alternative cryptocurrenciesMaster how cryptography is used to secure data with the help of examplesMaintain, monitor, and manage your blockchain solutionsCreate Ethereum walletsExplore research topics and the future scope of blockchain technology


Who this book is for:


This Learning Path is designed for blockchain developers who want to build decentralized applications and smart contracts from scratch using Hyperledger. Basic familiarity with any programming language will be useful to get started with this Learning Path.


Imran Bashir has a master’s degree in information security from Royal Holloway, University of London. He has a background in software development, solution architecture, infrastructure management, and IT service management. He is also a member of the Institute of Electrical and Electronics Engineers (IEEE) and British Computer Society (BCS). Imran has an experience of sixteen years in the public and financial sectors. He worked on large-scale IT projects for public sector before moving to the financial services industry. Since then he has worked in various technical roles for different financial companies in Europe's financial capital, London. Currently, he is working for an investment bank in London. Narayan Prusty is a full-stack developer. He works as a consultant for various start-ups around the world. He has worked on various technologies and programming languages but is very passionate about JavaScript, WordPress, Ethereum, Solr, React, Cordova, MongoDB, and AWS. Apart from consulting for various start-ups, he also runs a blog titled QNimate and a video tutorial site titled QScutter, where he shares information about a lot of the technologies he works on.

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 693

Veröffentlichungsjahr: 2019

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Advanced Blockchain Development

 

 

 

 

 

 

 

Build highly secure, decentralized applications and conduct secure transactions

 

 

 

 

 

 

Imran BashirNarayan Prusty

 

 

 

 

 

 

 

 

BIRMINGHAM - MUMBAI

Advanced Blockchain Development

 

Copyright © 2019 Packt Publishing

 

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors nor Packt Publishing or its dealers and distributors will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavoured to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

First published: May 2019

Production reference: 1200519

Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK.

ISBN 978-1-83882-319-1

www.packtpub.com

 
mapt.io

Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.

Why subscribe?

Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals

Improve your learning with Skill Plans built especially for you

Get a free eBook or video every month

Mapt is fully searchable

Copy and paste, print, and bookmark content

Packt.com

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.packt.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.

At www.packt.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks. 

Contributors

About the authors

Imran Bashir has a master’s degree in information security from Royal Holloway, University of London. He has a background in software development, solution architecture, infrastructure management, and IT service management. He is also a member of the Institute of Electrical and Electronics Engineers (IEEE) and British Computer Society (BCS). Imran has an experience of sixteen years in the public and financial sectors. He worked on large-scale IT projects for public sector before moving to the financial services industry. Since then he has worked in various technical roles for different financial companies in Europe's financial capital, London. Currently, he is working for an investment bank in London.

 

 

 

Narayan Prusty is a full-stack developer. He works as a consultant for various start-ups around the world. He has worked on various technologies and programming languages but is very passionate about JavaScript, WordPress, Ethereum, Solr, React, Cordova, MongoDB, and AWS. Apart from consulting for various start-ups, he also runs a blog titled QNimate (http://qnimate.com) and a video tutorial site titled QScutter (http://qscutter.com), where he shares information about a lot of the technologies he works on.

 

 

 

Packt is searching for authors like you

If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.

Table of Contents

Title Page

Copyright and Credits

Advanced Blockchain Development

About Packt

Why subscribe?

Packt.com

Contributors

About the authors

Packt is searching for authors like you

Preface

Who this book is for

What this book covers

To get the most out of this book

Download the example code files

Download the color images of this book

Conventions used

Get in touch

Reviews

Blockchain 101

The growth of blockchain technology

Distributed systems

The history of blockchain and Bitcoin

Electronic cash

Blockchain

Blockchain defined

Peer-to-peer

Distributed ledger

Cryptographically-secure

Append-only

Updateable via consensus

Generic elements of a blockchain

How blockchain works

How blockchain accumulates blocks

Benefits and limitations of blockchain

Tiers of blockchain technology

Features of a blockchain

Types of blockchain

Distributed ledgers

Distributed Ledger Technology

Public blockchains

Private blockchains

Semiprivate blockchains

Sidechains

Permissioned ledger

Shared ledger

Fully private and proprietary blockchains

Tokenized blockchains

Tokenless blockchains

Consensus

Consensus mechanism

Types of consensus mechanisms

Consensus in blockchain

CAP theorem and blockchain

Summary

Decentralization

Decentralization using blockchain

Methods of decentralization

Disintermediation

Contest-driven decentralization

Routes to decentralization

How to decentralize

The decentralization framework example

Blockchain and full ecosystem decentralization

Storage

Communication

Computing power and decentralization

Smart contracts

Decentralized Organizations

Decentralized Autonomous Organizations

Decentralized Autonomous Corporations

Decentralized Autonomous Societies

Decentralized Applications (DApps)

Requirements of a Decentralized Application

Operations of a DApp

DApp examples

KYC-Chain

OpenBazaar

Lazooz

Platforms for decentralization

Ethereum

MaidSafe

Lisk

Summary

Understanding How Ethereum Works

Overview of Ethereum

Ethereum accounts

Transactions

Consensus

Timestamp

Nonce

Block time

Forking

Genesis block

Ether denominations

Ethereum virtual machine

Gas

Peer discovery

Whisper and Swarm

Geth

Installing geth

OS X

Ubuntu

Windows

JSON-RPC and JavaScript console

Sub-commands and options

Connecting to the mainnet network

Creating a private network

Creating accounts

Mining

Fast synchronization

Ethereum Wallet

Mist

Weaknesses

Sybil attack

51% attack

Serenity

Payment and state channels

Proof-of-stake and casper

Sharding

Summary

Smart Contracts

History

Definition

Ricardian contracts

Smart contract templates

Oracles

Smart Oracles

Deploying smart contracts on a blockchain

The DAO

Summary

Symmetric Cryptography

Working with the OpenSSL command line

Introduction

Mathematics

Set

Group

Field

A finite field

Order

An abelian group

Prime fields

Ring

A cyclic group

Modular arithmetic

Cryptography

Confidentiality

Integrity

Authentication

Entity authentication

Data origin authentication

Non-repudiation

Accountability

Cryptographic primitives

Symmetric cryptography

Stream ciphers

Block ciphers

Block encryption mode

Electronic Code Book

Cipher Block Chaining

Counter mode

Keystream generation mode

Message authentication mode

Cryptographic hash mode

Data Encryption Standard

Advanced Encryption Standard

How AES works

Summary

Public Key Cryptography

Asymmetric cryptography

Integer factorization

Discrete logarithm

Elliptic curves

Public and private keys

RSA

Encryption and decryption using RSA

Elliptic Curve Cryptography

Mathematics behind ECC

Point addition

Point doubling

Discrete logarithm problem in ECC

RSA using OpenSSL

RSA public and private key pair

Private key

Public key

Exploring the public key

Encryption and decryption

Encryption

Decryption

ECC using OpenSSL

ECC private and public key pair

Private key

Private key generation

Hash functions

Compression of arbitrary messages into fixed-length digest

Easy to compute

Preimage resistance

Second preimage resistance

Collision resistance

Message Digest

Secure Hash Algorithms

Design of Secure Hash Algorithms

Design of SHA-256

Design of SHA-3 (Keccak)

OpenSSL example of hash functions

Message Authentication Codes

MACs using block ciphers

Hash-based MACs

Merkle trees

Patricia trees

Distributed Hash Tables

Digital signatures

RSA digital signature algorithm

Sign then encrypt

Encrypt then sign

Elliptic Curve Digital Signature Algorithm

How to generate a digital signature using OpenSSL

ECDSA using OpenSSL

Homomorphic encryption

Signcryption

Zero-Knowledge Proofs

Blind signatures

Encoding schemes

Financial markets and trading

Trading

Exchanges

Orders and order properties

Order management and routing systems

Components of a trade

The underlying instrument

General attributes

Economics

Sales

Counterparty

Trade life cycle

Order anticipators

Market manipulation

Summary

Getting Started with web3.js

Introduction to web3.js

Importing web3.js

Connecting to nodes

The API structure

BigNumber.js

Unit conversion

Retrieving gas price, balance, and transaction details

Sending ether

Working with contracts

Retrieving and listening to contract events

Building a client for an ownership contract

The project structure

Building the backend

Building the frontend

Testing the client

Summary

Introducing Bitcoin

Bitcoin

Bitcoin definition

Bitcoin – a bird's-eye view

Sending a payment to someone

Digital keys and addresses

Private keys in Bitcoin

Public keys in Bitcoin

Addresses in Bitcoin

Base58Check encoding

Vanity addresses

Multisignature addresses

Transactions

The transaction life cycle

Transaction fee

Transaction pools

The transaction data structure

Metadata

Inputs

Outputs

Verification

The script language

Commonly used opcodes

Types of transactions

Coinbase transactions

Contracts

Transaction verification

Transaction malleability

Blockchain

The structure of a block

The structure of a block header

The genesis block

Mining

Tasks of the miners

Mining rewards

Proof of Work (PoW)

The mining algorithm

The hash rate

Mining systems

CPU

GPU

FPGA

ASICs

Mining pools

Summary

Building a Wallet Service

Difference between online and offline wallets

hooked-web3-provider and ethereumjs-tx libraries

What is a hierarchical deterministic wallet?

Introduction to key derivation functions

Introduction to LightWallet

HD derivation path

Building a wallet service

Prerequisites

Project structure

Building the backend

Building the frontend

Testing

Summary

Alternative Coins

Theoretical foundations

Alternatives to Proof of Work

Proof of Storage

Proof of Stake (PoS)

Various stake types

Proof of coinage

Proof of Deposit (PoD)

Proof of Burn

Proof of Activity (PoA)

Nonoutsourceable puzzles

Difficulty adjustment and retargeting algorithms

Kimoto Gravity Well

Dark Gravity Wave

DigiShield

MIDAS

Bitcoin limitations

Privacy and anonymity

Mixing protocols

Third-party mixing protocols

Inherent anonymity

Extended protocols on top of Bitcoin

Colored coins

Counterparty

Development of altcoins

Consensus algorithms

Hashing algorithms

Difficulty adjustment algorithms

Inter-block time

Block rewards

Reward halving rate

Block size and transaction size

Interest rate

Coinage

Total supply of coins

Namecoin

Trading Namecoins

Obtaining Namecoins

Generating Namecoin records

Litecoin

Primecoin

Trading Primecoin

Mining guide

Zcash

Trading Zcash

Mining guide

Address generation

GPU mining

Downloading and compiling nheqminer

Initial Coin Offerings (ICOs)

ERC20 tokens

Summary

Development Tools and Frameworks

Languages

Compilers

Solidity compiler (solc)

Installation on Linux

Installation on macOS

Integrated Development Environments (IDEs)

Remix

Tools and libraries

Node version 7

EthereumJS

Ganache

MetaMask

Truffle

Installation

Contract development and deployment

Writing

Testing

Solidity language

Types

Value types

Boolean

Integers

Address

Literals

Integer literals

String literals

Hexadecimal literals

Enums

Function types

Internal functions

External functions

Reference types

Arrays

Structs

Data location

Mappings

Global variables

Control structures

Events 

Inheritance

Libraries

Functions

Layout of a Solidity source code file

Version pragma

Import

Comments

Summary

Building a Betting App

Introduction to Oraclize

How does it work?

Data sources

Proof of authenticity

Pricing

Getting started with the Oraclize API

Setting the proof type and storage location

Sending queries

Scheduling queries

Custom gas

Callback functions

Parsing helpers

Getting the query price

Encrypting queries

Decrypting the data source

Oraclize web IDE

Working with strings

Building the betting contract

Building a client for the betting contract

Projecting the structure

Building the backend

Building the frontend

Testing the client

Summary

Hyperledger

Projects under Hyperledger

Fabric

Sawtooth Lake

Iroha

Burrow

Indy

Explorer

Cello

Composer

Quilt

Hyperledger as a protocol

The reference architecture

Requirements and design goals of Hyperledger Fabric

The modular approach

Privacy and confidentiality

Scalability

Deterministic transactions

Identity

Auditability

Interoperability

Portability

Rich data queries

Fabric

Hyperledger Fabric

Membership services

Blockchain services

Consensus services

Distributed ledger

The peer to peer protocol

Ledger storage

Chaincode services

Components of the fabric

Peers

Orderer nodes

Clients

Channels

World state database

Transactions

Membership Service Provider (MSP)

Smart contracts

Crypto service provider

Applications on blockchain

Chaincode implementation

The application model

Consensus in Hyperledger Fabric

The transaction life cycle in Hyperledger Fabric

Sawtooth Lake

PoET

Transaction families

Consensus in Sawtooth

The development environment – Sawtooth Lake

Corda

Architecture

State objects

Transactions

Consensus

Flows

Components

Nodes

The permissioning service

Network map service

Notary service

Oracle service

Transactions

Vaults

CorDapp

The development environment – Corda

Summary

Alternative Blockchains

Blockchains

Kadena

Ripple

Transactions

Payments related

Order related

Account and security-related

Interledger

Application layer

Transport layer

Interledger layer

Ledger layer

Stellar

Rootstock

Sidechain

Drivechain

Quorum

Transaction manager

Crypto Enclave

QuorumChain

Network manager

Tezos

Storj

MaidSafe

BigchainDB

MultiChain

Tendermint

Tendermint Core

Tendermint Socket Protocol (TMSP)

Platforms and frameworks

Eris

Summary

Blockchain - Outside of Currencies

Internet of Things

Physical object layer

Device layer

Network layer

Management layer

Application layer

IoT blockchain experiment

First node setup

Raspberry Pi node setup

Installing Node.js

Circuit

Government

Border control

Voting

Citizen identification (ID cards)

Miscellaneous

Health

Finance

Insurance

Post-trade settlement

Financial crime prevention

Media

Summary

Scalability and Other Challenges

Scalability

Network plane

Consensus plane

Storage plane

View plane

Block size increase

Block interval reduction

Invertible Bloom Lookup Tables

Sharding

State channels

Private blockchain

Proof of Stake

Sidechains

Subchains

Tree chains (trees)

Block propagation

Bitcoin-NG

Plasma

Privacy

Indistinguishability Obfuscation

Homomorphic encryption

Zero-Knowledge Proofs

State channels

Secure multiparty computation

Usage of hardware to provide confidentiality

CoinJoin

Confidential transactions

MimbleWimble

Security

Smart contract security

Formal verification and analysis

Oyente tool

Summary

Building a Consortium Blockchain

What is a consortium blockchain?

What is Proof-of-Authority consensus?

Introduction to parity

Understanding how Aura works

Getting parity running

Installing rust

Linux

OS X

Windows

Downloading, installing and running parity

Creating a private network

Creating accounts

Creating a specification file

Launching nodes

Connecting nodes

Permissioning and privacy

Summary

Current Landscape and What's Next

Emerging trends

Application-specific blockchains (ASBCs)

Enterprise-grade blockchains

Private blockchains

Start-ups

Strong research interest

Standardization

Enhancements

Real-world implementations

Consortia

Answers to technical challenges

Convergence

Education of blockchain technology

Employment

Cryptoeconomics

Research in cryptography

New programming languages

Hardware research and development

Research in formal methods and security

Alternatives to blockchains

Interoperability efforts

Blockchain as a Service

Efforts to reduce electricity consumption

Other challenges

Regulation

Dark side

Blockchain research

Smart contracts

Centralization issues

Limitations in cryptographic functions

Consensus algorithms

Scalability

Code obfuscation

Notable projects

Zcash on Ethereum

CollCo

Cello

Qtum

Bitcoin-NG

Solidus

Hawk

Town-Crier

SETLCoin

TEEChan

Falcon

Bletchley

Casper

Miscellaneous tools

Solidity extension for Microsoft Visual Studio

MetaMask

Stratis

Embark

DAPPLE

Meteor

uPort

INFURA

Convergence with other industries

Future

Summary

Other Books You May Enjoy

Leave a review - let other readers know what you think

Preface

Blockchain technology is a distributed ledger with applications in industries such as finance, government, and media. This Learning Path is your guide to building blockchain networks using Ethereum, JavaScript, and Solidity. You will get started by understanding the technical foundations of blockchain technology, including distributed systems, cryptography and how this digital ledger keeps data secure. Further into the chapters, you’ll gain insights into developing applications using Ethereum and Hyperledger. As you build on your knowledge of Ether security, mining , smart contracts, and Solidity, you’ll learn how to create robust and secure applications that run exactly as programmed without being affected by fraud, censorship, or third-party interference. Toward the concluding chapters, you’ll explore how blockchain solutions can be implemented in applications such as IoT apps, in addition to its use in currencies. The book will also highlight how you can increase blockchain scalability and even discusses the future scope of this fascinating and powerful technology. By the end of this Learning Path, you'll be equipped with the skills you need to tackle pain points encountered in the blockchain life cycle and confidently design and deploy decentralized applications. This Learning Path includes content from the following Packt products:

Mastering Blockchain - Second Edition by Imran Bashir

Building Blockchain Projects by Narayan Prusty

Who this book is for

This Learning Path is designed for blockchain developers who want to build decentralized applications and smart contracts from scratch using Hyperledger. Basic familiarity with any programming language will be useful to get started with this course

What this book covers

Chapter 1, Blockchain 101, introduces the basic concepts of distributed computing on which blockchain technology is based. It also covers history, definitions, features, types, and benefits of blockchains along with various consensus mechanisms that are at the core of the blockchain technology.

Chapter 2, Decentralization, covers the concept of decentralization and its relationship with blockchain technology. Various methods and platforms that can be used to decentralize a process or a system have also been introduced.

Chapter 3, Understanding How Ethereum Works, explains how Ethereum works.

Chapter 4, Smart Contracts, provides an in-depth discussion on smart contracts. Topics such as history, the definition of smart contracts, Ricardian contracts, Oracles, and the theoretical aspects of smart contracts are presented in this chapter.

Chapter 5, Symmetric Cryptography, introduces the theoretical foundations of symmetric cryptography, which is necessary to understand how various security services such as confidentiality and integrity are provided.

Chapter 6, Public Key Cryptography, introduces concepts such as public and private keys, digital signatures and hash functions with practical examples. Finally, an introduction to financial markets is also included as there are many interesting use cases for blockchain technology in the financial sector.

Chapter 7, Getting Started with web3.js, introduces web3js and how to import and connect to geth.  It also explains how to use it in Node.js or client-side JavaScript.

Chapter 8, Introducing Bitcoin, covers Bitcoin, the first and largest blockchain. It introduces technical concepts related to bitcoin cryptocurrency in detail.

Chapter 9, Building a Wallet Service, explains how to build a wallet service that users can use to create and manage Ethereum Wallets easily, even offline. We will specifically use the LightWallet library to achieve this.

Chapter 10, Alternative Coins, introduces alternative cryptocurrencies that were introduced after the invention of Bitcoin. It also presents examples of different altcoins, their properties, and how they have been developed and implemented.

Chapter 11, Development Tools and Frameworks, provides a detailed practical introduction to the Solidity programming language and different relevant tools and frameworks that are used for Ethereum development.

Chapter 12, Building a Betting App, explains how to use Oraclize to make HTTP requests from Ethereum smart contracts to access data from the World Wide Web. We will also learn how to access files stored in IPFS, use the strings library to work with strings, and more.

Chapter 13, Hyperledger, presents a discussion about the Hyperledger project from the Linux Foundation, which includes different blockchain projects introduced by its members.

Chapter 14, Alternative Blockchains, introduces alternative blockchain solutions and platforms. It provides technical details and features of alternative blockchains and relevant platforms.

Chapter 15, Blockchain - Outside of Currencies, provides a practical and detailed introduction to applications of blockchain technology in fields others than cryptocurrencies, including Internet of Things, government, media, and finance.

Chapter 16, Scalability and Other Challenges, is dedicated to a discussion of the challenges faced by blockchain technology and how to address them.

Chapter 17, Building a Consortium Blockchain, will discuss consortium blockchain.

Chapter 18, Current Landscape and What's Next, is aimed at providing information about the current landscape, projects, and research efforts related to blockchain technology. Also, some predictions based on the current state of blockchain technology have been made.

To get the most out of this book

You require Windows 7 SP1+, 8, 10 or Mac OS X 10.8+, examples in this book have been developed on Ubuntu 16.04.1 LTS (Xenial) and macOS version 10.13.2. As such, it is recommended to use Ubuntu or any other Unix like system. However, any appropriate operating system, either Windows or Linux, can be used, but examples, especially those related to installation, may need to be changed accordingly.

Examples related to cryptography have been developed using the OpenSSL 1.0.2g 1 Mar 2016 command-line tool.

Ethereum Solidity examples have been developed using Remix IDE, available online at https:/ / remix. ethereum. org

Ethereum Byzantine release is used to develop Ethereum-related examples. At the time of writing, this is the latest version available and can be downloaded from https:/ / www. ethereum. org/ .

Examples related to IoT have been developed using a Raspberry Pi kit by Vilros, but any aapropriate latest model or kit can be used. Specifically, Raspberry Pi 3 Model B V 1.2 has been used to build the hardware example of IoT. Node.js V8.9.3 and npm V5.5.1 have been used to download related packages and run Node js server for IoT examples.

The Truffle framework has been used in some examples of smart contract deployment, and is available at http://truffleframework.com/. Any latest version available via npm should be appropriate.

Download the example code files

You can download the example code files for this book from your account at www.packt.com. If you purchased this book elsewhere, you can visit www.packt.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

Log in or register at

www.packt.com

.

Select the

SUPPORT

tab.

Click on

Code Downloads & Errata

.

Enter the name of the book in the

Search

box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

WinRAR/7-Zip for Windows

Zipeg/iZip/UnRarX for Mac

7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/TrainingByPackt/Advanced-Blockchain-Development .In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalogue of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/9781838823191_ColorImages.pdf

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, mention the book title in the subject of your message and email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packt.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packt.com.

Blockchain 101

If you are reading this book, it is very likely that you alreadyhaveheard about blockchain andhavesome fundamental appreciation of its enormous potential. If not, then let me tell you that this is a technology that has promised to positively alter the existing paradigms of nearly all industries including, but not limited to IT, finance, government, media, medical, and law.

This chapter serves an introduction to blockchain technology, its technical foundations, the theory behind it, and various techniques that have been combined together to build what is known today as blockchain.

In this chapter, we first describe the theoretical foundations of distributed systems. Next, we address the precursors of Bitcoin by which blockchain technology was introduced to the world. Finally, we introduce you to blockchain technology. This approach is a logical way to understanding blockchain technology, as the roots of blockchain are in distributed systems. We will cover a lot of ground quickly here, but don't worry—we will go over a great deal of this material in much greater detail as you move through the book.

The growth of blockchain technology

With the invention of Bitcoin in 2008, the world was introduced to a new concept, which is now likely to revolutionize the whole of society. It is something that promises to have an impact on every industry, including but not limited to the financial sector, government, media, law, and arts. Some describe blockchain as a revolution, whereas another school of thought believes that it is going to be more evolutionary, and it will take many years before any practical benefits of blockchain reach fruition. This thinking is correct to some extent, but in my opinion, the revolution has already begun.

Many prominent organizations all around the world are already writing proofs of concept using blockchain technology, as its disruptive potential has now been fully recognized. However, some organizations are still in the preliminary exploration stage, though they are expected to progress more quickly as the technology matures. It is a technology that has an impact on current technologies too and possesses the ability to change them at a fundamental level.

If we look at the last few years, we notice that in 2013 some ideas started to emerge that suggested usage of blockchain in other areas than cryptocurrencies. Around that time the primary usage of blockchain was cryptocurrencies, and many new coins emerged during that time. The following graph shows a broad-spectrum outline of year wise progression and adaption trend of blockchain technology. Years shown on the x axis indicate the range of time in which a specific phase of blockchain technology falls. Each phase has a name which represents the action and is shown on the x axis starting from the period of IDEAS & THOUGHTS to eventually MATURITY & FURTHER STANDARDIZATION. The y axis shows level of activity, involvement and adoption of blockchain technology. The graph shows that eventually, roughly around 2025 blockchain technology is expected to become mature with a high number of users.

Blockchain technology adoption and maturity

The preceding graph shows that in 2013 IDEAS & THOUGHTS emerged related to other usages of blockchain technology apart from cryptocurrencies. Then in 2014 some RESEARCH & EXPERIMENTATION started which led to PROOF OF CONCEPTS, FURTHER RESEARCH, and full-scale TRIAL PROJECTS between 2015 and 2017. In 2018 we will see REAL WORLD IMPLEMENTATIONS. Already many projects are underway and set to replace existing systems, for example, Australian Securities Exchange (ASX) is soon to become the first organization to replace its legacy clearing and settlement system with blockchain technology.

More information on this topic can be found at https://www.asx.com.au/services/chess-replacement.htm.

It is expected that during 2019 more research will be carried out along with some interest towards regulation and standardization of blockchain technology. After this, production ready projects and off the shelf products utilizing blockchain technology will be available from 2020 and by 2021 mainstream usage of blockchain technology is expected to start. Progress in blockchain technology almost feels like the internet dot-com boom of the late 1990s. More research is expected to continue along with adaption and further maturity of blockchain technology, and finally, in 2025 it is expected that the technology will be mature enough to be used on day to day basis. Please note that the timelines provided in the chart are not strict and can vary as it is quite difficult to predict that when exactly blockchain technology will become mature. This graph is based on the progress made in the recent years and the current climate of research, interest and enthusiasm regarding this technology which suggests that by 2025 blockchain technology is expected to become mature.

Interest in blockchain technology has risen quite significantly over the last few years. Once dismissed as simply geek money from a cryptocurrency point of view, or as something that was just not considered worth pursuing, blockchain is now being researched by the largest companies and organizations around the world. Millions of dollars are being spent to adapt and experiment with this technology. This is evident from recent actions taken by European Union where they have announced plans to increase funding for blockchain research to almost 340 million euros by 2020.

Interested readers can read more about this at https://www.irishtimes.com/business/technology/boost-for-blockchain-research-as-eu-increases-funding-four-fold-1.3383340.

Another report suggests that global spending on blockchain technology research could reach 9.2 billion dollars by 2021.

More information regarding this can be found at https://bitcoinmagazine.com/articles/report-suggests-global-spending-blockchain-tech-could-reach-92-billion-2021/.

There are various consortiums such as Enterprise Ethereum Alliance(EEA), Hyperledger, and R3, which have been established for research and development of blockchain technology. Moreover, a large number of start-ups are providing blockchain-based solutions already. A simple trend search on Google reveals the immense scale of interest in blockchain technology over the last few years. Especially, since early 2017 the increase in the search termblockchainis quite significant, as shown in the following graph:

Google trend graph for blockchain

Various benefits of this technology are envisioned, such as decentralized trust, cost savings, transparency, and efficiency. However, there are multiple challenges too that are an area of active research on blockchain, such as scalability and privacy.

In this book, we are going to see how blockchain technology can help bring about the benefits mentioned earlier. You are going to learn about what exactly is blockchain technology, and how it can reshape businesses, multiple industries, and indeed everyday life by bringing about a plenitude of benefits such as efficiency, cost saving, transparency, and security. We will also explore what is distributed ledger technology, decentralization, and smart contracts and how technology solutions can be developed and implemented using mainstream blockchain platforms such as Ethereum, and Hyperledger. We will also investigate that what challenges need to be addressed before blockchain can become a mainstream technology.

Chapter 16, Scalability and Other Challenges, is dedicated to a discussion of the limitations and challenges of blockchain technology.

Distributed systems

Understanding distributed systems is essential to the understanding of blockchain technology, as blockchain is a distributed system at its core. It is a distributed ledger which can be centralized or decentralized. A blockchain is originally intended to be and is usually used as a decentralized platform. It can be thought of as a system that has properties of both decentralized and distributed paradigms. It is a decentralized-distributed system.

Distributed systems are a computing paradigm whereby two or more nodes work with each other in a coordinated fashion to achieve a common outcome. It is modeled in such a way that end users see it as a single logical platform. For example, Google's search engine is based on a large distributed system, but to a user, it looks like a single, coherent platform.

A node can be defined as an individual player in a distributed system. All nodes are capable of sending and receiving messages to and from each other. Nodes can be honest, faulty, or malicious, and they have memory and a processor. A node that exhibits irrational behavior is also known as a Byzantine node after the Byzantine Generals Problem.

The Byzantine Generals problem In 1982, a thought experiment was proposed by Lamport and others in their research paper, The Byzantine Generals Problem which is available at: https://www.microsoft.com/en-us/research/publication/byzantine-generals-problem/ whereby a group of army generals who lead different parts of the Byzantine army are planning to attack or retreat from a city. The only way of communicating among them is via a messenger. They need to agree to strike at the same time in order to win. The issue is that one or more generals might be traitors who could send a misleading message. Therefore, there is a need for a viable mechanism that allows for agreement among the generals, even in the presence of the treacherous ones, so that the attack can still take place at the same time. As an analogy to distributed systems, the generals can be considered nodes, the traitors as Byzantine (malicious) nodes, and the messenger can be thought of as a channel of communication among the generals. This problem was solved in 1999 by Castro and Liskov who presented the Practical Byzantine Fault Tolerance (PBFT) algorithm, where consensus is reached after a certain number of messages are received containing the same signed content.

This type of inconsistent behavior of Byzantine nodes can be intentionally malicious, which is detrimental to the operation of the network. Any unexpected behavior by a node on the network, whether malicious or not, can be categorized as Byzantine.

A small-scale example of a distributed system is shown in the following diagram. This distributed system has six nodes out of which one (N4) is a Byzantine node leading to possible data inconsistency. L2 is a link that is broken or slow, and this can lead to partition in the network.

Design of a distributed system: N4 is a Byzantine node, L2 is broken or a slow network link

The primary challenge in distributed system design is coordination between nodes and fault tolerance. Even if some of the nodes become faulty or network links break, the distributed system should be able to tolerate this and continue to work to achieve the desired result. This problem has been an active area of distributed system design research for many years, and several algorithms and mechanisms have been proposed to overcome these issues.

Distributed systems are so challenging to design that a hypothesis known as the CAP theorem has been proven, which states that a distributed system cannot have all three of the much-desired properties simultaneously; that is, consistency, availability, and partition tolerance. We will dive into the CAP theorem in more detail later in this chapter.

The history of blockchain and Bitcoin

Blockchain was introduced with the invention of Bitcoin in 2008. Its practical implementation then occurred in 2009. For the purposes of this chapter, it is sufficient to review Bitcoin very briefly, as it will be explored in great depth in Chapter8, Introducing Bitcoin. However, it is essential to refer to Bitcoin because, without it, the history of blockchain is not complete.

Electronic cash

The concept of electronic cash or digital currency is not new. Since the 1980s, e-cash protocols have existed that are based on a model proposed by David Chaum.

Just as understanding the concept of distributed systems is necessary to comprehend blockchain technology, the idea of electronic cash is also essential in order to appreciate the first and astonishingly successful application of blockchain, Bitcoin, or more broadly cryptocurrencies in general.

Two fundamental e-cash system issues need to be addressed: accountability and anonymity.

Accountability is required to ensure that cash is spendable only once (double-spend problem) and that it can only be spent by its rightful owner. Double spend problem arises when same money can be spent twice. As it is quite easy to make copies of digital data, this becomes a big issue in digital currencies as you can make many copies of same digital cash. Anonymity is required to protect users' privacy. As with physical cash, it is almost impossible to trace back spending to the individual who actually paid the money.

David Chaum solved both of these problems during his work in 1980s by using two cryptographic operations, namely blind signatures and secret sharing. These terminologies and related concepts will be discussed in detail in Chapter 5, Symmetric Cryptography and Chapter 6, Public Key Cryptography. For the moment, it is sufficient to say that blind signatures allow for signing a document without actually seeing it, and secret sharing is a concept that enables the detection of double spending, that is using the same e-cash token twice (double spending).

In 2009, the first practical implementation of an electronic cash (e-cash) system named Bitcoin appeared. The term cryptocurrency emerged later. For the very first time, it solved the problem of distributed consensus in a trustless network. It used public key cryptography with a Proof of Work (PoW) mechanism to provide a secure, controlled, and decentralized method of minting digital currency. The key innovation was the idea of an ordered list of blocks composed of transactions and cryptographically secured by the PoW mechanism. This concept will be explained in greater detail in Chapter 8, Introducing Bitcoin.

Other technologies used in Bitcoin, but which existed before its invention, include Merkle trees, hash functions, and hash chains. All these concepts are explained in appropriate depth in Chapter 6, Public Key Cryptography.

Looking at all the technologies mentioned earlier and their relevant history, it is easy to see how concepts from electronic cash schemes and distributed systems were combined to create Bitcoin and what now is known as blockchain. This concept can also be visualized with the help of the following diagram:

The various ideas that supported the invention of Bitcoin and blockchain

Blockchain

In 2008, a groundbreaking paper entitled Bitcoin: A Peer-to-Peer Electronic Cash System was written on the topic of peer-to-peer electronic cash under the pseudonym Satoshi Nakamoto. It introduced the term chain of blocks. No one knows the actual identity of Satoshi Nakamoto. After introducing Bitcoin in 2009, he remained active in the Bitcoin developer community until 2011. He then handed over Bitcoin development to its core developers and simply disappeared. Since then, there has been no communication from him whatsoever, and his existence and identity are shrouded in mystery. The term chain of blocks evolved over the years into the word blockchain.

As stated earlier, blockchain technology incorporates a multitude of applications that can be implemented in various economic sectors. Particularly in the finance sector, significant improvement in the performance of financial transactions and settlements is seen as resulting in desirable time and cost reductions. It is sufficient to say that parts of nearly all economic sectors have already realized the potential and promise of blockchain and have embarked, or will do so soon, on the journey to capitalize on the benefits of blockchain technology.

Blockchain defined

Layman's definition: Blockchain is an ever-growing, secure, shared record keeping system in which each user of the data holds a copy of the records, which can only be updated if all parties involved in a transaction agree to update.Technical definition: Blockchain is a peer-to-peer, distributed ledger that is cryptographically-secure, append-only, immutable (extremely hard to change), and updateable only via consensus or agreement among peers.

Now let's examine the preceding definitions in more detail. We will look at all keywords in the definitions one by one.

Peer-to-peer

The first keyword in the technical definition is peer-to-peer. This means that there is no central controller in the network, and all participants talk to each other directly. This property allows for cash transactions to be exchanged directly among the peers without a third-party involvement, such as by a bank.

Distributed ledger

Dissecting the technical definition further reveals that blockchain is a distributed ledger, which simply means that a ledger is spread across the network among all peers in the network, and each peer holds a copy of the complete ledger.

Cryptographically-secure

Next, we see that this ledger is cryptographically-secure, which means that cryptography has been used to provide security services which make this ledger secure against tampering and misuse. These services include non-repudiation, data integrity, and data origin authentication. You will see how this is achieved later in Chapter 5, Symmetric Cryptography which introduces the fascinating world of cryptography.

Append-only

Another property that we encounter is that blockchain is append-only, which means that data can only be added to the blockchain in time-ordered sequential order. This property implies that once data is added to the blockchain, it is almost impossible to change that data and can be considered practically immutable. Nonetheless, it can be changed in rare scenarios wherein collusion against the blockchain network succeeds in gaining more than 51 percent of the power. There may be some legitimate reasons to change data in the blockchain once it has been added, such as the right to be forgotten or right to erasure (also defined in General Data Protection (GDPR) ruling, https://gdpr-info.eu/art-17-gdpr/).

However, those are individual cases that need to be handled separately and that require an elegant technical solution. For all practical purposes, blockchain is indeed immutable and cannot be changed.

Updateable via consensus

Finally, the most critical attribute of a blockchain is that it is updateable only via consensus. This is what gives it the power of decentralization. In this scenario, no central authority is in control of updating the ledger. Instead, any update made to the blockchain is validated against strict criteria defined by the blockchain protocol and added to the blockchain only after a consensus has been reached among all participating peers/nodes on the network. To achieve consensus, there are various consensus facilitation algorithms which ensure that all parties are in agreement about the final state of the data on the blockchain network and resolutely agree upon it to be true. Consensus algorithms are discussed later in this chapter and throughout the book as appropriate.

Blockchain can be thought of as a layer of a distributed peer-to-peer network running on top of the internet, as can be seen in the following diagram. It is analogous to SMTP, HTTP, or FTP running on top of TCP/IP.

The network view of a blockchain

At the bottom layer in the preceding diagram, there is the internet, which provides a basic communication layer for any network. In this case, a peer-to-peer network runs on top of the internet, which hosts another layer of blockchain. That layer contains transactions, blocks, consensus mechanisms, state machines, and blockchain smart contracts. All of these components are shown as a single logical entity in a box, representing blockchain above the peer-to-peer network. Finally, at the top, there are users or nodes that connect to the blockchain and perform various operations such as consensus, transaction verification, and processing. These concepts will be discussed in detail later in this book.

From a business standpoint, a blockchain can be defined as a platform where peers can exchange value / electronic cash using transactions without the need for a centrally-trusted arbitrator. For example, for cash transfers, banks act as a trusted third party. In financial trading, a central clearing house acts as an arbitrator between two trading parties. This concept is compelling, and once you absorb it, you will realize the enormous potential of blockchain technology. This disintermediation allows blockchain to be a decentralized consensus mechanism where no single authority is in charge of the database. Immediately, you'll see a significant benefit of decentralization here, because if no banks or central clearing houses are required, then it immediately leads to cost savings, faster transaction speeds, and trust.

A block is merely a selection of transactions bundled together and organized logically. A transaction is a record of an event, for example, the event of transferring cash from a sender's account to a beneficiary's account. A block is made up of transactions, and its size varies depending on the type and design of the blockchain in use.

A reference to a previous block is also included in the block unless it is a genesis block. A genesis block is the first block in the blockchain that is hardcoded at the time the blockchain was first started. The structure of a block is also dependent on the type and design of a blockchain. Generally, however, there are just a few attributes that are essential to the functionality of a block: the block header, which is composed of pointer to previous block, the timestamp, nonce, Merkle root, and the block body that contains transactions. There are also other attributes in a block, but generally, the aforementioned components are always available in a block.

A nonce is a number that is generated and used only once. A nonce is used extensively in many cryptographic operations to provide replay protection, authentication, and encryption. In blockchain, it's used in PoW consensus algorithms and for transaction replay protection.

Merkle root is a hash of all of the nodes of a Merkle tree. Merkle trees are widely used to validate the large data structures securely and efficiently. In the blockchain world, Merkle trees are commonly used to allow efficient verification of transactions. Merkle root in a blockchain is present in the block header section of a block, which is the hash of all transactions in a block. This means that verifying only the Merkle root is required to verify all transactions present in the Merkle tree instead of verifying all transactions one by one. We will elaborate further on these concepts in Chapter 6, Public Key Cryptography.

The generic structure of a block.

This preceding structure is a simple block diagram that depicts a block. Specific block structures relative to their blockchain technologies will be discussed later in the book with greater in-depth technical detail.

Generic elements of a blockchain

Now, let's walk through the generic elements of a blockchain. You can use this as a handy reference section if you ever need a reminder about the different parts of a blockchain. More precise elements will be discussed in the context of their respective blockchains in later chapters, for example, the Ethereum blockchain. The structure of a generic blockchain can be visualized with the help of the following diagram:

Generic structure of a blockchain

Elements of a generic blockchain are described here one by one. These are the elements that you will come across in relation to blockchain:

Address

: Addresses are unique identifiers used in a blockchain transaction to denote senders and recipients. An address is usually a public key or derived from a public key. While addresses can be reused by the same user, addresses themselves are unique. In practice, however, a single user may not use the same address again and generate a new one for each transaction. This newly-created address will be unique. Bitcoin is, in fact, a pseudonymous system. End users are usually not directly identifiable, but some research in removing the anonymity of Bitcoin users has shown that they can be identified successfully. A good practice is for users to generate a new address for each transaction in order to avoid linking transactions to the common owner, thus preventing identification.

Transaction

: A transaction is the fundamental unit of a blockchain. A transaction represents a transfer of value from one address to another.

Block

: A block is composed of multiple transactions and other elements, such as the previous block hash (hash pointer), timestamp, and nonce.

Peer-to-peer network

: As the name implies, a peer-to-peer network is a network topology wherein all peers can communicate with each other and send and receive messages.

Scripting or programming language

: Scripts or programs perform various operations on a transaction in order to facilitate various functions. For example, in Bitcoin, transaction scripts are predefined in a language called

Script

, which consist of sets of commands that allow nodes to transfer tokens from one address to another. Script is a limited language, however, in the sense that it only allows essential operations that are necessary for executing transactions, but it does not allow for arbitrary program development. Think of it as a calculator that only supports standard preprogrammed arithmetic operations. As such, Bitcoin script language cannot be called

Turing complete

. In simple words, Turing complete language means that it can perform any computation. It is named after Alan Turing who developed the idea of Turing machine that can run any algorithm however complex. Turing complete languages need loops and branching capability to perform complex computations. Therefore, Bitcoin's scripting language is not Turing complete, whereas Ethereum's Solidity language is.

To facilitate arbitrary program development on a blockchain, Turing complete programming language is needed, and it is now a very desirable feature of blockchains. Think of this as a computer that allows development of any program using programming languages. Nevertheless, the security of such languages is a crucial question and an essential and ongoing research area. We will discuss this in greater detail in Chapter 8, Introducing Bitcoin, Chapter 4, Smart Contracts, and Chapter 11, Development Tools and Frameworks, later in this book.

Virtual machine

: This is an extension of the transaction script introduced earlier. A

virtual machine

allows Turing complete code to be run on a blockchain (as smart contracts); whereas a transaction script is limited in its operation. However, virtual machines are not available on all blockchains. Various blockchains use virtual machines to run programs such as

Ethereum Virtual Machine

(

EVM

) and

Chain Virtual Machine

(

CVM

). EVM is used in Ethereum blockchain, while CVM is a virtual machine developed for and used in an enterprise-grade blockchain called

Chain Core

.

State machine

: A blockchain can be viewed as a state transition mechanism whereby a state is modified from its initial form to the next one and eventually to a final form by nodes on the blockchain network as a result of a transaction execution, validation, and finalization process.

Node

: A node in a blockchain network performs various functions depending on the role that it takes on. A node can propose and validate transactions and perform mining to facilitate consensus and secure the blockchain. This goal is achieved by following a

consensus protocol

(most commonly PoW). Nodes can also perform other functions such as simple payment verification (lightweight nodes), validation, and many other functions depending on the type of the blockchain used and the role assigned to the node. Nodes also perform a transaction signing function. Transactions are first created by nodes and then also digitally signed by nodes using private keys as proof that they are the legitimate owner of the asset that they wish to transfer to someone else on the blockchain network. This asset is usually a token or virtual currency, such as Bitcoin, but it can also be any real-world asset represented on the blockchain by using tokens.

Smart contract

: These programs run on top of the blockchain and encapsulate the business logic to be executed when certain conditions are met. These programs are enforceable and automatically executable. The smart contract feature is not available on all blockchain platforms, but it is now becoming a very desirable feature due to the flexibility and power that it provides to the blockchain applications. Smart contracts have many use cases, including but not limited to identity management, capital markets, trade finance, record management, insurance, and e-governance. Smart contracts will be discussed in more detail in

Chapter 4

,

Smart Contracts

.

How blockchain works

We have now defined and described blockchain. Now let's see how a blockchain actually works. Nodes are either miners who create new blocks and mint cryptocurrency (coins) or block signers who validates and digitally sign the transactions. A critical decision that every blockchain network has to make is to figure out that which node will append the next block to the blockchain. This decision is made using a consensus mechanism. The consensus mechanism will be described later in this chapter.

Now we will look at the how a blockchain validates transactions and creates and adds blocks to grow the blockchain.

How blockchain accumulates blocks

Now we will look at a general scheme for creating blocks. This scheme is presented here to give you a general idea of how blocks are generated and what the relationship is between transactions and blocks:

A node starts a transaction by first creating and then digitally signing it with its private key. A transaction can represent various actions in a blockchain. Most commonly this is a data structure that represents transfer of value between users on the blockchain network. Transaction data structure usually consists of some logic of transfer of value, relevant rules, source and destination addresses, and other validation information. This will be covered in more detail in specific chapters on Bitcoin and Ethereum later in the book.

A transaction is propagated (flooded) by using a flooding protocol, called Gossip protocol, to peers that validate the transaction based on preset criteria. Usually, more than one node are required to verify the transaction.

Once the transaction is validated, it is included in a block, which is then propagated onto the network. At this point, the transaction is considered confirmed.

The newly-created block now becomes part of the ledger, and the next block links itself cryptographically back to this block. This link is a hash pointer. At this stage, the transaction gets its second confirmation and the block gets its first confirmation.

Transactions are then reconfirmed every time a new block is created. Usually, six confirmations in the Bitcoin network are required to consider the transaction final.

It is worth noting that steps 4 and 5 are considered non-compulsory, as the transaction itself is finalized in step 3; however, block confirmation and further transaction reconfirmations, if required, are then carried out in step 4 and step 5.

This completes the basic introduction to blockchain. In the next section, you will learn about the benefits and limitations of this technology.

Benefits and limitations of blockchain

Numerous advantages of blockchain technology have been discussed in many industries and proposed by thought leaders around the world who are participating in the blockchain space. The notable benefits of blockchain technology are as follows:

Decentralization

: This is a core concept and benefit of the blockchain. There is no need for a trusted third party or intermediary to validate transactions; instead, a consensus mechanism is used to agree on the validity of transactions.

Transparency and trust

: Because blockchains are shared and everyone can see what is on the blockchain, this allows the system to be transparent. As a result, trust is established. This is more relevant in scenarios such as the disbursement of funds or benefits where personal discretion in relation to selecting beneficiaries needs to be restricted.

Immutability

: Once the data has been written to the blockchain, it is extremely difficult to change it back. It is not genuinely immutable, but because changing data is so challenging and nearly impossible, this is seen as a benefit to maintaining an immutable ledger of transactions.

High availability

: As the system is based on thousands of nodes in a peer-to-peer network, and the data is replicated and updated on every node, the system becomes highly available. Even if some nodes leave the network or become inaccessible, the network as a whole continues to work, thus making it highly available. This redundancy results in high availability.

Highly secure

: All transactions on a blockchain are cryptographically secured and thus provide network integrity.

Simplification of current paradigms