Foundations of Blockchain
eBook - ePub

Foundations of Blockchain

The pathway to cryptocurrencies and decentralized blockchain applications

  1. 372 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Foundations of Blockchain

The pathway to cryptocurrencies and decentralized blockchain applications

About this book

Learn the foundations of blockchain technology - its core concepts and algorithmic solutions across cryptography, peer-to-peer technology, and game theory.

Key Features

  • Learn the core concepts and foundations of the blockchain and cryptocurrencies
  • Understand the protocols and algorithms behind decentralized applications
  • Master how to architect, build, and optimize blockchain applications

Book Description

Blockchain technology is a combination of three popular concepts: cryptography, peer-to-peer networking, and game theory. This book is for anyone who wants to dive into blockchain from first principles and learn how decentralized applications and cryptocurrencies really work.

This book begins with an overview of blockchain technology, including key definitions, its purposes and characteristics, so you can assess the full potential of blockchain. All essential aspects of cryptography are then presented, as the backbone of blockchain. For readers who want to study the underlying algorithms of blockchain, you'll see Python implementations throughout.

You'll then learn how blockchain architecture can create decentralized applications. You'll see how blockchain achieves decentralization through peer-to-peer networking, and how a simple blockchain can be built in a P2P network. You'll learn how these elements can implement a cryptocurrency such as Bitcoin, and the wider applications of blockchain work through smart contracts. Blockchain optimization techniques, and blockchain security strategies are then presented. To complete this foundation, we consider blockchain applications in the financial and non-financial sectors, and also analyze the future of blockchain. A study of blockchain use cases includes supply chains, payment systems, crowdfunding, and DAOs, which rounds out your foundation in blockchain technology.

What you will learn

  • The core concepts and technical foundations of blockchain
  • The algorithmic principles and solutions that make up blockchain and cryptocurrencies
  • Blockchain cryptography explained in detail
  • How to realize blockchain projects with hands-on Python code
  • How to architect the blockchain and blockchain applications
  • Decentralized application development with MultiChain, NEO, and Ethereum
  • Optimizing and enhancing blockchain performance and security
  • Classical blockchain use cases and how to implement them

Who this book is for

This book is for anyone who wants to dive into blockchain technology from first principles and build a foundational knowledge of blockchain. Familiarity with Python will be helpful if you want to follow how the blockchain protocols are implemented. For readers who are blockchain application developers, most of the applications used in this book can be executed on any platform.

Trusted by 375,005 students

Access to over 1.5 million titles for a fair monthly price.

Study more efficiently using our study tools.

Information

Year
2019
Print ISBN
9781789139396
Edition
1
eBook ISBN
9781789138191

Cryptocurrency

In this chapter, we will explore the original and best implementation of blockchain technology—cryptocurrency. Cryptocurrency is much more than just a blockchain application; it makes use of cryptographic primitives such as digital signatures to achieve asset management by using atomic events called transactions. Throughout this chapter, we will be familiarized with all the concepts required to understand how cryptocurrency is different from any of the traditional digital currencies.
In this chapter, we will cover the following topics:
  • The basics of Bitcoin
  • Keys and addresses
  • Transactions
  • Mining and consensus
  • Blockchain
  • Blockchain networks
  • The creation of a simple cryptocurrency application
Bitcoin was the first successful cryptocurrency to be deployed in a decentralized network. It is the best-known cryptocurrency to date due to its resilient software and infrastructure, widespread adoption in various fields, and high market capitalization. By the end of 2017, Bitcoin had achieved a market cap of 300 billion USD, which is the highest by any cryptocurrency to date. Most of the cryptocurrencies in the market are inspired by and use similar designs to Bitcoin. We will be using Bitcoin to learn about most of the relevant concepts in cryptocurrency, and later on in this chapter, we will also implement a cryptocurrency similar to Bitcoin.
A cryptocurrency is a digital asset that uses cryptography to secure, spend, and verify its value in the transactions. The cryptocurrency could be transferred from the owner to any recipient without the need for an intermediary to settle the transactions. Although the early adoption of cryptocurrency provided a number of features, such as pseudo anonymity, lower transaction fees, and removing the need for an intermediary, it never achieved true decentralization. There were known issues, such as double-spending. This was when a single asset was transferred to multiple recipients because there was no centralized source to verify these transactions. All of these issues were addressed when a completely decentralized cryptocurrency called Bitcoin was created in 2009. This solved the double-spend issue for the first time in a decentralized network by using immutable blockchain to achieve consensus among the nodes.

Bitcoin basics

Bitcoin is a collection of cryptography and decentralized consensus algorithms that enabled the creation of a complete decentralized digital currency ecosystem.
Bitcoin can be used just like conventional currencies. It can be used to buy and sell goods and services or to just transfer money to people. Bitcoin has several advantages over conventional currencies, such as lower transaction costs and the ability to transfer currency to any part of the world, because it is not controlled by any national authorities. Bitcoin is also entirely virtual, meaning there is no physical form of the currency. The value of Bitcoin is generated by transactions in Bitcoin. Anyone can transfer Bitcoin to a particular Bitcoin address using a transaction. The address of the legitimate recipient of the Bitcoin will be identified by a secret key corresponding to the address. The user can then transfer the Bitcoin to others by constructing a new transaction using the secret key. Generally, a Bitcoin address is created using the public key, and the secret key is the private key counterpart of the public key. The keys are generally stored in a software application called a wallet, but they can also be backed up and stored anywhere if we need better security.
As we know, Bitcoin is the system that paved the way for the invention of blockchain. It utilizes all the concepts we have discussed so far to build a cryptocurrency that functions in a completely decentralized peer-to-peer (P2P) system. Because of Bitcoin's completely decentralized network, there is no need for a central trusted authority, such as a bank, to act as a moderator and validate the transactions. Instead, everyone in the Bitcoin ecosystem participates in ensuring that valid transactions take place.
Bitcoin software is open source, and anyone can join the Bitcoin network by running this software on a device such as a smartphone or a computer. A lighter version of the Bitcoin software can be used on devices where the computing and storage capacity is limited. There is a special type of node called a miner, which uses processing power to verify transactions and contributes to the creation of blocks by solving a hard-cryptographic puzzle. This is a hash puzzle, more specifically called the Proof of Work consensus algorithm, which was discussed in Chapter 3, Cryptography in Blockchain. Every 10 minutes, a miner can publish a valid block, which is then propagated and validated by everyone on the Bitcoin network. The miner is rewarded in bitcoin for the computing power spent creating the block. Due to an increase in competition in mining, the difficulty of the puzzle has been adjusted so that the average block creation time remains around 10 minutes.
So, every time the miner creates a new block, new bitcoins are minted, which circulate in the Bitcoin network. There is a limit set on the total number of bitcoins that can circulate in the network, and it is hard-capped to 21 million coins.
To sum up, the following innovations helped Bitcoin to survive in a completely trustless network:
  • A decentralized P2P network
  • A blockchain (public ledger)
  • Decentralized consensus algorithm (Proof of Work)
  • Transaction validation rules
Throughout this chapter, we will try to explain how Bitcoin uses these concepts, which made its creation possible.

Getting started with Bitcoin Core

Bitcoin is an experimental digital currency that is maintained by an open source community. Bitcoin Core is the name of open source software that enables the use of this currency. It's the original implementation of the Bitcoin system and whose initial release was created by Satoshi Nakamoto.
Open source software is software whose source code is made available to the public with the right to read, modify, and redistribute it. Although open source code can be covered by different licenses, most of it is free to use for any purpose. Bitcoin is licensed under the MIT license.

Setting up a Bitcoin full node

A Bitcoin full node can be set up for development purposes, or just to enable a user to be a part of the Bitcoin network in order to validate or explore the transactions. The user has to set up all the tools, libraries, and dependent applications they may need if they want to set up a complete development environment, whereas a Bitcoin node can be set up without much effort just by installing the software.

Installing a Bitcoin full node

As mentioned, installing a Bitcoin full node is much simpler than setting up a development environment. Bitcoin full nodes are ideal for users who want to be a part of the Bitcoin network but don't want to worry about any of its implementations.
Running a Bitcoin full node has certain hardware requirements. It needs dedicated storage because it has to store all the blocks of the public ledger. At the time of writing, Bitcoin blockchain blocks occupy around 180 GB of storage. A Bitcoin full node also needs a decent amount of memory and processing power in order to validate the transactions of every block. Bitcoin can be installed on Linux, macOS, and Windows platforms quite easily.
We will not be providing details about the installation here because it varies from platform to platform. You can find installation details for different platforms in the GitHub repository of the book (https://github.com/PacktPublishing/Foundations-of-Blockchain). Moreover, you can find the installation instructions for all the platforms at https://bitcoin.org/en/full-node.

Compiling from source code

A Bitcoin development environment is set up by compiling the source code obtained from the Bitcoin repository. The source code of Bitcoin Core is hosted in a GitHub repository under the MIT license. You can either clone and fetch all the branches or download the ZIP file of a specific release.
You can clone the Bitcoin Core project from the https://github.com/bitcoin/bitcoin.git repository using the Git tool. Once the project has been cloned, you can either use the latest master code or checkout to any of the release using the Git tag.
The build process might take up to an hour depending on the system's hardware configuration. Compiling the source code involves only a few steps, but they are time-consuming:
  1. As the first step, Bitcoin Core needs you to run a script called autogen.sh, which creates a set of automatic configuration scripts that examine the system and ensure that your system has all the libraries to compile the code. The shell script is executed as follows:
 $ ./autogen.sh
  1. The next step is to use the configure script to customize the build process by enabling or disabling certain features. We can build Bitcoin Core with the default features because most of Bitcoin Core's features are required to set up a node. The configuration script is executed as follows:
 $ ./configure 
  1. Finally, the source code is compiled to create executables and install the created executables. This is achieved using the following commands:
  $ make  $ make install
The installation of will create a binary called bitcoind, which creates the Bitcoin daemon process, and a command-line tool called bitcoin-cli, which is used to invoke Bitcoin APIs to communicate with the local Bitcoin node.

Running the Bitcoin node

The Bitcoin daemon process is created when bitcoind is executed by creating a configuration file. The basic configuration file consists of a username and password for the JSON-RPC interface. There are several options that can be specified while running to Bitcoin node to alter its behavior. These options can also be specified in the configuration file. Execu...

Table of contents

  1. Title Page
  2. Copyright and Credits
  3. About Packt
  4. Contributors
  5. Preface
  6. Introduction
  7. A Bit of Cryptography
  8. Cryptography in Blockchain
  9. Networking in Blockchain
  10. Cryptocurrency
  11. Diving into Blockchain - Proof of Existence
  12. Diving into Blockchain - Proof of Ownership
  13. Blockchain Projects
  14. Blockchain Optimizations and Enhancements
  15. Blockchain Security
  16. When Shouldn't We Use Blockchain?
  17. Blockchain Use Cases
  18. Other Books You May Enjoy

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn how to download books offline
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1.5 million books across 990+ topics, we’ve got you covered! Learn about our mission
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more about Read Aloud
Yes! You can use the Perlego app on both iOS and Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app
Yes, you can access Foundations of Blockchain by Koshik Raj in PDF and/or ePUB format, as well as other popular books in Computer Science & Business Intelligence. We have over 1.5 million books available in our catalogue for you to explore.