Reader small image

You're reading from  Blockchain By Example

Product typeBook
Published inNov 2018
Reading LevelBeginner
PublisherPackt
ISBN-139781788475686
Edition1st Edition
Languages
Concepts
Right arrow
Authors (3):
Bellaj Badr
Bellaj Badr
author image
Bellaj Badr

Bellaj Badr is an experienced security and software engineer who loves blockchain with a passion. Currently, he is the CTO at Mchain, a blockchain start-up that develops blockchain solutions for companies. Alongside his role as CTO, he acts as technical consultant, offering strategic and technical consulting to many companies worldwide. Aside from this, he is involved in many blockchain projects involving the establishment of new blockchain business-oriented protocols. Badr is a frequent speaker at developer conferences and is father to two angels.
Read more about Bellaj Badr

Richard Horrocks
Richard Horrocks
author image
Richard Horrocks

Richard Horrocks is a freelance Ethereum and full-stack developer based in the UK, and holds a BA and MSc in natural sciences from the University of Cambridge. He worked for many years as a technical lead for Cisco Systems, where he worked on the operating systems of carrier-grade routing hardware, before leaving the world of IT to work as an English teacher. The advent of cryptocurrency piqued his interest sufficiently to lead him back to IT, and, since 2015, he has been working with Ethereum and other cryptocurrencies. His specialist interests are cryptoeconomics and incentive layers, with a particular focus on mechanism design and token engineering. When not in front of a computer, he enjoys yoga and falling off motorbikes.
Read more about Richard Horrocks

Xun (Brian) Wu
Xun (Brian) Wu
author image
Xun (Brian) Wu

Xun (Brian) Wu is a senior blockchain architect and consultant. With over 20 years of hands-on experience across various technologies, including Blockchain, big data, cloud, AI, systems, and infrastructure, Brian has worked on more than 50 projects in his career. He has authored nine books, which have been published by O'Reilly, Packt, and Apress, focusing on popular fields within the Blockchain industry. The titles of his books include: Learn Ethereum (First Edition), Learn Ethereum (Second Edition), Blockchain for Teens, Hands-On Smart Contract Development with Hyperledger Fabric V2, Hyperledger Cookbook, Blockchain Quick Start Guide, Security Tokens and Stablecoins Quick Start Guide, Blockchain by Example, and Seven NoSQL Databases in a Week.
Read more about Xun (Brian) Wu

View More author details
Right arrow

The emergence of blockchain and cryptocurrency

Many find it hard to understand the logic and the concepts behind blockchain, and why they would need it. This is primarily because we don't have a clear idea what problems it solves, or what advantages it promises.

Therefore, I believe it is necessary to clarify from the start which problems are solved by blockchain. We will start by learning about the concept and history of cryptocurrencies.

From virtual currencies to cryptocurrency

Blockchain didn't appear out of the blue. It was the product of the evolution of fintech and virtual currencies over the last few decades.

At the end of the last century, the widespread use of the internet favored the emergence of digital currencies as an extension of electronic cash systems. Many projects were developed to create new digital currencies: E-cash, E-gold, WebMoney, and Liberty Reserve, to name just a few

Despite huge success in the 1990s, these projects had ceased to exist by the beginning of the new century, either through bankruptcy or being halted by authorities. A currency which is capable of disappearing overnight is a real financial nightmare, but this situation was inevitable due to the centralized nature of such digital currency systems.

There was also always a need for a central authority to be involved, to fight fraud and manage trust within the system.

Because of this fatal weakness, the opposite, decentralized model was presented as a solution. However, it was hard to establish trust in such environments without any central authority. This contrast made creating a reliable digital currency a disentangled Gordian Knot.

Thankfully, the progress of cryptography and the emergence of some clever solutions such as proof of work (for example, the hashcash Project—see http://hashcash.org) brought hope of breaking the deadlock.

The invention of bitcoin

In 2008, Satoshi Nakamoto rose to the challenge and unveiled a digital currency called bitcoin. This new currency effectively harnessed cryptography techniques to manage ownership and to secure the systemhence the name cryptocurrency.

Satoshi solved the aforementioned problems by introducing what he called initially a chain of blocks. In his published whitepaper (see https://bitcoin.org/bitcoin.pdf), he presented his vision for a new peer-to-peer electronic cash systembitcoinand described in detail its underlying machineryblockchain.

Bitcoin was the first reliable and distributed electronic cash system that's fully peer-to-peer, underpinned by the following basic concepts:

  • Encryption to ensure ownership and identity
  • A proof-of-work consensus mechanism for validating transactions and securing the network against double transactions
  • A transparent and shared ledger (a blockchain)
  • Pseudonymity

With the assumption that the network majority (>51%) is honest, the bitcoin system operates autonomously following the rules defined by the protocol (consensus rules) to validate a given transaction. By using a shared blockchain, each player has the ability to check the transaction's log history and the sender's solvency, then vote on whether the proceeded transaction is valid or not.

The voting depends on the overall hash-power the player puts into service to secure the network (initially, one CPU is one vote).

To use a cryptocurrency, users need to install a specific client which creates a wallet, generates cryptographic key pairs (private/public keys), and syncs the blockchain with the network. The public key is used by the client (software) to generate valid addresses, and the funds sent to a given address are controlled by the private key from which the address was calculated. In this way, we rely on secure cryptographic principles to manage ownership.

The following diagram depicts how transactions are processed in bitcoin's peer-to-peer network and added into a blockchain:

In a bitcoin network where users don't know one another, the blockchain is considered the single source of truth to which they refer to learn about previous consensus outcomes. The blockchain with the consensus protocol allows the network to manage transactions without a single point of failure.

What is blockchain?

Often confused with bitcoin, blockchain is the underlying technology used by bitcoin to operate. Concretely, it's an append-only and chronologically (timestamped) growing database, which harnesses basic cryptographic measures to protect stored transactions from being tampered with (in other words, data can't be deleted or altered).

This database, or ledger, collects and records monetary transactions validated by the network in elementary units called blocks. Once validated by the network consensus mechanism, these blocks are added to an existing sequential chain of cryptographic hash-linked blocks, to ensure the integrity of the datahence the name blockchain.

If a single bit changes in one of the linked blocks, the hash-link collapses, the chain is broken, and it will be rejected by the network.

The following diagram shows how the blockchain is replicated and processed by the members of the network to ensure that everyone has a consistent view of the transaction log. When a new block is validated, all nodes synchronize the same copy:

The diagram also shows us that blockchain implements a special data structure, consisting of linked blocks storing transactions and smart contracts. Let us take a closer look at these key elements in detail.

Blocks

If we consider blockchain to be a ledger or a book, a block can be compared to a page or a table in which we record a collection of confirmed transactions. Each block stored in the blockchain is uniquely identified by a hash, and composed of a header and a body.

The header encloses information about its creation (timestamp, Merkle root, Nonce, difficulty target, and version), and a reference to a previous block, whereas the body is a collection of the accepted transactions.

When a block is successfully validated (mined), it becomes part of the official blockchain. New bitcoins are generated in the block (a coinbase transaction) and paid to the validators (or miners).

Transactions

Transactions are the most fundamental building blocks of the blockchain system. They represent the transfer of value (cryptocurrency) within the blockchain network between two addresses.

More tangibly, they are represented by small data structures, defined by the blockchain protocol (such as bitcoin or Ethereum), which specifies their attributes (metadata, inputs, outputs, and so on), and model.

Before broadcasting the transaction, the user sending the funds signs it using their private key (managed by their wallet), and specifies the destination address. Digital signatures and public keys are used to enable network users to validate the transaction, and to check whether the sender has the right to spend the bitcoins held by a specific address.

Smart contracts

Smart contracts are one of the most exciting concepts in blockchain, representing self-executing scripts stored on the blockchain itself. The smart contract takes the blockchain concept to the next stage, enabling it to translate business logic into inviolable contract terms, which will be autonomously executed without relying on a broker, lawyer, or other intermediary.

The earliest form of a smart contract was defined in bitcoin using basic locking and unlocking scripts, but the concept evolved with the emergence of other blockchains.

Smart contracts are one of the more powerful, disruptive forces within blockchain, and are garnering more and more business attention, as described in the Gartner report Why Blockchain’s Smart Contracts Aren’t Ready for the Business World (see https://www.gartner.com/smarterwithgartner/why-blockchains-smart-contracts-arent-ready-for-the-business-world/). Gartner estimates that by 2022, smart contracts will be used by more than 25% of global organizations.

Owing to their importance, we will return later in this book to introduce you to smart contracts in leading blockchain platforms—bitcoin, Ethereum, and Hyperledger.

We have now finished describing the conceptslet's practice a little bit to understand what has been presented so far.

Previous PageNext Page
You have been reading a chapter from
Blockchain By Example
Published in: Nov 2018Publisher: PacktISBN-13: 9781788475686
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (3)

author image
Bellaj Badr

Bellaj Badr is an experienced security and software engineer who loves blockchain with a passion. Currently, he is the CTO at Mchain, a blockchain start-up that develops blockchain solutions for companies. Alongside his role as CTO, he acts as technical consultant, offering strategic and technical consulting to many companies worldwide. Aside from this, he is involved in many blockchain projects involving the establishment of new blockchain business-oriented protocols. Badr is a frequent speaker at developer conferences and is father to two angels.
Read more about Bellaj Badr

author image
Richard Horrocks

Richard Horrocks is a freelance Ethereum and full-stack developer based in the UK, and holds a BA and MSc in natural sciences from the University of Cambridge. He worked for many years as a technical lead for Cisco Systems, where he worked on the operating systems of carrier-grade routing hardware, before leaving the world of IT to work as an English teacher. The advent of cryptocurrency piqued his interest sufficiently to lead him back to IT, and, since 2015, he has been working with Ethereum and other cryptocurrencies. His specialist interests are cryptoeconomics and incentive layers, with a particular focus on mechanism design and token engineering. When not in front of a computer, he enjoys yoga and falling off motorbikes.
Read more about Richard Horrocks

author image
Xun (Brian) Wu

Xun (Brian) Wu is a senior blockchain architect and consultant. With over 20 years of hands-on experience across various technologies, including Blockchain, big data, cloud, AI, systems, and infrastructure, Brian has worked on more than 50 projects in his career. He has authored nine books, which have been published by O'Reilly, Packt, and Apress, focusing on popular fields within the Blockchain industry. The titles of his books include: Learn Ethereum (First Edition), Learn Ethereum (Second Edition), Blockchain for Teens, Hands-On Smart Contract Development with Hyperledger Fabric V2, Hyperledger Cookbook, Blockchain Quick Start Guide, Security Tokens and Stablecoins Quick Start Guide, Blockchain by Example, and Seven NoSQL Databases in a Week.
Read more about Xun (Brian) Wu