Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Learn Ethereum
Learn Ethereum

Learn Ethereum: A practical guide to help developers set up and run decentralized applications with Ethereum 2.0 , Second Edition

Arrow left icon
Profile Icon Xun (Brian) Wu Profile Icon Dongying Song Profile Icon Zhihong Zou
Arrow right icon
€41.99
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (8 Ratings)
Paperback Aug 2023 814 pages 2nd Edition
eBook
€8.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Xun (Brian) Wu Profile Icon Dongying Song Profile Icon Zhihong Zou
Arrow right icon
€41.99
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (8 Ratings)
Paperback Aug 2023 814 pages 2nd Edition
eBook
€8.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€8.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

Learn Ethereum

Blockchain and Cryptocurrency

It is a common belief that the bankruptcy filed by Lehman Brothers, a Wall Street banking giant, on September 15, 2008, triggered the global financial crisis in 2008-2009. Excessive risk exposure to the subprime mortgage and financial derivative markets by large banks almost brought down the global financial system. The crisis was the ultimate consequence of a fundamental breakdown of trust in the relationship between customers and the financial institutions that should have been serving them.

Shortly after that, Satoshi Nakamoto, a mysterious and anonymous entity, published a whitepaper on October 31, 2008, called Bitcoin: A Peer-to-Peer Electronic Cash System, which is considered the origin of Bitcoin and all cryptocurrencies. Satoshi proposed a completely decentralized approach for Peer-to-Peer (P2P) payment without central banks or intermediaries. He outlined the principles and functions of what would be developed and introduced as Bitcoin in the following year.

The central technology behind his invention is referred to as blockchain and has since evolved well beyond Bitcoin and digital payment. It is now a suite of technologies, forming the foundation of distributed ledgers and cryptocurrency. No one knows who or where Satoshi is, whether it is one individual or a group, but the whitepaper has profoundly changed money, digital and cryptocurrencies, business, and the world. You can learn more about the Bitcoin whitepaper authorship debate at https://www.judiciary.uk/wp-content/uploads/2022/08/Wright-v-McCormack-Judgment.pdf.

The purpose of this book is to help you to understand blockchain technologies, introduce you to the tools and technologies of the Ethereum ecosystem, and get you started with developing smart contracts and end-to-end decentralized applications.

In this chapter, we will start with basic concepts in Bitcoin, Ethereum, cryptocurrency, and blockchain.

In this chapter, we will cover the following topics:

  • Introducing blockchain technology
  • Rehashing cryptography
  • Anatomizing the blockchain consensus mechanism
  • Understanding Bitcoin and cryptocurrency
  • Overview blockchain use cases in the industry and government
  • Ushering in the world of Ethereum

Technical requirements

All of the source code in this book can be found at the following GitHub link: https://github.com/PacktPublishing/Learn-Ethereum-Second-Edition/.

Introducing blockchain technology

You might have heard the parable of the blind men and the elephant. It is a folktale about six blind men’s individual descriptions of the same elephant based on their own perceptions from touching particular parts of the animal, each of them giving very different descriptions of what they think the creature looks like. It highlights the fact that different perspectives can lead to distinct viewpoints, emphasizing the limits of perception and the importance of a complete context.

When Satoshi invented Bitcoin, the fundamental concept of its vision was to build a blockchain, a shared public ledger (longest Proof-of-Work (PoW) chain), that verifies and immutably records all transactions through a decentralized computer network (P2P network) and a consensus mechanism with computational proof. Satoshi thus came up with an elegant solution to the double-spend problem in digital money. A double-spend is an attack where someone tries to spend money in a transaction that isn’t actually available anymore as the money has already been spent.

Blockchain is a new elephant in the digital world. To most of the public, blockchain is nothing but an obscure pseudonym for all cryptocurrencies, including Bitcoin, Ethereum, and more. So, what is blockchain? What does a blockchain look like? How does it work? Where can we use blockchain? Do you need a blockchain? There are many ways to describe a blockchain from different perspectives, but there is no universal definition of a blockchain.

On the contrary, there are prevalent debates over the essential attributes or qualities of a blockchain. It is perceived as a new architecture using existing technologies, the next generation of the internet and web, a future database and distributed shared ledger, the new Napster (a P2P file-sharing system used in the 90s) with a pure decentralized P2P network, a cryptocurrency, a trustless secure transaction system, and so on. In reality, it is all of these. Only by combining all of these perspectives can we understand the whole picture of blockchain technologies and get a sense of the true potential of blockchain.

The following picture illustrates different viewpoints of blockchain technology:

Figure 1.1 – Different viewpoints on blockchain technologies

Figure 1.1 – Different viewpoints on blockchain technologies

So, what is a blockchain anyway? Think of blockchain as a new architecture paradigm and a new trust protocol. It is a computer science primitive forming the foundation of most cryptocurrencies and decentralized applications. It is a P2P transaction model that can enable two parties to transact in a way that is tamper-resistant and cryptographically proven. As the technology behind Bitcoin and other cryptocurrencies, blockchain is an open, distributed ledger that can be simultaneously used and shared within a large, decentralized, publicly accessible network.

In essence, blockchain is a distributed shared ledger technology supported by three pillars, as shown in the following figure; these are P2P networks, cryptography, and a consensus mechanism:

Figure 1.2 – Key components of blockchain

Figure 1.2 – Key components of blockchain

To understand how blockchain works, let’s start with the fundamental concepts and key building blocks of blockchain technologies. Then, we’ll discuss the key differences between centralized, distributed, and decentralized systems. We will then dive into the blockchain data structure and discuss how transactions, blocks, and chains are maintained and how the network reaches a consensus on the state of the chain, as well as how to secure the blockchain with cryptographic technologies.

The following lists the key building blocks of blockchain technologies:

  • Transactions: A transaction is a value transfer between two parties. It could be a transfer of money, tangible assets, or cryptocurrency. Transactions are broadcasted to the blockchain network. They are validated and verified by all nodes and collected into blocks. Once the block reaches a certain depth — in Bitcoin, this is six blocks — those transactions in the block can be considered irreversible.
  • Block: All verified transaction records are collected into a data structure called a block. It has a header and body part, where the header contains a cryptographic hash of the previous block, a timestamp, and a Merkle tree root hash of all transactions in the block. The body is the container of transaction data. A Merkle tree is like the digital fingerprint of transactions in the block, which we will discuss extensively later in this section.
  • The chain of block (blockchain): A blockchain is a linked list of a chain of blocks. Blocks are linked together using a cryptographic hash as the pointer to the previous block.
  • Decentralized P2P network: It is a P2P network in which interconnected nodes share resources between themselves without the use of a central authority or some sort of intermediary.
  • Consensus protocol: The consensus protocol in blockchain is a set of rules that all network nodes will enforce when considering the validity of a block and its transactions. The consensus mechanism is the process used by the network nodes to achieve agreement on the network state. It is a fault-tolerant mechanism to ensure the reliability and integrity of the network.
  • Mining: Mining is the process by which network nodes in blockchain systems add new blocks to the blockchain and get rewarded with crypto-incentives.

In the next section, we will discuss how P2P networks work.

Decentralized P2P networks

To explain how blockchain works, let’s look at the steps involved with the existing business model for completing a simple payment transaction.

A customer, Alice, needs to pay $10 to Bob, who is in a geographically distant region from Alice and happens to have an account in the same bank as Alice. She can make the payment either by visiting a bank branch or using the web. Let’s say she tries to do it online through the bank’s web portal. She will need to authenticate herself using her username and password and then put the transfer order in and wait for the bank system to confirm whether the transaction is completed.

As shown in the following diagram, in order to support such online banking activities in the traditional world, the bank has to establish an identity, access management system, and authenticate Alice’s login credentials. Behind the scenes, the bank needs to develop a bank web portal and a backend system to verify whether Alice has the right account with the bank and has enough money to pay Bob, upon which the bank can transfer $10 out of Alice’s account and put $10 in Bob’s account. The bank has to maintain a ledger to record the details of the transaction in a database and show the balance each person has.

The following diagram shows a centralized bank system model:

Figure 1.3 – Centralized bank system model

Figure 1.3 – Centralized bank system model

As the business grows, customers needs change with it. The traditional brick-and-mortar business model is being replaced by the digital banking and commerce model. This requires technological changes in the bank system too. Banks nowadays deploy a distributed system model to serve the ever-growing needs of their customers.

The following diagram shows the distributed bank system model:

Figure 1.4 – Distributed bank system model

Figure 1.4 – Distributed bank system model

The fundamental issue with the preceding centralized or distributed system model is the risk from single points of failure. Failure could come from malicious network attacks, system failures, or security and privacy breaches; it could come from business failures in the bank itself, which can cause millions of people to lose their homes due to the bankruptcy of big banks during a global financial crisis. It could happen due currency failure, such as the currency collapse in Venezuela, where the lifetime savings of average citizens suddenly became worthless overnight. Also, payments can be blocked due to government censorship.

Satoshi Nakamoto believed that the root problem with the traditional fiat system is all the trust required to make it work. Citizens have to trust the central bank not to devalue the currency. Consumers have to trust the bank to manage their money. But history has shown again and again that this trust is often breached.

Satoshi designed an elegant decentralized P2P electronic cash system, and the technology behind that, blockchain, is the solution, where transactions are maintained in a distributed shared ledger and replicated across a global P2P network. Security and privacy are ensured with cryptographic technologies, and transaction integrity is achieved through a consensus mechanism.

The following diagram shows a decentralized bank system model:

Figure 1.5 – Decentralized bank system model

Figure 1.5 – Decentralized bank system model

As new transactions are made, they are broadcasted to all network nodes, and over time all transactions that have occurred are sequenced together in the public ledger and made available on all replicated network nodes, as shown in the following diagram:

Figure 1.6 – Decentralized public ledger

Figure 1.6 – Decentralized public ledger

Now that we understand the difference between centralized and decentralized models, let’s see how blockchain works.

How does blockchain work?

Using the previous example, as shown in the following diagram, let’s assume Alice wants to buy something from Bob and she agrees to pay Bob 10 bitcoins (BTC):

Figure 1.7 – Money transfer between two parties

Figure 1.7 – Money transfer between two parties

Let’s walk through the high-level processes step by step to demonstrate how blockchain works:

  1. Create blockchain transactions: A transaction is a value transfer between two parties. When Alice sends 10 BTC to Bob, it will create a transaction with one or more inputs and two or more outputs, where the inputs reflect Alice’s account, and the outputs reflect which account(s) Alice intends to transfer to. The transaction is then digitally signed with Alice’s private key and broadcasted to the P2P network. The receiver will use the digital signature to verify the ownership of Alice’s funds. We will discuss digital signatures and cryptographic hash functions in detail in later sections.
  2. Validate the transactions and add to the transaction pool: Once the transaction is submitted to the blockchain network, the bookkeeper node (usually a full node in a P2P network that receives the transactions) will validate it according to protocol rules defined by the blockchain network. If the transaction is valid, the bookkeeper will add it to the transaction pool and relay the transaction to the peers in the network.
  3. Create the candidate blocks: Transactions in the transaction pool are collected into the block periodically. In a Bitcoin network, every 10 minutes, a subset of network nodes, called mining nodes or miners, will collect all valid transactions from the transaction pool and create the candidate blocks. The following diagram shows the structure of a candidate block:
Figure 1.8 – Creation of candidate blocks

Figure 1.8 – Creation of candidate blocks

As illustrated in the preceding diagram, the high-level processes are as follows:

  • The candidate block packages the recent valid transactions into the block structure based on block specifications.
  • For each transaction in the package, it creates a cryptographic hash of the transaction data, recursively calculates the hash out of existing hashes, and creates a Merkle root of all transactions, as depicted in the following diagram:
Figure 1.9 – Merkle tree

Figure 1.9 – Merkle tree

The miner node looks for the latest block on the blockchain and adds its hash to the block header of the candidate block as the reference from the candidate block it intends to link to.

  1. Mine the new block: Once the candidate block is created, the race starts for the chance to add new blocks and win the rewards. The process for such a race is called mining. The winning of the race is determined by the consensus mechanism. We will discuss different consensus mechanisms in later sections. In blockchain systems such as Bitcoin or Ethereum 1.0, the PoW consensus mechanism is applied to mining. Miners will keep trying to find a random number, the nonce in the block header structure, until the hash meets certain challenging conditions. For example, one such challenging condition is, the resulting block hash is smaller than a target number, or in some cases, the hash has a few leading zeros. In practice, every random number has the same chance to win the race, so practically, you can just start a loop through from 1 to 232 until it finds such a nonce, the unique hash meeting the condition. It requires huge CPU hashing power to find such a nonce. The challenging condition, called difficulty, can be adjusted based on the target number or bits in the block header structure. The difficulty in winning the race grows exponentially the smaller the target number is or the fewer bits are in the block header structure.
  2. Add a new block to the blockchain: The first winning node will announce the new block to the rest of the network for verification. Once the block is verified and approved by the majority of the network miners, it will be accepted and becomes the new head of the chain. Since all blocks are chained together by linking the hash to the previous block, any tampering with the ledger becomes impossible since it will require PoW on all previous transitions.

All miners have the chance to solve the puzzle, but only the winning miner has the authority to add the block to the chain and claim the bounty. Once the new block is added to the blockchain, all in-progress miners will stop their mining efforts on the newly added block and start the race again on a new block.

The following diagram summarizes the step-by-step process when new transactions are submitted to the blockchain network:

Figure 1.10 – How blockchain works in one picture

Figure 1.10 – How blockchain works in one picture

Cryptography plays a critical role in maintaining the transaction state in the blockchain and ensuring immutability. Cryptography is not new. In the next section, we will go over some key concepts in cryptography.

Rehashing cryptography

Cryptography is the study of secure communication techniques that prevent third parties or the public from reading private messages and allow only the intended recipient of a message to view its contents. It is the cornerstone of information security, which serves as the basis for delivering secure business applications and services. Modern cryptography concerns itself with the following five objectives of information security:

  • Confidentiality: This is the concept of preventing sensitive data from being accessible by any unauthorized entities
  • Integrity: This means protecting sensitive data from unauthorized changes during transit from one party to another party
  • Authentication: This is the process of ensuring that user identity is truly what the user claims it to be, whether the user is human or a system
  • Authorization: This is the concept of determining what actions an authenticated user is allowed to perform
  • Non-repudiation: When a user performs an action on data, the action must be bound with the user so that it can’t deny performing such actions

Cryptography deals with the design of algorithms for encryption and decryption, which are intended to ensure the secrecy and authenticity of the messages or transactions in question. Let’s start with some key elements in modern cryptography:

  • Encryption: This is the process of converting plain text or data into an unintelligible form, typically using a mathematical algorithm.
  • Decryption: This is the process of reversing encryption, converting an encrypted message back into its original text and data.
  • Hash: This is the process of converting any data block (arbitrary size or message) into a fixed-length hash code. A cryptographic hash function is a deterministic mathematical function performing such a conversion using cryptography, and it always maps to the same result for a given data block.

Cryptography is the linchpin and one of the three pillars of blockchain technology, along with the consensus mechanism and P2P network. It is used in many different forms, including, for example, wallets (for proof of cryptocurrency ownership), transactions (for PoW consensus), and P2P communication. In the following subsections, we will go over key blockchain-related cryptography topics, including public-key cryptography, digital signatures, cryptographic hashing, and Merkle trees.

Public-key cryptography

Public-key cryptography is a form of cryptographic function in which encryption and decryption are performed using two different keys — one public and one private key. They are generated in pairs. It is also called asymmetric cryptography. The public key can be shared with the public, but the private key is meant to be a secret code only known by its owner.

The keys are used in tandem too. Either of the two keys can be used in encryption, with the other one used for decryption. It is computationally improbable to determine the private key given only knowledge of the cryptographic algorithm and the public key.

Public-key cryptography is mostly used to do the following three things:

  • Secure the message transmission between two parties and ensure the confidentiality of messages or data
  • Authenticate the sender and ensure the message is indeed sent from the sender
  • Combine it with the cryptographic hashing function and provide a digital signature on a document before sending it to the receiver

We will go over the first two here and discuss digital signatures in the following section:

  • Public-key cryptography for confidentiality: In this case, as depicted in the following diagram, the receiver’s keys are used to encrypt messages between two parties during transmission. The sender (Alice) uses the receiver’s public key to encrypt a message, and the receiver (Bob), who holds their own private key in secrecy, can decrypt the messages using their private key:
Figure 1.11 – Confidentiality with public key

Figure 1.11 – Confidentiality with public key

  • Public-key cryptography for authentication: In this case, as shown in the following diagram, the sender’s keys are used to authenticate the sender’s message. The sender uses its own private key to encrypt a message before sending it to the intended parties. The receiver can use the sender’s public key to confirm the message’s authenticity and decrypt it. The combination of this approach with the message’s cryptographic hashing function provides a digital signature, which we will discuss in the next section:
Figure 1.12 – Authentication with public key

Figure 1.12 – Authentication with public key

Public-key cryptography is an essential technology underpinning wallets and transactions in the blockchain. We will discuss the Bitcoin wallet in the Understanding Bitcoin and cryptocurrency section.

Cryptographic hash function

A cryptographic hash function is an algorithm used to randomly convert a string of binary data into a condensed representation of a message — a message digest. Its output is called a hash value, digital fingerprint, digest, or checksum. It is deterministic and always results in the same hash value for a given message. It is capable of taking any size of data block and producing a fixed-size hash value that uniquely identifies the original data block. It is a one-way, irreversible function; the only way to recreate the input data is to try a brute-force approach with all possible values to see whether there is a match, which is almost computationally infeasible.

Notable hash functions include MD5, SHA-1, SHA-2 and SHA-3. Although they are still widely in use, MD5 and SHA-1 are cryptographically broken due to collision attacks found in the algorithm, and are thus no longer recommended.

Cryptographic functions have been widely used in blockchain technology, including the following:

  • Merkle trees: As we showed earlier, when a miner node pulls transactions from the transaction pool, it packages them in a block, where the block header has a field referencing the Merkle root of all transactions.
  • Block chaining: Blocks in the blockchain are chained together with a reference to the previous block using a cryptographic hash.
  • PoW: The PoW consensus algorithm itself is a game in solving a cryptographic hash function. We will discuss it in more detail in the Understanding the blockchain consensus mechanism section.

In addition to cryptographic hash functions, digital signatures have been broadly leveraged in blockchain networks too. We will discuss their usage in the next subsection.

Digital signatures

A digital signature is a set of algorithms for determining the authenticity and integrity of digital messages or documents. It assures the recipient that the message was indeed created by the expected sender and that the message was not altered during transmission. The sender cannot deny having sent the message.

When Alice sends a document to Bob, she will follow certain steps to digitally sign the document, as shown in the following diagram:

Figure 1.13 – Digital signature

Figure 1.13 – Digital signature

The steps to digitally sign the document are as follows:

  1. Calculate the message digest of the document Alice wants to send to Bob with a cryptographic hash function, usually any SHA-2 or SHA-3 algorithm.
  2. Encrypt the message digest with Alice’s private key, append the encrypted message digest to the original document, and send the combined message out.
  3. Once Bob receives the combined message from Alice, he will separate the encrypted message digest from the document itself. Bob will use Alice’s public key to decrypt the encrypted message digest.
  4. At the same time, Bob will calculate the message digest of the received document and compare the resulting message digest with the decrypted message digest to see whether there is a match. If yes, Bob is assured that the document originated from Alice without any tampering.

In blockchain, a digital signature is a way to prove ownership of the underlying cryptocurrency or electronic coin. When Alice needs to pay Bob 10 BTC, she will digitally sign a hash of the previous transaction, which can prove that Alice has ownership of the 10 BTC.

In summary, cryptography is one of three foundational pillars in blockchain technology. Public-key cryptography is the basis for blockchain wallets and transactions, and the cryptographic hash function is a key element underpinning the PoW consensus mechanism. A digital signature is used as proof of ownership of electronic coins or cryptocurrency.

In the next section, we will introduce and look at a blockchain consensus mechanism in detail and discuss how cryptography technologies are leveraged to reach consensus among decentralized parties.

Anatomizing a blockchain consensus mechanism

A fundamental problem in large-scale distributed systems is how to achieve overall system reliability in the presence of failures. Systems need to be fault-tolerant. This requires a process for distributed, often heterogeneous systems to reach a consensus and agree on the network state, whether it is a database commit or an action to take. In this section, we will discuss two types of consensus algorithms, PoW and PoS.

What is consensus?

Consensus in a blockchain is the process by which a network of mutually distrusted nodes reaches an agreement on the global state of the chain of blocks. In blockchain, transactions or data are shared and distributed across the network. Every node has the same copy of the blockchain data. Consensus allows all of the network nodes to follow the same rules to validate transactions and add new blocks to the chain, and therefore allows it to maintain uniformity in all copies of a blockchain.

Sometimes, it is also called a consensus mechanism or consensus algorithm. A consensus mechanism focuses on the rules and incentives for the network to reach an agreement. A consensus algorithm is a formal procedure or computer program for solving a consensus problem, based on conducting a sequence of specified actions. It is designed to achieve reliability in a network involving multiple nodes. Consensus algorithms ensure that the next block in a blockchain is fully validated and secured. Multiple kinds of consensus algorithms currently exist, each with different fundamental processes. Different blockchain platforms may implement different consensus mechanisms. In this section, we will focus on the following two popular algorithms, show how they work, and discuss the pros and cons of each mechanism:

  • PoW: This consensus algorithm was first coined and formalized in a 1999 paper by Markus Jakobsson and Ari Juels. It got popularized by Satoshi in the Bitcoin whitepaper. It was commonly adopted by many other blockchains, including Ethereum 1.0. The PoW is the mining process with the purpose of finding an answer to a cryptographic hashing problem. To do so, the miner has to follow the block selection rules to locate the previous block and use the hash from the previous block header, together with the Merkle root of current transactions in the new block, to solve the hashing problem. It requires considerable computations and hashing power. In Bitcoin, block selection rules specify that the longest chain wins.
  • PoS: This consensus algorithm aims to select network nodes to propose new blocks using various combinations of random selection based on their wealth or age (the stake). Instead of miners competing to solve energy-consuming cryptographic hash functions, the network instead uses a pool of validators. Validators are network nodes that are willing to stake their cryptocurrency on the new block that they claim should be added to the public blockchain.

Let us get into the details of how PoW and PoS actually work in the following subsections.

Proof-of-work

Proof-of-work, also referred to as PoW, is the most popular consensus algorithm used by blockchain and cryptocurrencies such as Bitcoin and Ethereum 1.0, each one with its own differences. We will talk about the specific implementation of PoW in Bitcoin and Ethereum in later sections.

How PoW works

PoW, in terms of protocol design, is an intensive computation game among all miners in the network. The problem to be solved is a cryptographic puzzle. Behind the game theory, it is the incentive system that rewards the winners with bitcoins for contributing new blocks into the blockchain. As shown in the following picture, miners collect all pending transactions from the transaction pool and race against each other to solve the cryptographic puzzle. The miner solving the puzzle will create the new block and publish it into the network for verification from other nodes. Once verified, all nodes can add the new block to their own copy of the blockchain:

Figure 1.14 – How PoW works

Figure 1.14 – How PoW works

The cryptographic puzzle that miners race to solve is identifying the value of the nonce. A nonce is an attribute in the block header structure. In the beginning, each miner guesses a number to start with, checking whether the resulting hash value is less than the blockchain specific target. Bitcoin uses the SHA-256 algorithm for this. SHA-256 outputs a fixed-length number. Every number between 0 to 232 has the same chance to solve the puzzle, therefore a practical approach is to loop through from 0 to 232 until a number can meet the criteria, as shown in the following diagram:

Figure 1.15 – PoW mining process

Figure 1.15 – PoW mining process

Once a miner finds the nonce, the results, including the previous block’s hash value, the collection of transactions, the Merkle root of all transactions in the block and the nonce, are broadcasted to the network for verification. Upon being notified, the other nodes from the network automatically check whether the results are valid. If the results are valid, they add the block to their copies of the blockchain, stop the mining work in hand, and move on to the next block.

Targets and difficulty

A target is a blockchain-specific 256-bit number that the network sets up for all miners. The SHA-256 hash of a block’s header — the nonce plus the rest of the block header — must be lower than or equal to the current target for the block to be accepted by the network.

The difficulty of a cryptographic puzzle depends on the number of leading zeros in the target. The lower the target, the more difficult it is to generate a block. Adding leading zeros in the target number will increase the difficulty of finding such a nonce exponentially. As you can imagine, the higher the difficulty setting, the more difficult it will be to evaluate the nonce. Adding one leading zero in the target will reduce by 50% the chance of finding the nonce. The difficulty is decided by the blockchain network itself. The basic rule of thumb is to set the difficulty proportionally to the total effort on the network. If the number of miner nodes doubles, the difficulty will also double. The difficulty is periodically adjusted to keep the block time around the target time. In Bitcoin, it is 10 minutes.

Incentives and rewards

The winner of the cryptographic puzzle usually needs to expend huge amounts of energy and crucial CPU time to find the nonce and win the chance to create new blocks in the blockchain. The reward for such actions depends on the blockchain itself. In the Bitcoin blockchain, the winner is rewarded with Bitcoin, the cryptocurrency of the Bitcoin blockchain.

The PoW consensus is a simple yet reliable mechanism to maintain the state of the blockchain. It is simple to implement. It is a democratic lottery-based system that lets you participate in the game of mining and get the rewards, where every node can join and higher CPU power may not translate into higher rewards. Currently, the winning miner is rewarded with 6.25 BTC for each block created in the Bitcoin blockchain.

Double-spend issues

Satoshi’s original intention in using a PoW mechanism is to solve double-spend issues and ensure the integrity of the global state of the Bitcoin blockchain network. Let’s say Alice sends 10 BTC to Bob, and at the same time or later on she pays Catherine the same 10 BTC. We could end up with the following three situations:

  • The first transaction goes through the PoW and is added to the blockchain when the second transaction is submitted. In this case, the second one will be rejected when miners pull it from the transaction pool and validate it against all parent blocks.
  • Both transactions are submitted simultaneously and both go into the unconfirmed pool of transactions. In this case, only the first transaction gets a confirmation and will be added in the next block. Her second transaction will not be confirmed as per validation rules.
  • Both get confirmed and are added into competing blocks. This happens when miners take both transactions from the pool and put them into competing blocks. The competing blocks form a temporary fork on the blockchain. Whichever transaction gets into the longest chain will be considered valid and spent, and the other one within the block on the short chain will be recycled. When it is reprocessed, it will be rejected since it is already spent. In this case, it may take a few blocks to get the other one recognized as the double-spent one.

Double spend is a technical flaw in all digital currencies prior to Bitcoin, where the same unit of digital currency could potentially be used in transactions multiple times. Bitcoin’s solution in addressing double-spend issues paved the way for Bitcoin to be the true digital currency.

Advantages and disadvantages

However, there are a few drawbacks to the PoW algorithm due to the economic cost of maintaining the blockchain network safety:

  • Energy consumption: PoW consensus, which uses a network of powerful computers to secure the network, is extremely expensive and energy-intensive. Miners need to use specialized hardware with high computing capacity in order to perform mining and get rewards. A large amount of electricity is required to run these mining nodes continuously. Some people also claim these cryptographic hash calculations are useless as they can’t produce any business value. At the end of 2018, the Bitcoin network across the globe used more power than Denmark.
  • Vulnerability: PoW consensus is vulnerable to 51% attacks, which means, in theory, dishonest miners could gain a majority of hashing power and manipulate the blockchain to their advantage.
  • Centralization: Winning a mining game requires specified and expensive hardware, typically an ASIC type of machine. Expenses grow unmanageable, and mining becomes possible only for a small number of sophisticated miners. The consequence of this is a gradual increase in the centralization of the system, as it becomes a game of riches.

On the flip side, it requires huge computing power and electricity to take over the PoW-based blockchain. Therefore, PoW is perceived as an effective way to prevent Denial-of-Service (DoS) and Distributed Denial-of-Service (DdoS) attacks on the blockchain.

Proof-of-stake

As opposed to PoW consensus, where miners are rewarded for solving cryptographic puzzles, in the PoS consensus algorithm, a pool of selected validators each take turns proposing new blocks. The validator is chosen in a deterministic way, depending on its wealth, also defined as a stake. Anyone who deposits their coins as a stake can become a validator. The chance to participate may be proportional to the stakes they put in. Let’s say, Alice, Bob, Catherine, and David stake 40 ether, 30 ether, 20 ether, and 10 ether respectively to participate; they will get a 40%, 30%, 20%, and 10% chance of being selected as the block creator.

The following is how it works in the PoS consensus mechanism:

Figure 1.16 – How PoS works

Figure 1.16 – How PoS works

As shown in the preceding diagram, the blockchain keeps track of a set of validators. Depending on their roles in creating new blocks, sometimes the validator is also called block creator, builder, or proposer. At any time, whenever new blocks need to be created, the blockchain randomly selects a validator. The selected validator verifies the transactions and proposes new blocks for all validators to agree on. New blocks are then voted on by all current validators. Voting power is based on the stake the validator puts in. Whoever proposes invalid transactions, blocks, or votes maliciously, which means they intentionally compromise the integrity of the chain, may lose their stakes. Upon the new blocks being accepted, the block creator can collect the transaction fee as the reward for the work of creating new blocks.

PoS is considered more energy efficient and environmentally friendly compared with the PoW mechanism. It is also perceived as more secure too. It essentially reduces the threat of a 51% attack since malicious validators would need to accumulate more than 50% of the total stakes in order to take over the blockchain network.

Similar to PoW, total decentralization may not be fully possible in the PoS-based public blockchain. This is because a few wealthy nodes can monopolize the stakes in the network. Those who put in more stakes can effectively control most of the voting. Both algorithms are subject to the socio-economic issue of making the rich richer.

PoS is getting more popular these days, due to social economical perspective and scalability limitation of PoW mechanism. Ethereum transitioned to PoS and decommissioned PoW as part of the merge of Ethereum 1.0 and Ethereum 2.0 in September 2022. We will discuss Ethereum 1.0 and 2.0 in more details in the next chapter.

Forking

Earlier, we spoke about the temporary fork that occurs when two competing blocks are added to the blockchain. As shown in the following screenshot, this can continue until the majority of the nodes see the longest chain. Newer blocks will be appended to the longest chain. Blocks added to the shortleaf of the forked chain will be discarded, and those transactions will go back to the transaction pool and will be picked again for reprocessing. Eventually, the blockchain will comprise all conforming blocks, chained together using cryptographic hashes pointing to its ancestor:

Figure 1.17 – Forking in a blockchain

Figure 1.17 – Forking in a blockchain

Just like software development, forking is a common practice in blockchain. Forking takes place when a blockchain bifurcates into two separate paths. The following events, intentionally or accidentally, can trigger a blockchain fork:

  • New features are added, requiring a change in blockchain protocol, such as block size, mining algorithm, and consensus rules
  • Hacking or software bugs
  • A temporary fork occurs when competing for blocks with the same block height

A general forking scenario in a blockchain may look like the following screenshot:

Figure 1.18 – Competing blocks during forking

Figure 1.18 – Competing blocks during forking

Depending on the nature of such events, the actions to fix the issues could be a hard fork or a soft fork or, in the case of a temporary fork, doing nothing and allowing the network to self-heal.

Hard fork

A hard fork happens when radical changes in the blockchain protocol are introduced and it makes historical blocks non-conformant with new protocols or rules. Some are planned. Developers and operators agree with protocol changes and upgrades to new software. Blocks following the old protocol will be rejected, and blocks following the new protocol will become the longest chain moving forward.

But, in some cases, this is controversial and heavily debated in the blockchain community, as was the case with the Bitcoin fork on 6 August 2010 or the fork between Ethereum and Ethereum Classic. In such contentious hard fork cases, as long as miners continue to maintain both the old and new software, the blocks created by the old and new software will diverge into separate blockchains.

The following screenshot illustrates both planned and contentious hard forks:

Figure 1.19 – Hard forks

Figure 1.19 – Hard forks

During a contentious hard fork of blockchain, a new cryptocurrency will be created to fuel the new blockchain. The owner of the existing crypto-assets may stay in the current network or move to the new network. When moving to the new network, they will receive a proportional amount of new cryptocurrency in the new network. Hard forks often create pricing volatility. The conversion rate between the old and new fork may be determined by the market. It is important to know the context and details of a hard fork and understand the crypto-economic impacts of such a fork to both cryptocurrencies in order to take advantage of such sudden and drastic changes.

Once forked, nodes will start with separate paths moving forward. Nodes would need to decide which blockchain network they want to stay in. For example, Bitcoin Cash diverged from Bitcoin due to a disagreement within the Bitcoin community as to how to handle the scalability problem. As a result, Bitcoin Cash became its own chain and shares the transaction history from the genesis block up to the forking point. As of May 23, 2022, Bitcoin Cash’s market cap is around $3.67 billion, ranking twenty-fourth, versus Bitcoin’s $556 billion.

Soft fork

A soft fork, by contrast, is any change of rules that is backward-compatible between two versions of the software and the blocks. It goes both ways. In the soft fork case, existing historical blocks are still considered valid blocks by the new software. At the same time, the new blocks created through new software can still be recognized as valid ones by the old software. In the decentralized network, not all nodes upgrade their software at the same time. Nodes staying with an older version of the blockchain software continue creating new blocks using the older software. Nodes upgraded to the newer version of blockchain software will create new blocks using new software. Eventually, when the majority of the network hashing capacity upgrades to a newer version of the software, in theory more blocks will be created with the newer version and make it the longest chain. Nodes with older software can still create new blocks. Since it is not in the longest chain, as illustrated in the following screenshot, similar to the temporary fork case, these blocks will soon be overtaken by the new chain:

Figure 1.20 – Soft fork in progress

Figure 1.20 – Soft fork in progress

Where more nodes are stuck on the older version, as illustrated in the following screenshot, new blocks created from an older version of blockchain software may become longer and longer; it will take a while for the new software to be effective:

Figure 1.21 – Soft fork at the end

Figure 1.21 – Soft fork at the end

So far, you have learned how PoW and PoS work. We have analyzed the advantages and disadvantages of different consensus mechanisms. In the next section, we will help you understand what Bitcoin and cryptocurrency are and discuss how blockchain technology applies to Bitcoin.

Understanding Bitcoin and cryptocurrency

Blockchain is the technology behind Bitcoin, which is considered the origin of all cryptocurrencies. In this section, we will introduce the basics of Bitcoin and discuss the digital payment mechanism with Bitcoin.

Bitcoin basics

Bitcoin is a decentralized electronic cash system that makes peer-to-peer payment possible without going through an intermediary. The original Bitcoin software was developed by Satoshi Nakamoto, released under the MIT license in 2009, following the Bitcoin whitepaper, Bitcoin: A Peer-to-Peer Electronic Cash System. Bitcoin is the first successful implementation of a distributed cryptocurrency. Thirteen years after Bitcoin was born, as of May 23, 2022, it has about 19 million Bitcoins in circulation and it has reached about a 556 billion market cap (https://coinmarketcap.com/currencies/bitcoin/).

Like any fiat currencies or tangible assets, the price of Bitcoins can fluctuate over time and its valuation is determined by the open market. Several factors can influence the price, including supply and demand on the market, competing cryptocurrencies and altcoins, and governance and regulations. The following screenshot shows the Bitcoin market cap, daily transaction volume, and price movement since its inception up to May 23, 2022:

Figure 1.22 – Bitcoin market cap

Figure 1.22 – Bitcoin market cap

In this section, we will present key concepts in Bitcoin, including the wallet, transaction and account balances, Bitcoin supply, and bootstrap. We will demonstrate how Bitcoin payments work with blockchain. We will also discuss major challenges in Bitcoin and the Bitcoin blockchain. Finally, we also briefly talk about various altcoins, different types of cryptocurrency on the market.

What is a wallet?

Bitcoin is a cryptocurrency, digital cash, or virtual money. Unlike a fiat currency, you can’t touch or feel it. You can’t stash Bitcoins under your bed. So, where do you store your Bitcoins? How do you prove ownership of the Bitcoins? Technically, Bitcoins aren’t stored anywhere. They don’t exist in any physical form. They are a set of software objects circulating around the Bitcoin network, where ownership of the Bitcoin is proved with a cryptographic key. Payment records detailing money being transferred in or out of people’s wallets are recorded as a chain of private keys showing ownership transfer in the blockchain. If you own the private keys, you own that Bitcoin. If you lose your keys, you lose everything you have on the Bitcoin network.

A Bitcoin wallet is an application where the cryptographic keys, that is, pairs of public and private keys, are stored. There are many forms of Bitcoin wallets in use, as shown in the following diagram, but broadly, they are categorized into the following four types: desktop, mobile, web, and hardware wallets. Hardware wallets are considered cold wallets, while the rest are considered hot wallets. We have an extensive discussion on crypto wallets in Chapter 14, Build Ethereum Wallets:

Figure 1.23 – Types of Bitcoin wallets

Figure 1.23 – Types of Bitcoin wallets

Your private key is used by you to digitally sign the transaction when you spend some Bitcoin. Anyone who knows your public key can verify your signature on the payment you make to them. The public key — or more accurately, a wallet address associated with your public key — is used by anyone else to pay Bitcoin to you. You can have as many pairs of public and private keys as you want in your wallet.

In Bitcoin, a private key is a 256-bit-long hash and a public key is 512 bits long. They can be converted into shorter lengths in a hexadecimal representation. A Bitcoin address is generated based on the public key, using multiple rounds of mixed use of the SHA-256 and RIPEMD-160 cryptographic hash functions. You can have as many addresses as you need, and each address can be used once for each Bitcoin transaction.

The following screenshot gives an example of a Bitcoin wallet generated from the website at https://www.bitaddress.org/bitaddress.org-v3.3.0-SHA256-dec17c07685e1870960903d8f58090475b25af946fe95a734f88408cef4aa194.html:

Figure 1.24 – Bitcoin wallet

Figure 1.24 – Bitcoin wallet

The QR code on the left side is the Bitcoin address you can share with your trading partners. The secret one, the QR code on the right, is your private key with which you sign your transaction.

Transactions, UTXO, and account balances

Whenever you check your bank account, you always see a balance associated with your checking or savings accounts. Your bank keeps track of all of your transactions and updates your balances following each and every transaction. A Bitcoin wallet provides you with a balance too. However, the balance in Bitcoin is not that straightforward. Instead of keeping track of every transaction, Bitcoin keeps track of unspent coins, also called UTXO.

UTXO stands for unspent transaction output. In Bitcoin, a transaction is a collection of inputs and outputs transferring the ownership of bitcoins between payer and payee. Inputs instruct the network which coin or coins the payment will draw from. Those coins in the inputs have to be unspent, which means they have not been used to pay someone else. Outputs provide the spendable amounts of bitcoins that the payer agrees to pay to the payees. Once the transaction is made, the outputs become the unspent amounts to the payee; they remain unspent until the current payee pays someone else with the coin.

Taking the earlier example where Alice needs to pay Bob 10 BTCs, let’s assume, prior to this transaction, that Alice has two UTXOs in her wallet, one with 5 BTCs and another with 8 BTCs. Bob has one UTXO of 30 BTCs in his wallet from other transactions. Let’s also ignore the transaction fee for now. When Alice uses both UTXOs as the input to pay 10 BTCs to Bob, both will be the inputs of the transaction. One 10 BTC UTXO will be created as output to Bob, and one 3 BTC UTXO will be returned to Alice. After the transaction, Alice will have one 3 BTC UTXO in her account, and Bob will have two UTXOs in his account. They remain as UTXOs until they are used to pay for other transactions:

Figure 1.25 – How UTXOs work

Figure 1.25 – How UTXOs work

When either Alice or Bob pays someone with the remaining UTXOs, the unspent output from the previous transaction becomes an input to the new transaction. Since all transactions are digitally signed, essentially a Bitcoin becomes a chain of digital signatures on the Bitcoin blockchain network.

In fact, the blockchain is a state machine that records all transactions on an immutable ledger. Each UTXO can be ultimately traced back to the original coins that were mined by miners, which in turn can be traced back to the first set of bitcoins on the first block. Piecing together all the transactions that have occurred on the Bitcoin blockchain, from the genesis block to all blocks on the blockchain, you would see Bitcoins changing hands as in the following directed acyclic graph:

Figure 1.26 – UTXO in a directed acyclic graph

Figure 1.26 – UTXO in a directed acyclic graph

To count the number of UTXO transactions or the total amount of unspent bitcoins, you have to count the number of leaf UTXOs, and the total amounts of bitcoins in the leaf UTXOs. To count how much bitcoin you have in your own wallet, all you need to do is add all unspent bitcoins in all leaf UTXOs where you are specified as the payee in the transaction outputs.

Genesis block and coin supply

In Bitcoin, there is no central authority to issue the cryptocurrency and control the money supply. Instead, Bitcoin is created by the Bitcoin blockchain network through the discovery of new blocks. As shown in the following screenshot, the first block is also called the genesis block, or block #0, which was mined on June 3, 2009, with an output of 50 BTC. The first 50 BTC is not spendable.

The following screenshot shows the genesis block in the Bitcoin blockchain:

Figure 1.27 – Genesis block

Figure 1.27 – Genesis block

Source: https://www.blockchain.com/btc/block/000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f

Bitcoin uses a Bitcoin generation algorithm to control how many coins will be minted and at what rate. It is a function of the Bitcoin block height and its block reward. It started with a block reward of 50 BTC. The block reward is cut in half for every 210,000 blocks, or approximately every four years. The rate of block creation is adjusted based on mining difficulty. The maximum capacity of Bitcoins in the system is 21 million, which can be reached when 6,929,999 blocks have been mined.

For more information, you should check out the Bitcoin wiki site: https://en.Bitcoin.it/wiki/Controlled_supply.

How does Bitcoin payment work?

Take the earlier example when Alice needs to pay Bob 10 BTC. Alice opens her Bitcoin wallet, scans or copies Bob’s transaction address, and creates a transaction with a 10 BTC payment to Bob. Once the transaction is digitally signed and submitted, it is sent to the Bitcoin blockchain network:

Figure 1.28 – How Bitcoin payment works

Figure 1.28 – How Bitcoin payment works

Once the transaction is broadcasted to the Bitcoin network, the bookkeeper node, usually a full node in a P2P network that receives the transactions, will validate it according to Bitcoin protocol rules. If the transaction is valid, the bookkeeper will add it to the transaction pool and relay the transaction to the peers in the network. In the Bitcoin network, every 10 minutes, a subset of network nodes, called mining nodes or miners, will collect all valid transactions from the transaction pool and create the candidate blocks. They also create a Coinbase transaction for themselves to be rewarded by collecting the transaction fees in the event they win the mining race and add the block to the chain. All nodes will verify the new block and add it to their own copies of the blockchain. Magically, Bob will be able to see the payment from Alice and 10 BTC in his wallet.

Bitcoin transaction and block structure

When creating a Bitcoin transaction, the wallet application has to follow the Bitcoin protocol rules and create the transaction data structure in line with the Bitcoin specification. Invalid transactions will be rejected by the network. For details of the Bitcoin transaction and block structure, please refer to https://en.Bitcoin.it/wiki/.

The following are key data structures in a Bitcoin transaction and block:

  • Bitcoin block structure: The following table shows the data structure within a Bitcoin block:
Figure 1.29 – Bitcoin block structure

Figure 1.29 – Bitcoin block structure

  • Block header structure: The following table shows the data structure for a block header:
Figure 1.30 – Bitcoin header structure

Figure 1.30 – Bitcoin header structure

In particular, hashPrevBlock references the 256-bit hash value of the previous block, and hashMerkleRoot is the hash Merkle root of all transactions in the block, including the Coinbase transactions. And the nonce is the magic number that miners need to find so that the SHA-256 hash value of the block header is smaller than or equal to the blockchain-defined specific target.

  • Transaction structure in Bitcoin: The following screenshot shows the general data structure of a Bitcoin transaction:
Figure 1.31 – Bitcoin transaction structure

Figure 1.31 – Bitcoin transaction structure

A transaction can have many inputs and outputs, as specified in the field of list of inputs and list of outputs fields. The input structure is shown as follows:

Figure 1.32 – Transaction inputs in a Bitcoin transaction

Figure 1.32 – Transaction inputs in a Bitcoin transaction

The following table shows the structure for the output:

Figure 1.33 – Transaction outputs in a Bitcoin transaction

Figure 1.33 – Transaction outputs in a Bitcoin transaction

Now, you understand transaction and block data structure. In the next subsection, let us see how transactions are processed in a blockchain network.

Transaction validation and block verification

Bitcoin protocol rules define a set of validation rules, including syntactic rules and valid values. Bookkeepers, or miner nodes, need to validate transactions according to those rules before the transaction is added to the pool. It also checks the following (https://en.Bitcoin.it/wiki/Protocol_rules):

  • Transaction duplication: This is to see whether we have matching transactions in the transaction pool or in a block in the main branch
  • Double spend: This is to check whether the input is used to pay concurrently in any other transactions in the pool or in the main branch
  • Orphan transaction: For each input, this checks whether we can find the reference output transaction in the main branch and the transaction pool
  • Coinbase maturity: This is to make sure coins from the Coinbase transaction are mature enough to be spent
  • Overdraft: This checks the inputs and outputs to make sure there is enough to make the payment and be able to make a reasonable transaction fee

Once a miner completes a new block with the mining, the new block will be broadcasted to the Bitcoin network for verification. Each full node, including mining nodes, will verify the new block and all transactions within the block. The same set of transaction validation rules will be applied. For block verification, all nodes check whether the block has the right cryptographic hash and the nonce makes the hash smaller than the target. The miner will add the block to the longest chain. As we discussed earlier, temporary forking may happen; a Bitcoin block tends to self-heal and only the blocks in the longest chain will stay.

Limitations in Bitcoin

Thanks to Bitcoin, blockchain technology has attracted worldwide attention. Like any new technology, it has its limitations. Notable limitations include the following:

  • Scalability and throughput: Scalability is a major concern in the Bitcoin network, and more broadly in any PoW-based blockchain. By design, every transaction has to be verified by all nodes, and it takes about an average of 10 minutes to create a new block with the block size limited to 1 MB. Block size and frequency limitations further constrain the network’s throughput.
  • Transaction processing cost: Mining in the Bitcoin network is costly and energy intensive. The miners who add new blocks to the blockchain are rewarded with bitcoins. As the bitcoin supply gets closer to the maximum capacity of 21 M bitcoins, mining becomes less profitable. Miners will rely more and more on transaction fees to offset the mining cost and make a profit. It will drastically increase the transaction cost in Bitcoin. Please refer to https://Bitcoinfees.info for real-time transaction fees in the Bitcoin network.
  • Security and privacy: Bitcoin has the 51% attack issue. At least in theory, network could be compromised if the majority of CPU hashing power is controlled by dishonest miners. It may not be economically feasible to launch such an attack on the main Bitcoin network. But recently, at least five cryptocurrencies with much smaller networks have been hit with attacks of this type. By design, all transactions are permanently stored in the Bitcoin network and can be traced to the involved parties. They are made public. This greatly improves transparency, however, unfortunately, also raises privacy concerns.
  • Usability: Bitcoin uses a stack-based scripting system for transaction processing. It supports very rudimental operations and lacks the functionalities of modern programming languages. It is Turing-incomplete and inhibits the ability to build more sophisticated real-world business and payment applications.
  • Finality: Transaction finality refers to the moment that blockchain transactions are considered complete and can no longer be reverted. In a PoW-based blockchain system such as Bitcoin, the blockchain goes with the longest chain, therefore there is no immediate finality. The deeper in the chain a given block becomes, the more likely it is that the transactions in the block will be finalized. In Bitcoin, transaction finality is probabilistic. It is believed that it takes 6 blocks to be considered as safe and final, which means about 60 minutes.

By design, if you lose your private keys, you lose access to your bitcoins. In the same way, if your private keys are compromised by hackers, they can take possession of your bitcoins and make any transactions they wish. To address this issue and some accompanying security concerns, Bitcoin introduced multiple signatures (multisig) in 2014 to allow multiple keys to be used to authorize one single Bitcoin transaction. Bitcoin Core has been using Elliptic Curve Digital Signature Algorithm or ECDSA as its cryptographic algorithm for digital signatures from day one, when it was distributed by Satoshi in 2009. As shown in the following diagram, three payors, Alice, Kyle, and Sam, each need to sign the transaction with their own keys. All three digital signatures need to be added to the transaction when they pay Bob some bitcoins together:

Figure 1.34 – Multisig in Bitcoin transactions

Figure 1.34 – Multisig in Bitcoin transactions

The latest update to Bitcoin Core in 2021 was the Taproot upgrade, designed to further address privacy concerns and improve scalability and throughput. The Taproot upgrade leverages Schnorr signatures as a replacement for the ECDSA schema when signing transactions, and introduces a Merklized Abstract Syntax Tree (MAST) schema to aggregate multiple signatures into one Schnorr signature for multisig transactions, as shown in the following screenshot:

Figure 1.35 – Schnorr signature in Bitcoin transactions

Figure 1.35 – Schnorr signature in Bitcoin transactions

Schnorr signatures are much more efficient in signing and verification than the ECDSA schema, and require less data to be transmitted within the P2P network and stored on the blockchain, which in turn makes the Bitcoin blockchain more efficient, secure, and scalable. With the Taproot upgrade, you no longer need to expose all your public keys when making multi-signature Bitcoin transactions.

Note

For more information, you should check out the Bitcoin wiki site: https://en.bitcoin.it/wiki/Taproot_activation_proposals.

Altcoins

Altcoins are cryptocurrencies other than Bitcoin. Some earlier altcoins, such as Litecoin, are variations of Bitcoin with changes and improvements implemented to address some of the particular limitations we discussed in the previous section. Some, including Ethereum, BNB Chain, Cardano, and Solana, are intended as new blockchain platforms for building decentralized applications. According to http://coinmarketcap.com, the following are the top ten altcoins based on the market cap, as of May 23, 2022:

Figure 1.36 – Top 10 altcoins

Figure 1.36 – Top 10 altcoins

Compared with the top 10 altcoins published in 2019 in the first edition of this book, Bitcoin and Ethereum continue to stay as the top two crypto coins. XRP and Cardano also remain in the top 10, but the other 6 were nowhere to be seen back in 2019, although their market caps now range from $10 billion to $73 billion. Bitcoin variants such as Litecoin or Bitcoin Cash declined to #18 and #24, respectively.

The following is a list of leading altcoins:

  • Ethereum: This is one of the best-known smart contract platforms that enables Decentralized Applications (DApps). It was invented by Vitalik Buterin in 2013. Ether is the native currency of the Ethereum platform and uses the symbol ETH. It comes with the Ethereum Virtual Machine (EVM) to enable smart contract execution on the Ethereum blockchain. We will dive into the details of Ethereum throughout the rest of this book.
  • XRP: XRP is a native cryptocurrency that powers the XRP ledger, enabling value transfers in the Ripple network. Unlike Bitcoin or Ethereum, all XRP tokens were pre-minted at the beginning. The XRP Ledger (XRPL) is a decentralized public blockchain that maintains the order and sequence of all XRP transactions. It doesn’t use PoW or PoS. Instead, in the XRP consensus protocol, designated servers reach an agreement on outstanding transactions every 3-5 seconds. All transactions are made public, with strong cryptography to guarantee the integrity of the system.
  • BNB Chain: Similar to Ethereum, BNB Chain is another smart contract-enabled blockchain platform intended to create a Decentralized Finance (DeFi) ecosystem. It is EVM compatible, which means you can deploy Ethereum smart contracts on the Binance chain and vice versa. Instead of using PoW as in Bitcoin or PoS consensus as in Ethereum 2.0, it operates using a Proof-of-Authority (PoA) consensus mechanism. The native token of BNB Chain is the BNB coin. We will discuss in detail how BNB Chain and other EVM-compatible blockchains work in Chapter 4, EVM-Compatible Blockchain Networks.
  • Solana: Solana is another native blockchain platform created for supporting smart contracts and DApps. It uses the SOL symbol. Different than other blockchain platforms, Solana uses a combination of the PoS consensus mechanism and a Proof-of-History (PoH) algorithm to ensure network security and the accurate recording of transaction sequences on the blockchain. We will briefly introduce the Solana blockchain in Chapter 5, Deep Research and Latest Developments in Ethereum.
  • Litecoin: This is almost identical to Bitcoin except that the time for adding a new block was reduced from 10 minutes to 2 minutes.
  • Bitcoin Cash: This is a hard fork of the Bitcoin chain that was created because of a group of Bitcoin Core developers that wanted to use a different way of addressing the scalability issue.

Blockchain technology will continue to evolve. As blockchain finds more usages in industry, more advanced blockchain networks and newer altcoins will continue to rise to the top. In the next section, we will showcase some of the influential blockchain use cases across all industries.

Overview of blockchain use cases in the industry and government

Since its invention in 2009, blockchain has garnered great interest across industry worldwide. It is considered a disruptive technology that has unsettled financial services, banking, and the payment industry and continues to fundamentally change the way business is conducted in all other industries. It has found great success in all traditional industries, as well as in governments around the world. As the world desperately searches for ways to get out of the tangled web of the Web2 world and explore unchartered paths on a voyage into the digital future, it is blockchain that ushers in the unknown metaverse and the world of Web3.

In this section, we will showcase a few successful use cases of blockchain technology in industry and government.

Financial services

Blockchain started as a peer-to-peer electronic payments solution, and quickly found broad success in the financial services, banking, and payment industries. Decentralized Finance (DeFi) is a collective term for financial instruments created on top of distributed ledger technology and blockchain, which replicate all traditional financial instruments in the digital world using cryptocurrencies and smart contracts. It created a world in the digital and crypto space parallel to the real, traditional world of financial services to which we have been accustomed for the last few hundred years – and it offered more. Today, DeFi products and services range from crypto asset management, lending and borrowing, and DeFi exchange, to sophisticated risk management products such as derivatives, insurance, and more. Bridges between traditional finance and DeFi are built to provide blockchain and smart contract solutions to traditional financial institutions to enable them to diversify and expose themselves to the crypto markets.

You will learn more about blockchain, smart contracts, and cryptocurrency throughout the rest of this book. In particular, we will delve into DeFi use cases and the leading protocols in Chapter 3, Decentralized Finance.

Payments

There are great opportunities in the payment market due to its size. According to the McKinsey on Payments in 2021 report, covering the trends and opportunities in the global payments space, more than three quarters of Americans are using some form of digital payments. Digital payments constitute 78% of all payments. McKinsey’s survey of executives from leading banks found that leveraging blockchain and distributed ledger technologies to support the digitization of supply chain financing is one of the technology trends they observed.

Blockchain-enabled models further support banks in offering frictionless real-time payments with lower costs. Ripple came into the picture as early as 2012 with the intention to make a dent in the inter-bank money transfer system. This space has traditionally been dominated by the Society for Worldwide Interbank Financial Telecommunication, better known by its acronym SWIFT. That year, Ripple Labs Inc. released a real-time gross settlement system, including a currency exchange and remittance network. RippleNet provides a service to send money globally by connecting banks, payment providers, and digital asset exchanges. To transfer funds between banks, RippleNet uses its native XRP tokens and guarantees fast and secure settlements. As of February 2023, this payment network involves 55 countries and hosts over 120 currency pairs. More than 100 financial institutions worldwide have joined its payment network.

Ripple is not the only blockchain-based payment service. Mastercard and the blockchain company R3 announced a partnership to produce a cross-border payment solution in September 2019. China Construction Bank also developed a blockchain solution enabling supply-chain financing for cross-border payments with the aim of reducing settlement time.

We expect that companies with objectives such as financial inclusion, consumer protection, and regulatory compliance will continue to leverage blockchain and other emerging technologies, and work together towards the same goal, a noble goal of offering a global currency and robust, secure infrastructure to empower the lives of people all over the world.

Audit and assurance

During an audit, an organization’s financial statements are evaluated to determine their accuracy and fairness. If all the transactions are recorded in an immutable blockchain as indelible marks, audits will become redundant. However, there is still the chance that blockchain transactions could be logged in the wrong sections of financial statements, or a transaction itself may be illegal if, say, it’s sent and received between parties that might not comply with regulations. In some cases, it can even be sent as an off-chain agreement.

Internationally, the audit market is dominated by big players such as Price Waterhouse Coopers (PwC), KPMG, Ernst & Young (EY), and Deloitte. All of them are bringing in blockchain innovations.

PwC announced a blockchain auditing service in March 2018. PwC France and Francophone Africa brought together experts specialized in cybersecurity, big data, and audits in its blockchain lab, located in Paris. The lab collaborated with Request Network, which is a project that’s building a decentralized payment system for the Ethereum network.

KPMG, partnered with Microsoft, has expanded its blockchain strategy for audits. Microsoft Azure’s hybrid cloud capabilities, security at an enterprise level, and extensive compliance certification portfolio were combined by KPMG to break down complex business workflows. The first joint blockchain nodes opened in Frankfurt and Singapore as early as February 2017.

By April 2018, EY had announced its blockchain analyzer to make the lives of audit teams easier in sourcing all transaction data across an organization from multiple ledgers on the blockchain. May 2022 saw the production release of the third generation of EY Blockchain Analyzer: Reconciler, being made available for the first time to non-audit clients. It enables the auditors and non-audit users to do the following:

  • Import enterprise records
  • Reconcile off-chain enterprise records with on-chain transactions
  • Track wallet balances

In 2017, Deloitte released 90,000 certificates on the private blockchain, with an international accredited registrar DNV GL. How does this work? As soon as a new certificate is issued, it will be digitized and stored in a private blockchain. In this private network, each certificate is tagged uniquely and can be traced. Simply scanning a QR code makes it possible for anyone to verify that a company is certified.

Blockchain technology also brings new challenges to auditing and assurance. The chaos from Initial Coin Offerings (ICOs) and Initial Token Offerings (ITOs), which we will talk in Chapter 3, Decentralized Finance, as well as the security and audit issues in smart contracts, will make auditing and assurance of DeFi companies and the transparency and accountability of cryptocurrency much harder to achieve. The dramatic crash of Terra/Luna demonstrates that it requires a different level of expertise that audit and assurance firms have to build. Lack of regulatory clarity on how crypto assets are audited will ultimately only hurt the average Joe.

Healthcare

Healthcare is another industry that has strived to find ways to maintain health quality and lower overall costs. Blockchain has the potential to disrupt the entire industry.

COVID-19 contact tracing

The COVID-19 pandemic is an ongoing global pandemic of a coronavirus disease caused by severe acute respiratory syndrome coronavirus 2 (SARS-CoV-2). Since early 2020, it has overwhelmed healthcare systems and disrupted people’s lives around the world. Beyond vaccines, the best way to slow down the rate of infection is social distancing and contact tracing.

IBM developed a digital health pass using blockchain, like a health passport, to track and selectively share individual COVID-19 status so that it can help to control the spread of the disease. It allows organizations to verify the health credentials of those they have interacted with or do business with. With privacy built into the tools, it enables individuals to manage their health information through an encrypted digital wallet on their smartphones and maintain control of who it is shared with and for what purpose.

As published on HealthIT.gov in the middle of 2020, Villanova University developed a blockchain solution to help medical facilities track coronavirus cases globally. The system enables medical facilities around the world to publish coronavirus test results between doctors on a blockchain. Assisted by technologies such as the Internet of Things (IoT) and Artificial Intelligence (AI), the system triggers alerts about potential surges of COVID-19 cases based on high-risk gatherings and public space surveys. These alerts enable healthcare providers to make data-driven decisions in allocating medical staff and equipment already in short supply.

Tech Mahindra developed a vaccine ledger using blockchain technology to track COVID-19 vaccines from manufacturers to the recipients, with the intention of preventing counterfeits. As a result, vaccine distribution becomes safer and more reliable, especially during initial outbreaks, where the scarcity of authentic vaccines may drive price gauging and the spread of counterfeits. Similarly, Novartis, a global health company, has been exploring the potential of blockchain for pharmaceutics and developing drug tracking systems using blockchain to combat counterfeits and black-market medicine.

Electronic medical records

Blockchain in healthcare can help improve medical record access and sharing. Anthem, the largest health plan in the BlueCross BlueShield system and the second largest health insurer in the United States, is using blockchain technology to allow secure data access and sharing of its members’ medical records. It started as a pilot in 2019 and expects to roll out this feature to all 40 million members.

Medical claim adjudication and payment

Several leading healthcare payor and provider organizations are working together to explore the potential of taking advantage of blockchain to improve the efficiency of administrative processes with the goal of bending curve in the administrative cost in healthcare ecosystem. Anthem, together with Health Care Service Corporation (HCSC), another of the largest insurers in the BlueCross BlueShield system, shared other party liability information over blockchain and made it to all parties, which in turn removes friction and the possibility of erroneous manual processing from coordination of benefit during the claim adjudication.

A group of top healthcare heavyweights, including Anthem, HCSC, and Aetna, together with IBM, initiated a blockchain healthcare network with the intention to tackle various healthcare industry challenges, including efficiency and end-to-end visibility in claims processing and payments, as well as provider data accuracy. Not coincidently, United Healthcare, Humana, and Change Healthcare are also piloting blockchain solutions with another group of health organizations, initially focusing on addressing provider data quality issues using distributed ledger technology. Provider data accuracy and quality are prevailing industry challenges that cost the healthcare industry billions of dollars in administrative expenses each year.

Providence St. Joseph Health, one of the leading not-for-profit healthcare systems, is focusing on building an integrated provider-payer system on a blockchain platform to streamline claims processing and interoperability among all parties, and improve revenue cycle efficiency. One of the successful use cases is to utilize blockchain technology and shared ledgers to improve prior authorization processes, a complex process that often infuriates providers and doctors due to erroneous denials of medical services, increasing friction between providers and healthcare payors.

Blockchain use cases led by government

Governments around the world have leveraged blockchain technology to improve service provision to citizens in their countries. In this section, we will discuss some of the prominent blockchain use cases implemented in the public sector.

Food safety initiatives

Believe it or not, the food industry is leading the blockchain adoption. The FDA is taking a new approach to food safety. In the New Era of Smarter Food Safety blueprint, announced in July 2020, the FDA laid out its technology heavy approaches for creating a safer, more digital and traceable food system, including tech-enable traceability and smarter tools for prevention and outbreak response. In its blueprint, it plans to tap into new technologies, like blockchain and Internet of Things (IoT), for maintaining records and tracking events from growing to the food on the table.

In fact, there are many such food safety tracking implementations already on blockchain. Walmart, partnering with IBM and Nestle, implemented a supply chain food tracking system using Hyperledger, a permissioned blockchain, as early as 2018. It tracks the journey of fresh produce from farms to grocery stores. Agricultural conglomerate Cargill Inc. is leveraging blockchain technology to track its Thanksgiving turkeys from the store they were sold in back to the farm that raised them. In a similar way, Nestle, the Swiss multinational food and drink processing conglomerate, is harnessing blockchain technology for baby food safety. It allows the consumer to simply scan a QR code to track items such as organic infant formula, baby food, and instant mashed potatoes from the manufacturer to the grocery store shelf.

The immutable and auditable nature of blockchain transaction records make it best suited for supply chain tracking. From the top 50 blockchain use cases reported by Forbes in the last 3 years, it is no wonder that supply chain tracking using blockchain has been applied in almost every industry. For example, AP Moller Maersk, a Danish shipping company, is using Hyperledger to track shipping containers during ocean and inland freight transportation. Breitling, the luxury watchmaker, has built a Ethereum-based blockchain system to track and prove the authenticity of its products. De Beers, the diamond producer, and LVMH, the world leader in high-quality luxury products, are also using blockchain technology to track products, prove authenticity, and fight counterfeiting.

Blockchain finds its way in driving positive changes in Environment, Social, and Governance (ESG) issues and supporting ESG’s mission for a sustainable future too. Mining giant BHP developed blockchain solutions to document emission data and trace its carbon footprint. Other use cases have been implemented by Industrial and Commercial Bank of China (ICBC) to track and incentivize energy-efficient vehicle usage by connecting ICBC customer wallets to government transportation data via blockchain.

Smart city ambitions

The smart city concept is not new. A smart city is a technologically modern physical infrastructure that integrates and leverages information, communication, and network technology to optimize city operations and services for its residences. With the advent of blockchain, 5G, IoT, and AI/Machine Learning (ML), interpretations of the smart city concept have expanded. Modern smart cities use different types of IoT devices and sensors to collect specific data from citizens, devices, buildings, assets, and every element of city operations, and leverage 5G networks to efficiently transmit and share this data. AI/ML technology is used to gain insights and drive efficiency in managing assets, resources, and services, improving operations across the city. Blockchain is expected to be used as an immutable and shared ledger to facilitate frictionless data exchange.

One such ambition is Saudi Arabia’s $500 billion smart city project, NEOM, which intends to build a cognitive city and hyperconnected infrastructure from scratch. Advanced technology plays a key role in ensuring efficient and smart operations in cities. Blockchain and smart contracts will be used to manage instantaneous transactions and financial payments. It will enable network participants to exchange data with a high degree of reliability and transparency. If this has gotten you interested, you can check https://www.neom.com/en-us for any new developments.

Central bank-issued digital currency

A central bank-issued digital currency (CBDC) is a digital form of central bank money that is widely available to the public. It is also viewed as the digital form of fiat money. Although the US has not decided whether or when it will issue a CDBC yet, the Federal Reserve has recognized the benefits of CDBCs and is exploring the implications and options for issuing a US CDBC, sometimes also called a digital dollar. In its Money and Payments: The U.S. Dollar in the Age of Digital Transformation report published in January 2022, the Federal Reserve made it clear that it considers CDBCs to be a digitized version of fiat currency, and an expansion to the existing fiat currency, not intended to reduce or replace it.

Due to the widespread use of Bitcoin and other cryptocurrencies, central banks around the globe face the same dilemma. As tracked by the Atlantic Council’s Geoeconomics Center, 9 out 91 countries on the tracking list have launched their own CDBCs, including the Bahamas, Nigeria, and seven eastern Caribbean countries. 15 countries are piloting CDBCs, including China, Singapore, Russia, and South Korea. 16 countries are in the development stage of their own CDBCs. The US is one of 40 countries still in the research stage.

China’s Central Bank released a pilot version of its digital yuan wallet in April 2021 and has expanded the pilot to more than 11 regions as of February 2023. Although the US is behind the other top central banks, including the EU, UK, and Japan, a number of technological experiments related to digital currencies have already been conducted in the US, including a hypothetical CBDC and the use of distributed ledger technology for wholesale payments. Research on economic and policy, stakeholder engagement and outreach activities, and international collaboration are underway to help the Fed reach a decision about the appropriateness of issuing a US CBDC.

Powering many blockchain implementations of the use cases in the preceding subsections are a set of newer blockchain technologies and smart contracts. In the next section, we will introduce you to Ethereum, a smart contract-enabled blockchain network.

Ushering in the world of Ethereum

Vitalik Buterin, the founder of Ethereum, addressed the limitations of Bitcoin discussed earlier quite differently. While working on Bitcoin, he recognized that Bitcoin’s stack-based scripting is very limited and lacks the functionality and capability for application development beyond the transfer of cryptocurrency ownership. He saw it as a huge opportunity and began writing his own whitepaper in 2013.

In his famous Ethereum whitepaper (https://github.com/ethereum/wiki/wiki/White-Paper), Vitalik laid out his vision and intent to build a blockchain that includes the following:

  • A built-in Turing-complete programming language
  • A smart contract and decentralized application platform, allowing anyone to define, create, and trade all types of cryptocurrencies and crypto assets

Similar to Bitcoin, Ethereum is built on blockchain technology. It has all of the critical characteristics of a blockchain. It is a shared distributed ledger on top of a decentralized P2P network. It works in a similar way to that discussed in the Bitcoin and cryptocurrency section earlier in this chapter. Unlike Bitcoin, which is a decentralized state transition system with limited decentralized computing capability via Bitcoin scripting, Ethereum is a decentralized computing and data platform featuring Turing-complete smart contract functionality.

Ethereum introduced a few new and critical concepts, including the smart contract, EVM, and account. We will cover them in detail in the rest of this book.

Smart contract

A smart contract is a piece of programming code that is stored and executed on the blockchain. Ethereum now has a Turing-complete language, Solidity, which enables developers to develop and deploy smart contracts. In addition to moving ether (the cryptocurrency of the Ethereum network) between accounts, Ethereum smart contract code can support more modern program language constructs such as loops and perform much more complex computations, including data access, cryptographic algorithms, and function calls. Each such operation has a gas price associated with it. That is how Ethereum calculates the transaction cost of running smart contracts and, through a gas limit, protects smart contracts from infinite loops or programming errors.

A smart contract is like a scripted agreement between interacting parties; the code built into the contract is stored on the Ethereum blockchain and cannot be tampered with or removed. This greatly increases the credibility of legal documents.

EVM

The EVM is the runtime environment for smart contracts in Ethereum. It is a virtual operating system deployed as an Ethereum client to all network nodes across the globe. Similar to the Java Virtual Machine (JVM) in the Java world, contract code is compiled into bytecode, which is loaded into the EVM as part of contract creation.

Account

There is no concept of accounts in Bitcoin. Instead, Bitcoin uses the concept of UTXO to keep track of money transfers and account balances. Ethereum introduces the concept of the world state and account. The world state comprises a mapping of all accounts and their public addresses. To facilitate both state transactions and decentralized computing, Ethereum introduces two types of accounts: Externally Owned Accounts (EOAs), controlled by private keys, and contract accounts, controlled by their contract code.

Summary

In this chapter, we explained key blockchain components and elements and the different characteristics of blockchain, and we discussed how blockchain works. We reviewed cryptographic technologies and how they are leveraged in blockchain. We illustrated how PoW and PoS consensus mechanisms work. We went over some key concepts in Bitcoin, as well as examining some Bitcoin limitations. We provided a short overview of cryptocurrencies and altcoins. We then showcased some of the leading blockchain implementations across the industry. We also briefly introduced Ethereum, as well as the key differences between Bitcoin and Ethereum.

In the next chapter, we will delve into the Ethereum architecture and ecosystem in greater depth. Stay tuned.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Learn new development with Ethereum 2.0 and the planned merge of Eth1 and Eth2
  • Build, develop, and test end-to-end Ethereum dApps using Solidity, Node.js, and Web3
  • Setup private blockchains with Ethereum and delve into its wallets system

Description

Ethereum is a blockchain-based, decentralized computing platform that allows you to run smart contracts. With this book, you’ll discover the latest Ethereum tools, frameworks, wallets, and layer 2, along with setting up and running decentralized applications for the complete, end-to-end development experience. Learn Ethereum, 2nd Edition is a comprehensive overview of the Ethereum ecosystem, exploring its concepts, mechanisms, and decentralized application development process. You’ll delve into Ethereum's internals, technologies, and tools, including Ethereum 2.0 and the Ethereum Virtual Machine (EVM), gas, and its account systems. You’ll also explore Ethereum's transition to proof of stake, L1/L2 scaling solutions, DeFi protocols, and the current marketplace. Additionally, you’ll learn about EVM-compatible blockchains, connectivity techniques, and advanced topics such as sharding, off-chain scaling, DAOs, Metaverse, and NFTs. By the end of this book, you’ll be well-equipped to write smart contracts and develop, test, and deploy DApps using various tools, wallets, and frameworks.

Who is this book for?

This book is for blockchain developers and architects looking to learn the Ethereum blockchain fundamentals and those who want to build real-world decentralized applications using Solidity. Basic knowledge of an object-oriented programming language such as JavaScript will be useful but not mandatory.

What you will learn

  • Understand blockchain, cryptocurrency, and architectures
  • Explore decentralized finance protocols
  • Grasp how EVM-compatible blockchain networks work
  • Discover the latest developments in Ethereum
  • Use Solidity and Web3 API fundamentals on blockchain frameworks
  • Develop your own personalized cryptocurrency
  • Build tailor-made smart contracts and NFT marketplace DApps
  • Set up an Ethereum private chain
Estimated delivery fee Deliver to Cyprus

Premium delivery 7 - 10 business days

€32.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Aug 31, 2023
Length: 814 pages
Edition : 2nd
Language : English
ISBN-13 : 9781804616512
Category :
Languages :
Concepts :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Cyprus

Premium delivery 7 - 10 business days

€32.95
(Includes tracking information)

Product Details

Publication date : Aug 31, 2023
Length: 814 pages
Edition : 2nd
Language : English
ISBN-13 : 9781804616512
Category :
Languages :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 109.97
The Essential Guide to Web3
€29.99
Mastering Blockchain, Fourth Edition
€37.99
Learn Ethereum
€41.99
Total 109.97 Stars icon
Banner background image

Table of Contents

23 Chapters
Part 1: Blockchain and Ethereum Basics Chevron down icon Chevron up icon
Chapter 1: Blockchain and Cryptocurrency Chevron down icon Chevron up icon
Chapter 2: Ethereum Architecture and Ecosystem Chevron down icon Chevron up icon
Chapter 3: Decentralized Finance Chevron down icon Chevron up icon
Chapter 4: EVM-Compatible Blockchain Networks Chevron down icon Chevron up icon
Chapter 5: Deep Research and the Latest Developments in Ethereum Chevron down icon Chevron up icon
Part 2:Ethereum Development Fundamentals Chevron down icon Chevron up icon
Chapter 6: Fundamentals of Solidity Chevron down icon Chevron up icon
Chapter 7: Web3 API Fundamentals Chevron down icon Chevron up icon
Chapter 8: Developing Your Own Cryptocurrency Chevron down icon Chevron up icon
Part 3: Ethereum Development Fundamentals Chevron down icon Chevron up icon
Chapter 9: Smart Contract Development and Test Fundamentals Chevron down icon Chevron up icon
Chapter 10: Writing a Frontend to Build the NFT Marketplace DApp Chevron down icon Chevron up icon
Chapter 11: Ethereum Tools and Frameworks Chevron down icon Chevron up icon
Part 4:Production and Deployment Chevron down icon Chevron up icon
Chapter 12: Setting Up Ethereum Private Chain Chevron down icon Chevron up icon
Chapter 13: Deployment of Your DApps Chevron down icon Chevron up icon
Chapter 14: Building Ethereum Wallets Chevron down icon Chevron up icon
Chapter 15: Oracles, Technology, and Layer 2 in Practice Chevron down icon Chevron up icon
Part 5:Conclusion Chevron down icon Chevron up icon
Chapter 16: Conclusion Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Full star icon 5
(8 Ratings)
5 star 100%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Jim Yao Jan 05, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Learn Ethereum is a comprehensive and up-to-date introduction to the Ethereum blockchain platform and its development tools, frameworks, and protocols. The book covers the basics of blockchain, cryptocurrency, and smart contracts, as well as the latest developments in Ethereum 2.0, such as the beacon chain, proof of stake, sharding, and the merge of Eth1 and Eth2. The book also provides practical examples and exercises on how to build, deploy, and test decentralized applications (DApps) using Solidity, Node.js, Web3, and various Ethereum tools and libraries. The book is suitable for beginners who want to learn the fundamentals of Ethereum and blockchain development, as well as intermediate and advanced developers who want to explore the latest features and challenges of Ethereum 2.0. The book is well-written, clear, and engaging, with plenty of diagrams, code snippets, and screenshots to illustrate the concepts and techniques. The book also covers some of the most popular and emerging topics in the Ethereum ecosystem, such as decentralized finance (DeFi), non-fungible tokens (NFTs), layer 2 scaling solutions, EVM-compatible blockchains, and more. The book is a valuable resource for anyone who wants to learn Ethereum and develop DApps for the future of decentralized computing.
Amazon Verified review Amazon
Alexandru Panait Jan 03, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
As someone passionate about blockchain technology and its practical applications, I was thrilled to come across "Learn Ethereum, 2nd Edition." This book serves as an indispensable resource for both beginners and seasoned developers in the world of Ethereum and decentralized applications (DApps).The authors did an excellent job of dissecting complex topics such as Ethereum's transition to Proof of Stake (PoS), the intricacies of the Ethereum Virtual Machine (EVM), and the much-anticipated merge of Eth1 and Eth2. The chapters are meticulously organized, starting with the fundamentals of blockchain and cryptocurrency, gradually moving into the Ethereum architecture and ecosystem.What sets this book apart is its hands-on approach to learning. It guides you through building, developing, and testing end-to-end Ethereum DApps using Solidity, Node.js, and Web3. The step-by-step instructions to set up private blockchains and delve into Ethereum's wallet system are invaluable for practical learning.The book also provides a comprehensive overview of Layer 1 (L1) and Layer 2 (L2) scaling solutions, crucial for anyone looking to understand the challenges and solutions in scaling Ethereum. The sections on decentralized finance protocols, EVM-compatible blockchain networks, and advanced topics like sharding, DAOs, and the Metaverse are insightful and future-oriented."Learn Ethereum, 2nd Edition" is not just theoretical; it's brimming with practical applications. The chapters on developing your own cryptocurrency, building smart contracts, and creating an NFT marketplace DApp are particularly useful for applying your knowledge in real-world scenarios.This book is ideal for blockchain developers and architects seeking to deepen their understanding of Ethereum fundamentals. While basic knowledge of an object-oriented programming language is helpful, the author ensures that the concepts are accessible even to those new to programming.
Amazon Verified review Amazon
Kelly Y. Nov 01, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
As an essential companion to the intricate world of Ethereum, "Learn Ethereum" stands as an invaluable guide for developers, enthusiasts, and entrepreneurs venturing into the realm of blockchain technology. This book, authored by an accomplished expert with over two decades of hands-on experience in blockchain architecture, is a beacon of comprehensive knowledge and practical insights.Flavia P.'s review from the United States encapsulates the essence of this book perfectly. It not only serves as a robust entry point for novices but also delves deep into the intricate workings of Ethereum, catering to the most seasoned developers and tech-savvy individuals. The book offers a balanced approach, detailing both the advantages and disadvantages of Ethereum technology, ensuring readers obtain a well-rounded perspective.The comprehensiveness of "Learn Ethereum" lies in its ability to cater to a diverse audience. Whether you're a beginner seeking foundational knowledge or an experienced developer aiming to delve into advanced topics, this book is structured to accommodate varied interests and levels of expertise. The extensive coverage of Ethereum's ecosystem, from fundamentals to cutting-edge advancements like Ethereum 2.0, makes it an all-encompassing resource.The inclusion of practical guidance on creating cryptocurrencies, crafting smart contracts, and navigating the intricacies of decentralized finance and NFT marketplaces adds significant value to this guide. The book doesn't just stop at theoretical explanations but also provides hands-on examples and exercises, ensuring a comprehensive and immersive learning experience.One notable highlight is its coverage of the latest Ethereum developments, such as the shift to proof of stake, L1/L2 scaling solutions, sharding, and the metaverse, ensuring readers are well-versed in the most recent innovations."Learn Ethereum" is a treasure trove of knowledge, sparing readers from hours of aimless online searches by consolidating a vast amount of information in an accessible and reader-friendly manner. It's an investment that not only saves time but also equips individuals with the necessary tools to confidently navigate the complexities of Ethereum's expansive ecosystem.In conclusion, "Learn Ethereum" is a must-have for anyone interested in exploring the blockchain and Ethereum realm. Its blend of practicality, depth, and up-to-date information positions it as an indispensable resource, regardless of one's expertise level. This book serves as a beacon guiding enthusiasts through the intricate labyrinth of Ethereum, making it a perfect companion for those aspiring to master decentralized applications in the Ethereum landscape.
Amazon Verified review Amazon
Flavia P. Oct 08, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
The book "Learn Ethereum" is an essential practical guide for developers, entrepreneurs, investors, and anyone interested in the blockchain and Ethereum field. Written by an expert in blockchain architecture with over 20 years of hands-on experience in technologies, including Blockchain, an innovative technological leader with over 20 years of experience delivering cutting-edge enterprise solutions, and a remarkable technology leader, this book provides answers to all the essential questions in this field.With a captivating start through a concise history, the book doesn't bore you but quickly immerses you in the fascinating world of blockchain and Ethereum. The illustrations in the book are an invaluable aid in understanding complex concepts such as PoW and digital signatures.A remarkable aspect of the book is its balanced approach to the advantages and disadvantages of Ethereum technology, ensuring that readers are well-informed before getting involved in this field. Additionally, the book goes into detail about the involved risks, providing a realistic perspective.A significant plus of the book is that it can be read as a whole or in parts, depending on the reader's interests and needs. This makes "Learn Ethereum" a flexible and accessible resource for anyone interested in starting DApp development or gaining a better understanding of the Ethereum world.In conclusion, "Learn Ethereum" is an indispensable book for anyone looking to explore the world of blockchain and Ethereum. It is a comprehensive and accessible guide that answers essential questions and provides valuable information for those wishing to venture into this field or strengthen their knowledge.
Amazon Verified review Amazon
Dragoon Jan 04, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Learn Ethereum, 2nd Edition" is not merely a book; it's a comprehensive expedition into the evolving world of Ethereum, and by extension, the future of decentralized applications. For developers and enthusiasts eager to understand and harness the power of Ethereum 2.0, this text proves to be an indispensable guide.The authors‘ narrative is deeply informative yet surprisingly accessible. It starts by laying a robust foundation with an introduction to blockchain and cryptocurrency, gradually steering you through the complexities of Ethereum's architecture and ecosystem. The book excels in demystifying the nuanced mechanics of Ethereum 2.0, the Ethereum Virtual Machine (EVM), and the pivotal transition to a Proof of Stake consensus.What's truly commendable is the book's pragmatic approach. It's not just about theories and concepts; it's about rolling up your sleeves and diving into the world of development. The chapters dedicated to building and testing Ethereum DApps using tools like Solidity, Node.js, and Web3 are packed with actionable insights and step-by-step guidance. It's a real-world approach that equips you to not just understand but also to implement and innovate.The exploration of Layer 1 and Layer 2 scaling solutions is particularly timely, addressing one of the most pressing challenges in the blockchain space. The coverage of decentralized finance protocols, EVM-compatible blockchains, and advanced topics such as sharding, DAOs, Metaverse, and NFTs, ensures that readers are not just keeping pace with current trends but are also prepared for future developments.For developers, the sections on developing personalized cryptocurrencies, building tailor-made smart contracts, and setting up an Ethereum private chain are invaluable. They offer a hands-on approach that transforms readers from passive learners to active creators.While the book is technically detailed, a fundamental understanding of object-oriented programming is enough to get started. This makes "Learn Ethereum, 2nd Edition" accessible to a broad audience, from beginners to seasoned developers looking to expand their blockchain horizons."Learn Ethereum, 2nd Edition" is a masterful blend of comprehensive knowledge and practical application. It stands out as a vital resource for anyone serious about mastering Ethereum and the broader blockchain ecosystem. The included free PDF eBook is a thoughtful addition, enhancing its value as a long-term reference. Whether you're a developer, architect, or simply a curious mind, this book is your gateway to becoming an active participant in the blockchain revolution. Highly recommended for its depth, clarity, and practicality.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela