100% нашли этот документ полезным (1 голос)
45 просмотров

Download full Beginning Ethereum Smart Contracts Programming: With Examples in Python, Solidity, and JavaScript Lee ebook all chapters

Ethereum

Загружено:

lebustamesyh
Авторское право
© © All Rights Reserved
Мы серьезно относимся к защите прав на контент. Если вы подозреваете, что это ваш контент, заявите об этом здесь.
Доступные форматы
Скачать в формате PDF, TXT или читать онлайн в Scribd
100% нашли этот документ полезным (1 голос)
45 просмотров

Download full Beginning Ethereum Smart Contracts Programming: With Examples in Python, Solidity, and JavaScript Lee ebook all chapters

Ethereum

Загружено:

lebustamesyh
Авторское право
© © All Rights Reserved
Мы серьезно относимся к защите прав на контент. Если вы подозреваете, что это ваш контент, заявите об этом здесь.
Доступные форматы
Скачать в формате PDF, TXT или читать онлайн в Scribd
Вы находитесь на странице: 1/ 55

Download the Full Version of textbook for Fast Typing at textbookfull.

com

Beginning Ethereum Smart Contracts Programming:


With Examples in Python, Solidity, and JavaScript
Lee

https://textbookfull.com/product/beginning-ethereum-smart-
contracts-programming-with-examples-in-python-solidity-and-
javascript-lee/

OR CLICK BUTTON

DOWNLOAD NOW

Download More textbook Instantly Today - Get Yours Now at textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Biota Grow 2C gather 2C cook Loucas

https://textbookfull.com/product/biota-grow-2c-gather-2c-cook-loucas/

textboxfull.com

Introducing Ethereum and Solidity: Foundations of


Cryptocurrency and Blockchain Programming for Beginners
Chris Dannen
https://textbookfull.com/product/introducing-ethereum-and-solidity-
foundations-of-cryptocurrency-and-blockchain-programming-for-
beginners-chris-dannen/
textboxfull.com

Ethereum for Architects and Developers With Case Studies


and Code Samples in Solidity Springerlink (Online Service)

https://textbookfull.com/product/ethereum-for-architects-and-
developers-with-case-studies-and-code-samples-in-solidity-
springerlink-online-service/
textboxfull.com

Beginning Functional JavaScript. Functional Programming


with JavaScript using EcmaScript 6 1st Edition Anto
Aravinth
https://textbookfull.com/product/beginning-functional-javascript-
functional-programming-with-javascript-using-ecmascript-6-1st-edition-
anto-aravinth/
textboxfull.com
Beginning Functional JavaScript: Functional Programming
with JavaScript Using EcmaScript 6 1st Edition Anto
Aravinth
https://textbookfull.com/product/beginning-functional-javascript-
functional-programming-with-javascript-using-ecmascript-6-1st-edition-
anto-aravinth-2/
textboxfull.com

Ethereum for Architects and Developers: With Case Studies


and Code Samples in Solidity 1st Edition Debajani Mohanty

https://textbookfull.com/product/ethereum-for-architects-and-
developers-with-case-studies-and-code-samples-in-solidity-1st-edition-
debajani-mohanty/
textboxfull.com

Good Habits for Great Coding: Improving Programming Skills


with Examples in Python Michael Stueben

https://textbookfull.com/product/good-habits-for-great-coding-
improving-programming-skills-with-examples-in-python-michael-stueben/

textboxfull.com

Beginning Programming with Python For Dummies 2nd Edition


John Paul Mueller

https://textbookfull.com/product/beginning-programming-with-python-
for-dummies-2nd-edition-john-paul-mueller/

textboxfull.com

Blockchain The Ultimate Guide to the World of Blockchain


Technology Bitcoin Ethereum Cryptocurrency Smart Contracts
1st Edition Takashima
https://textbookfull.com/product/blockchain-the-ultimate-guide-to-the-
world-of-blockchain-technology-bitcoin-ethereum-cryptocurrency-smart-
contracts-1st-edition-takashima/
textboxfull.com
Beginning Ethereum
Smart Contracts
Programming
With Examples in Python,
Solidity and JavaScript

Wei-Meng Lee
Beginning Ethereum Smart Contracts Programming:
With Examples in Python, Solidity and JavaScript
Wei-Meng Lee
Ang Mo Kio, Singapore

ISBN-13 (pbk): 978-1-4842-5085-3    ISBN-13 (electronic): 978-1-4842-5086-0


https://doi.org/10.1007/978-1-4842-5086-0

© 2019 by Wei-Meng Lee

Any source code or other supplementary material referenced by the author in this book is available to
readers on GitHub via the book’s product page, located at www.apress.com/9781484250853. For more
detailed information, please visit http://www.apress.com/source-code.
Contents

Introduction�����������������������������������������������������������������������������������������������������������xvii

Chapter 1: Understanding Blockchain���������������������������������������������������������������������� 1


Motivations Behind Blockchain����������������������������������������������������������������������������������������������������� 2
Placement of Trusts����������������������������������������������������������������������������������������������������������������� 2
Trust Issues����������������������������������������������������������������������������������������������������������������������������� 3
Solving Trust Issues Using Decentralization���������������������������������������������������������������������������� 4
Example of Decentralization���������������������������������������������������������������������������������������������������� 4
Blockchain As a Distributed Ledger����������������������������������������������������������������������������������������� 8
How Blockchain Works����������������������������������������������������������������������������������������������������������������� 9
Chaining the Blocks��������������������������������������������������������������������������������������������������������������� 10
Mining������������������������������������������������������������������������������������������������������������������������������������ 12
Broadcasting Transactions���������������������������������������������������������������������������������������������������� 12
The Mining Process��������������������������������������������������������������������������������������������������������������� 13
Proof of Work������������������������������������������������������������������������������������������������������������������������� 16
Immutability of Blockchains�������������������������������������������������������������������������������������������������� 16
Blockchain in More Detail����������������������������������������������������������������������������������������������������������� 17
Types of Nodes���������������������������������������������������������������������������������������������������������������������� 19
Merkle Tree and Merkle Root������������������������������������������������������������������������������������������������� 21
Uses of Merkle Tree and the Merkle Root������������������������������������������������������������������������������ 22
Summary������������������������������������������������������������������������������������������������������������������������������������ 23
Chapter 2: Implementing Your Own Blockchain Using Python������������������������������� 25
Our Conceptual Blockchain Implementation������������������������������������������������������������������������������� 25
Obtaining the Nonce�������������������������������������������������������������������������������������������������������������� 27
Installing Flask���������������������������������������������������������������������������������������������������������������������� 28
Importing the Various Modules and Libraries������������������������������������������������������������������������ 29
Declaring the Class in Python������������������������������������������������������������������������������������������������ 29
Finding the Nonce����������������������������������������������������������������������������������������������������������������� 31
Appending the Block to the Blockchain��������������������������������������������������������������������������������� 32
Adding Transactions�������������������������������������������������������������������������������������������������������������� 32
Exposing the Blockchain Class as a REST API����������������������������������������������������������������������� 33
Obtaining the Full Blockchain������������������������������������������������������������������������������������������������ 33
Performing Mining����������������������������������������������������������������������������������������������������������������� 34
Adding Transactions�������������������������������������������������������������������������������������������������������������� 35
Testing Our Blockchain��������������������������������������������������������������������������������������������������������������� 36
Synchronizing Blockchains��������������������������������������������������������������������������������������������������������� 41
Testing the Blockchain with Multiple Nodes�������������������������������������������������������������������������� 45
Full Listing for the Python Blockchain Implementation��������������������������������������������������������������� 51
Summary������������������������������������������������������������������������������������������������������������������������������������ 59

Chapter 3: Connecting to the Ethereum Blockchain����������������������������������������������� 61


Downloading and Installing Geth������������������������������������������������������������������������������������������������ 62
Installing Geth for macOS������������������������������������������������������������������������������������������������������ 62
Installing Geth for Windows��������������������������������������������������������������������������������������������������� 63
Installing Geth for Linux��������������������������������������������������������������������������������������������������������� 64
Getting Started with Geth������������������������������������������������������������������������������������������������������������ 64
Examining the Data Downloaded������������������������������������������������������������������������������������������� 65
Geth JavaScript Console�������������������������������������������������������������������������������������������������������� 66
Sync Modes��������������������������������������������������������������������������������������������������������������������������� 68
Summary������������������������������������������������������������������������������������������������������������������������������� 69
Chapter 4: Creating Your Own Private Ethereum Test Network������������������������������ 71
Creating the Private Ethereum Test Network������������������������������������������������������������������������������ 71
Creating the Genesis Block��������������������������������������������������������������������������������������������������� 72
Creating a Folder for Storing Node Data�������������������������������������������������������������������������������� 73
Initiating a Blockchain Node�������������������������������������������������������������������������������������������������� 74
Starting Up the Nodes����������������������������������������������������������������������������������������������������������� 76
Managing Accounts��������������������������������������������������������������������������������������������������������������������� 88
Removing Accounts��������������������������������������������������������������������������������������������������������������� 90
Setting the Coinbase������������������������������������������������������������������������������������������������������������� 90
Summary������������������������������������������������������������������������������������������������������������������������������� 91

Chapter 5: Using the MetaMask Chrome Extension������������������������������������������������ 93


What Is MetaMask?�������������������������������������������������������������������������������������������������������������������� 93
How MetaMask Works Behind the Scene������������������������������������������������������������������������������ 94
Installing MetaMask�������������������������������������������������������������������������������������������������������������� 95
Signing in to MetaMask��������������������������������������������������������������������������������������������������������� 97
Selecting Ethereum Networks�������������������������������������������������������������������������������������������������� 103
Getting Ethers���������������������������������������������������������������������������������������������������������������������� 104
Creating Additional Accounts����������������������������������������������������������������������������������������������� 111
Transferring Ethers�������������������������������������������������������������������������������������������������������������� 113
Recovering Accounts����������������������������������������������������������������������������������������������������������� 117
Importing and Exporting Accounts�������������������������������������������������������������������������������������������� 120
Exporting Accounts�������������������������������������������������������������������������������������������������������������� 120
Importing Accounts������������������������������������������������������������������������������������������������������������� 124
Summary���������������������������������������������������������������������������������������������������������������������������������� 126

Chapter 6: Getting Started with Smart Contract��������������������������������������������������� 127


Your First Smart Contract���������������������������������������������������������������������������������������������������������� 127
Using the Remix IDE������������������������������������������������������������������������������������������������������������ 128
Compiling the Contract�������������������������������������������������������������������������������������������������������� 131
Testing the Smart Contract Using the JavaScript VM���������������������������������������������������������� 133
Getting the ABI and Bytecode of the Contract��������������������������������������������������������������������� 136
Loading the Smart Contract onto Geth�������������������������������������������������������������������������������������� 139
Testing the Contract������������������������������������������������������������������������������������������������������������ 142
Calling the Contract from Another Node������������������������������������������������������������������������������ 144
Summary���������������������������������������������������������������������������������������������������������������������������������� 146

Chapter 7: Testing Smart Contracts Using Ganache��������������������������������������������� 147


Downloading and Installing Ganache���������������������������������������������������������������������������������������� 147
Command-Line Interface����������������������������������������������������������������������������������������������������� 148
Graphical User Interface������������������������������������������������������������������������������������������������������ 150
Creating a Smart Contract�������������������������������������������������������������������������������������������������������� 153
Deploying the Contract to Ganache������������������������������������������������������������������������������������� 154
Examining Ganache������������������������������������������������������������������������������������������������������������� 156
Testing the Contract������������������������������������������������������������������������������������������������������������ 159
Connecting MetaMask to Ganache������������������������������������������������������������������������������������������� 161
Summary���������������������������������������������������������������������������������������������������������������������������������� 167

Chapter 8: Using the web3.js APIs����������������������������������������������������������������������� 169


What Is web3.js?����������������������������������������������������������������������������������������������������������������������� 169
Installing web3.js���������������������������������������������������������������������������������������������������������������� 170
Testing the web3.js Using MetaMask���������������������������������������������������������������������������������� 171
Testing the web3.js Without MetaMask������������������������������������������������������������������������������� 175
Deploying Contracts Using web3.js������������������������������������������������������������������������������������������ 178
Interacting with a Contract Using web3.js�������������������������������������������������������������������������� 184
Sending Ethers to Smart Contracts������������������������������������������������������������������������������������� 191
Summary���������������������������������������������������������������������������������������������������������������������������������� 198

Chapter 9: Smart Contract Events������������������������������������������������������������������������ 199


What Are Events in Solidity?����������������������������������������������������������������������������������������������������� 199
Adding Events to the ProofOfExistence Contract����������������������������������������������������������������� 200
Deploying the Contract�������������������������������������������������������������������������������������������������������� 203
Handling Events Using web3.js������������������������������������������������������������������������������������������������� 204
Testing the Front End����������������������������������������������������������������������������������������������������������� 208
Notarizing the Same Document Twice��������������������������������������������������������������������������������� 213
Sending Incorrect Amount of Ether������������������������������������������������������������������������������������� 215
Summary���������������������������������������������������������������������������������������������������������������������������������� 219

Chapter 10: Project – Online Lottery�������������������������������������������������������������������� 221


How the Lottery Game Works���������������������������������������������������������������������������������������������������� 221
Defining the Smart Contract������������������������������������������������������������������������������������������������ 223
Constructor�������������������������������������������������������������������������������������������������������������������������� 224
Betting a Number���������������������������������������������������������������������������������������������������������������� 225
Drawing the Winning Number and Announcing the Winners����������������������������������������������� 227
Getting the Winning Number����������������������������������������������������������������������������������������������� 229
Killing the Contract�������������������������������������������������������������������������������������������������������������� 230
Testing the Contract������������������������������������������������������������������������������������������������������������������ 230
Betting on a Number����������������������������������������������������������������������������������������������������������� 231
Viewing the Winning Number���������������������������������������������������������������������������������������������� 236
Examining the Contract on Etherscan��������������������������������������������������������������������������������� 237
Killing the Contract�������������������������������������������������������������������������������������������������������������� 239
Adding Events to the Contract��������������������������������������������������������������������������������������������� 243
Creating the Web Front End������������������������������������������������������������������������������������������������������ 247
Returning Ethers Back to the Owner at the End of the Game���������������������������������������������� 253
Making the Game Run Indefinitely�������������������������������������������������������������������������������������� 255
Summary���������������������������������������������������������������������������������������������������������������������������������� 256

Chapter 11: Creating Your Tokens������������������������������������������������������������������������ 257


What Are Tokens?���������������������������������������������������������������������������������������������������������������������� 257
How Tokens Are Implemented?������������������������������������������������������������������������������������������� 259
Minting New Tokens������������������������������������������������������������������������������������������������������������ 259
Burning Tokens�������������������������������������������������������������������������������������������������������������������� 259
Units Used Internally in Token Contracts����������������������������������������������������������������������������� 260
ERC20 Token Standard�������������������������������������������������������������������������������������������������������� 261
Creating Token Contracts���������������������������������������������������������������������������������������������������������� 263
Deploying the Token Contract���������������������������������������������������������������������������������������������� 272
Adding Tokens to MetaMask������������������������������������������������������������������������������������������������ 275
Buying Tokens��������������������������������������������������������������������������������������������������������������������� 279
Creating an ICO Page����������������������������������������������������������������������������������������������������������� 284
Summary���������������������������������������������������������������������������������������������������������������������������������� 287

Index��������������������������������������������������������������������������������������������������������������������� 289
Introduction
Welcome to Beginning Ethereum Smart Contracts Programming!
This book is a quick guide to getting started with Ethereum Smart Contracts
programming. It first starts off with a discussion on blockchain and the motivations
behind it. You will learn what is a blockchain, how blocks in a blockchain are chained
together, and how blocks get added to a blockchain. You will also understand how
mining works and discover the various types of nodes in a blockchain network.
Once that is out of the way, we will dive into the Ethereum blockchain. You will
learn how to use an Ethereum client (Geth) to connect to the Ethereum blockchain and
perform transactions such as sending ethers to another account. You will also learn how
to create private blockchain networks so that you can test them internally within your
own network.
The next part of this book will discuss Smart Contracts programming, a unique
feature of the Ethereum blockchain. Readers will be able to get jumpstarted on Smart
Contracts programming without needing to wade through tons of documentation. The
learn-by-doing approach of this book makes you productive in the shortest amount
of time. By the end of this book, you would be able to write smart contracts, test them,
deploy them, and create web applications to interact with them.
The last part of this book will touch on tokens, something that has taken the
cryptocurrency market by storm. You would be able to create your own tokens and
launch your own ICO and would be able to write token contracts that allow buyers to buy
tokens using Ethers.
This book is for those who want to get started quickly with Ethereum Smart
Contracts programming. Basic programming knowledge and an understanding of
Python or JavaScript are recommended.
I hope you will enjoy working on the sample projects as much as I have enjoyed
working on them!
CHAPTER 1

Understanding Blockchain
One of the hottest technologies of late is Blockchain. But what exactly is a blockchain?
And how does it actually work? In this chapter, we will explore the concept of blockchain,
how the concept was conceived, and what problems it aimed to solve. By the end of this
chapter, the idea and motivation behind blockchain would be crystal clear.

Tip For the clearly impatient – A blockchain is a digital transaction of records


that’s arranged in chunks of data called blocks. These blocks link with one another
through a cryptographic validation known as a hashing function. Linked together,
these blocks form an unbroken chain – a blockchain. A blockchain is programmed
to record not only financial transactions but virtually everything of value. Another
name for blockchain is distributed ledger.

Hold on tight, as I’m going to discuss a lot of concepts in this chapter. But if you
follow along closely, you’ll understand the concepts of blockchain and be on your way to
creating some really creative applications on the Ethereum blockchain in the upcoming
chapters!

Tip Ethereum is an open-source public blockchain that is similar to the Bitcoin


network. Besides offering a cryptocurrency known as Ether (which is similar
to Bitcoin), the main difference between Bitcoin and itself is that it offers a
programming platform on top of the blockchain, called Smart Contract. This book
focuses on the Ethereum blockchain and Smart Contract.
Chapter 1 Understanding Blockchain

Motivations Behind Blockchain


Most people have heard of cryptocurrencies, or at least, Bitcoin.

Note The technology behind cryptocurrencies is blockchain.

To understand why we need cryptocurrencies, you have to first start with


understanding a fundamental concept – trust. Today, any asset of value or transaction is
recorded by a third party, such as bank, government, or company. We trust banks won’t
steal our money, and they are regulated by the government. And even If the banks fail,
it is backed by the government. We also trust our credit card companies – sellers trust
credit card companies to pay them the money, and buyers trust credit card companies to
settle any disputes with the sellers.

Placement of Trusts
All these boil down to one key concept – placement of trust. And that is, we place our
trust on a central body. Think about it, in our everyday life, we place our trusts on banks,
and we place our trusts on our governments.
Even for simple mundane day-to-day activities, we place our trusts in central bodies.
For example, when you go to the library to borrow a book, you trust that the library
would maintain a proper record of the books that you have borrowed and returned.
The key theme is that we trust institutions but don’t trust each other. We trust our
government, banks, even our library, but we just don’t trust each other. As an example,
consider the following scenario. Imagine you work at a cafe, and someone walks up
to you and offers you a US ten-dollar bill for two cups of coffee. And another person
who offers to pay you for the two cups of coffee using a handwritten note saying he
owes you ten dollars. Which one would you trust? The answer is pretty obvious, isn’t it?
Naturally you would trust the US ten-dollar bill, as opposed to the handwritten note.
This is because you understand that using the ten-dollar bill, you can use it elsewhere
to exchange for other goods or services, and that it is backed by the US government. In
contract, the handwritten note is not backed by anyone else (except perhaps the person
who wrote it), and hence it has literally no value.

2
Chapter 1 Understanding Blockchain

Now let’s take the discussion a bit further. Again, imagine you are trying to sell
something. Someone comes up to you and suggests paying for your goods using the
currencies as shown in Figure 1-1.

Figure 1-1. Currencies from two countries

Would you accept the currencies as shown in the figure? Here, you have two different
currencies – one from Venezuela and one from Zimbabwe. In this case, the first thing
you consider is whether these currencies are widely accepted and also your trust in these
governments. You might have read from the news about the hyperinflation in these two
countries, and that these currencies might not retain its value over time.
And so, would you accept these currencies as payment?

T rust Issues
Earlier on, I mentioned that people trust institutions and don’t trust each other. But even
established economies can fail, such as in the case of the financial crisis of the United
States in 2007–2008. Investment bank Lehman Brothers collapsed in September 2008
because of the subprime mortgage market. So, if banks from established economies can

3
Chapter 1 Understanding Blockchain

collapse, how can people in less developed countries trust their banks and governments?
Even if the banks are trusted, your deposits may be monitored by the government, and
they could arrest you based on your transactions.
As we have seen in the example in the previous section, there are times when people
don’t trust institutions, especially if the political situation in that country is not stable.
All these discussions bring us to the next key issue – even though people trust
institutions, institutions can still fail. And when people lose trust in institutions, people
turn to cryptocurrencies. In the next section, we will discuss how we can solve the trust
issues using decentralization, a fundamental concept behind cryptocurrency.

Solving Trust Issues Using Decentralization


Now that you have seen the challenges of trust – who to trust and who not to trust, it
is now time to consider a way to solve the trust issues. In particular, blockchain uses
decentralization to solve the trust issue.
In order to understand decentralization, let’s use a very simple example that is based
on our daily lives.

E xample of Decentralization
To understand how decentralization solves the trust issue, let’s consider a real-life example.
Imagine a situation where you have three persons with DVDs that they want to share
with one another (see Figure 1-2).

4
Chapter 1 Understanding Blockchain

Figure 1-2. Sharing DVDs among a group of people

The first thing they need to do is to have someone keep track of the whereabouts
of each DVD. Of course, the easiest is for each person to keep track of what they have
borrowed and what they have lent, but since people inherently do not trust each other,
this approach is not very popular among the three persons.
To solve this issue, they decided to appoint one person, say B, to keep a ledger, to
hold a record of the whereabouts of each DVD (see Figure 1-3).

5
Chapter 1 Understanding Blockchain

Figure 1-3. Appointing a particular person to keep the records

This way, there is a central body to keep track of the whereabouts of each DVD. But
wait, isn’t this the problem with centralization? What happens if B is not trustworthy?
Turns out that B has the habit of stealing DVDs, and he in fact could easily modify the
ledger to erase the record of DVDs that he has borrowed. So, there must be a better way.
And then, someone has an idea! Why not let everyone keep a copy of the ledger
(see Figure 1-4)? Whenever someone borrows or lent a DVD, the record is broadcast to
everyone, and everyone records the transaction.

6
Chapter 1 Understanding Blockchain

Figure 1-4. Getting everyone to keep the records

We say that the record keeping is now decentralized! We now have three persons
holding the same ledger. But wait a minute. What if A and C conspire to change the
records together so that they can steal the DVDs from B? Since majority wins, as long
as there is more than 50% of the people with the same records, the others would have
to listen to the majority. And because there are only three persons in this scenario, it is
extremely easy to get more than 50% of the people to conspire.
The solution is to have a lot more people to hold the ledger, especially people who
are not related to the DVDs sharing business (see Figure 1-5).

7
Chapter 1 Understanding Blockchain

Figure 1-5. Getting a group of unrelated people to help keep the records

This way, it makes it more difficult for one party to alter the records on the ledger,
and that in order to alter a record, it would need to involve a number of people altering
the record all at the same time, which is a time-consuming affair. And this is the key idea
behind distributed ledger, or commonly known as blockchain.

Blockchain As a Distributed Ledger


Now that we have a better idea of a distributed ledger, we can now associate it with
the term – blockchain. Using the DVD rental example, each time a DVD is borrowed
or returned, a transaction is created. A number of transactions are then grouped
into a block. As more transactions are performed, the blocks are linked together
cryptographically, forming what we now call a blockchain (see Figure 1-6).

8
Chapter 1 Understanding Blockchain

Figure 1-6. Transactions form a block, and then blocks are then chained

Based on what we have discussed, we can now summarize a few important points:

• Centralized databases and institutions work when there is trust in the


system of law, governments, regulatory bodies, and people.

• A decentralized database built on the blockchain removes the need


for the trust in a central body.

• A blockchain can be used for anything of value, not just currencies.

How Blockchain Works


At a very high level, a blockchain consists of a number of blocks. Each block contains a
list of transactions, as well as a timestamp (see Figure 1-7).

9
Chapter 1 Understanding Blockchain

Figure 1-7. Every blockchain has a beginning block known as the genesis block

The blocks are connected to each other cryptographically, the details in which we
will discuss in the sections ahead. The first block in a blockchain is known as the genesis
block.

Note Every blockchain has a genesis block.

So, the next important questions is – how do you chain the blocks together?

Chaining the Blocks


Before we discuss how blocks in a blockchain are chained together, we have to discuss
a key concept in blockchain – hashing. A hash function is a function that maps data of
arbitrary size to data of fixed size. By altering a single character in the original string, the
resultant hash value is totally different from the previous one. Most importantly, observe
that a single change in the original message results in a completely different hash,
making it difficult to know that the two original messages are similar.
10
Chapter 1 Understanding Blockchain

A hash function has the following characteristics:

• It is deterministic – the same message always results in the same


hash.

• It is a one-way process – when you hash a string, it is computationally


hard to reverse a hash to its original message.

• It is collision resistant – it is hard to find two different input messages


that hash to the same hash.

We are now ready to discuss how blocks in a blockchain are chained together. To
chain the blocks together, the content of each block is hashed and then stored in the next
block (see Figure 1-8). That way, if any transactions in a block is altered, that is going to
invalidate the hash of the current block, which is stored in the next block, which in turn
is going to invalidate the hash of the next block, and so on.

Figure 1-8. Chaining the blocks with hashes

11
Chapter 1 Understanding Blockchain

Observe that when hashing the content of a block, the hash of the previous block is
hashed together with the transactions. However, do take note that this is a simplification
of what is in a block. Later on, we will dive into the details of a block and see exactly how
transactions are represented in a block.
Storing the hash of the previous block in the current block assures the integrity of the
transactions in the previous block. Any modifications to the transaction(s) within a block
causes the hash in the next block to be invalidated, and it also affects the subsequent
blocks in the blockchain. If a hacker wants to modify a transaction, not only must he
modify the transaction in a block but all other subsequent blocks in the blockchain. In
addition, he needs to synchronize the changes to all other computers on the network,
which is a computationally expensive task to do. Hence, data stored in the blockchain
is immutable, for they are hard to change once the block they are in is added to the
blockchain.
Up to this point, you have a high-level overview of what constitutes a blockchain and
how the blocks are chained together. In the next section, you will understand the next
important topic in blockchain – mining.

M
 ining
Whenever you talk about blockchain or cryptocurrencies, there is always one term that
comes up – mining. In this section, you will learn what is mining, and what goes on
behind the scene.
Mining is the process of adding blocks to a blockchain. In a blockchain network,
such as the Bitcoin or Ethereum network, there are different types of computers known
as nodes. Computers on a blockchain that add blocks to the blockchain are known as
miner nodes (or mining nodes, or more simply miners).
We will talk about the different types of nodes later on in this course, but for now, we
want to talk about a particular type of node, known as the miner node. The role of the
miner node is to add blocks to the blockchain.
But how are blocks added?

B
 roadcasting Transactions
When a transaction is performed, the transaction is broadcasted to the network (see
Figure 1-9).

12
Chapter 1 Understanding Blockchain

Figure 1-9. Transactions are broadcasted to mining nodes, which then assemble
them into blocks to be mined

Each mining node may receive them at different times. As a node receives
transactions, it will try to include them in a block. Observe that each node is free to
include whatever transactions they want in a block. In practice, which transactions get
included in a block depends on a number of factors, such as transaction fees, transaction
size, order of arrival, and so on.
At this point, transactions that are included in a block but which are not yet added
to the blockchain are known as unconfirmed transactions. Once a block is filled with
transactions, a node will attempt to add the block to the blockchain.
Now here comes the problem – with so many miners out there, who gets to add the
block to the blockchain first?

The Mining Process


In order to slow down the rate of adding blocks to the blockchain, the blockchain
consensus protocol dictates a network difficulty target (see Figure 1-10).

13
Chapter 1 Understanding Blockchain

Figure 1-10. Hashing the block to meet the network difficulty target

In order to successfully add a block to the blockchain, a miner would hash the
content of a block and check that the hash meets the criteria set by the difficulty target.
For example, the resultant hash must start with five zeros and so on.
As more miners join the network, the difficultly level increases, for example, the
hash must now start with six zeros and so on. This allows the blocks to be added to the
blockchain at a consistent rate.
But, wait a minute, the content of a block is fixed, and so no matter how you hash it,
the resultant hash is always the same. So how do you ensure that the resultant hash can
meet the difficulty target? To do that, miners add a nonce to the block, which stands for
number used once (see Figure 1-11).

14
Chapter 1 Understanding Blockchain

Figure 1-11. Adding a nonce to change the content of the block in order to meet
the network difficulty target

The first miner who meets the target gets to claim the rewards and adds the block to
the blockchain. It will broadcast the block to other nodes so that they can verify the claim
and stop working on their current work of mining their own blocks. The miners would
drop their current work, and the process of mining a new block starts all over again.
The transactions that were not included in the block that was successfully mined will be
added to the next block to be mined.

REWARDS FOR MINERS

In the case of Bitcoin, the block reward initially was 50 BTC and will halve every 210,000
blocks. At the time of writing, the block reward is currently at 12.5 BTC, and it will eventually
be reduced to 0 after 64 halving events. For Ethereum, the reward for mining a block is
currently 2 ETH (Ether).

15
Chapter 1 Understanding Blockchain

BLOCKS ADDING RATES

For Bitcoin, the network adjusts the difficulty of the puzzles so that a new block is being mined
roughly every 10 minutes. For Ethereum, a block is mined approximately every 14 seconds.

Proof of Work
The process in which blocks are mined and added to the blockchain is known as the
Proof of Work (PoW). It is difficult to produce the proof but very easy to validate. A good
example of Proof of Work is cracking a combination lock – it takes a lot of time to find the
right combination, but it is easy to verify once the combination is found.
Proof of Work uses tremendous computing resources – GPUs are required, while
CPU speed is not important. It also uses a lot of electricity, because miners are doing the
same work repeatedly – find the nonce to meet the network difficulty for the block.
A common question is why you need to use a powerful GPU instead of CPU for
mining? Well, as a simple comparison, a CPU core can execute 4 32-bit instructions per
clock, whereas a GPU like the Radeon HD 5970 can execute 3200 32-bit instructions per
clock. In short, the CPU excels at doing complex manipulations to a small set of data,
whereas the GPU excels at doing simple manipulations to a large set of data. And since
mining is all about performing hashing and finding the nonce, it is a highly repetitive
task, something that GPU excels in.

Tip When a miner has successfully mined a block, he earns mining fees as well
as transaction fees. That’s what keeps miners motivated to invest in mining rigs
and keep them running 24/7, thereby incurring substantial electricity bills.

Immutability of Blockchains
In a blockchain, each block is chained to its previous block through the use of a
cryptographic hash. A block’s identity changes if the parent’s identity changes. This in
turn causes the current block’s children to change, which affects the grandchildren, and
so on. A change to a block forces a recalculation of all subsequent blocks, which requires
enormous computation power. This makes the blockchain immutable, a key feature of
cryptocurrencies like Bitcoin and Ethereum.

16
Chapter 1 Understanding Blockchain

As a new block is added to the blockchain, the block of transactions is said to be


confirmed by the blockchain. When a block is newly added, it’s deemed to have one
confirmation. As another block is added to it, its number of confirmation increases.
Figure 1-12 shows the number of confirmations that the blocks in a blockchain have. The
more confirmations a block has, the more difficult it is to remove it from the blockchain.

Tip In general, once a block has six or more confirmations, it’s deemed infeasible
for it to be reversed. Therefore, the data stored in the blockchain is immutable.

Figure 1-12. Confirmations of blocks in a blockchain

Blockchain in More Detail


In the previous section, you learned that a block contains a nonce, timestamp, and the
list of transactions. That was a simplification. In real implementation, a block consists of

• A block header

• The list of transactions

17
Chapter 1 Understanding Blockchain

The block header in turn consists of the following:

• The hash of the previous block

• Timestamp

• Merkle root

• Nonce

• Network difficulty target


Note that the block header contains the Merkle root, and not the transactions (see
Figure 1-13). The transactions are collectively represented as a merkle root, details of
which will be discussed in the next few sections.

Figure 1-13. A block contains the block header, which in turns contains the
Merkle root of the transactions

18
Chapter 1 Understanding Blockchain

T ypes of Nodes
Before we address the rationale for storing the Merkle root in the block header, we need
to talk about the types of nodes in a blockchain network. Figure 1-14 shows the different
types of nodes in a blockchain network.

Figure 1-14. Different types of nodes in a blockchain network

As we mentioned in our earlier sections, computers connected to the blockchain


network are known as nodes. We have discussed the role of mining nodes, whose key
responsibility is to gather transactions into blocks and then try to add the block to the
blockchain by finding the nonce that satisfies the network difficulty. Mining nodes are
also known as full nodes.

Tip Note that full nodes are not necessarily mining nodes. However, mining
nodes need to be a full node.

The purpose of a full node is to ensure the integrity of the blockchain and people
running full nodes do not get rewards. On the other hand, mining nodes are rewarded
when they add a block to the blockchain.
19
Chapter 1 Understanding Blockchain

An example of a full node is a desktop wallet, which allows users to perform


transaction using the cryptocurrency.
Each full node has a copy of the entire blockchain. Full nodes also validate every
block and transactions presented to it.
Besides full nodes, there are also light nodes. Light nodes help to verify transactions
using a method called simplified payment verification (SPV). SPV allows a node to verify
if a transaction has been included in a block, without needing to download the entire
blockchain. Using SPV, light nodes connect to full nodes and transmit transactions to the
full nodes for verifications.
Light nodes only need to store the block headers of all the blocks in the blockchain. An
example of a light node is a mobile wallet, such as the Coinbase mobile app for iOS and
Android. Using a mobile wallet, a user can perform transactions on the mobile device.

Note Desktop wallets can be full node or light node.

And so, we can summarize the types of nodes that we have discussed thus far:

• Full node

• Maintains a complete copy of the blockchain

• Able to verify all transactions since the beginning

• Verifies a newly created block and add it to the blockchain

• Visit the following sites to see the current number of full nodes for
the following blockchains:
• Bitcoin – https://bitnodes.earn.com

• Ethereum – www.ethernodes.org/network/1

• Mining node (must be a full node)

• Works on a problem (finding the nonce)

• Light node (e.g., wallets)

• Maintains the headers of the blockchain

• Uses SPV to verify if a transaction is present and valid in a block

20
Exploring the Variety of Random
Documents with Different Content
"Where is my father, Dorothy?" she asked, feeling as if she
must say something.

"Your father has gone out with the old priest who was here
last night, Mistress Anne," was the short reply.

And Dorothy, who was usually disposed for a gossip at the


smallest encouragement, retired and shut the door without
another word.

Wicked and base as was the action she had committed, in


itself, Anne was very much to be pitied. Her mind had for
weeks been utterly unsettled.

As Jack had said, she was, in her heart, almost entirely


convinced that her brother was right, and that she was
wrong. In spite of herself, as it were, she could not help
recalling all that she had heard and read with Agnes
Harland, which was a great deal more than she had told
Jack. In spite of herself, when she was listening to the
harangues of the preaching friars against heresy, her mind
would persist in bringing up and arranging arguments on
the other side. When she repeated, as she did daily, her
long litany of invocations to the saints and the Virgin Mary,
something kept constantly telling her that it was a useless
labor, and making such suggestions as these:

"How do you know that these saints can hear you? They
were, and are, but finite beings like yourself, and cannot
possibly be present in all places and at all times at once."

These were but a few of the distractions which beset her


night and day, destroying her peace of mind, humbling her
pride, and undermining her faith in those things wherein
she had made her boast.
But Anne would not listen. She said to herself that they
were but temptations of the enemy, such as had beset all
eminent saints, and were to be banished by the proper
means. So she fasted and scourged herself, and lay on the
bare floor, and repeated ten times more prayers than ever.
She had been fed upon "Lives of the Saints" from the time
she could read, and for years, her cherished ambition had
been to become a saint, on the model of Elizabeth of
Hungary, or St. Bridget: to be looked up to as a pattern of
holiness and austerity; to found a new order of nuns, more
self-denying even than the "poor Clares," more
contemplative than the Carmelites; to rule them while she
lived, to be made a saint, and have miracles worked at her
grave, when she was dead and buried.

Father Barnaby had cultivated these notions, seeing in the


girl material which might encouraged her to believe made
useful, and had believe that in the course of a few years she
might be placed at the head of a sisterhood of her own
founding. Anne had plenty of imagination, and hundreds of
times she had gone over the whole matter in her own mind,
arranging the rules and services of her house, and the very
dress of the sisters. She fancied herself like St. Hilda, giving
counsel and advice to abbots and priests, even to bishops
and heads of the Church; as helping to stay the tide of
heresy by her prayers and writings; as educating girls to
perpetuate the doctrines and ways of her new order.

And was all this to be given up? Was she to abandon all her
cherished ambitions and be content with the life of a
daughter at home or a mere commonplace mother of a
family? Or, still worse, was she to run the risk of open
shame and disgrace and punishment, of being despised and
held up as a warning, instead of an example, by those over
whom she had hoped and expected to rule? Was she to
confess that all her righteousness, her prayers and
penances and sufferings, were worse than worthless in
God's sight, and receive the gift of salvation as a free,
wholly undeserved alms? Was her only title to heaven to
consist in the fact, not that she was a saint, but a sinner? It
could not be true—it should not be true! It was a work of
the devil tempting her to abandon her vocation and all the
great things she had planned.

And then came the thought—was it not her own fault after
all? Had she not by weakly yielding to family affection—
those fleshly ties from which she had been told again and
again she must tear herself loose—had she not given the
Tempter a handle against her? Ought she not to do all in
her power to prevent the spread of heresy, and had she not,
by yielding to her regard for her only brother, and
concealing his fault, made herself a partaker therein? Would
not her peace of mind return, if she were once to make the
sacrifice? Would not that sacrifice be an additional and most
precious jewel in the crown of martyrdom she coveted?

Yes, it must be so, and the sacrifice must be made. Once


done, the deed could never be recalled. She would be held
up as a bright example of piety, and she should again find
her former peace, and satisfaction in prayer and penance
and saintly reveries, and the doubts which disturbed her
would depart forever.

Then there was Sister Barbara—Sister Barbara whose


coming she had expected and prepared for, with so much
pleasure, who had been one of the elders of the order, and
a pattern of sanctity. There had long existed not even the
semblance of confidence between them, but Anne had no
doubt she was as bad as Jack, every whit. She had seen a
book in her hands which was no prayer-book—she was sure
of that—and she was always reading it while her "Hours"
and her rosary lay neglected day after day. Sister Barbara
and Jack were always talking quietly together and
exchanging smiles and glances. Besides, did she not go to
hear Father William preach even after he had refused to
celebrate masses for the dead, and declared his opinion
that it was lawful for priests to marry if they saw fit?

These and other indications convinced Anne that Sister


Barbara was as bad as Jack—nay, worse, for was she not a
nun, and had she not been a person in authority? Then
there was her school! Was she to be allowed to pervert the
children under her charge?

The morning that Sister Barbara went away, Anne went to


the Priory church, determined, as she said, to decide the
matter one way or the other before she came home. The
first person she met was Father Barnaby. In her excited
state of mind, this encounter seemed a supernatural sign
sent for the confirmation of her wavering resolution, and
she did not rest till she had told him all. She could not
indeed tell the place where Sister Barbara had taken refuge,
for she did not know it, but she told all she did know about
the matter.

Father Barnaby was well pleased. He had come down, as


Father John said, armed with a special commission for the
searching out and destruction of heretical books and the
suppression of heresy, and he was determined to carry
through his work with an unsparing hand. It was a good
omen to be thus met at the beginning, and served in some
degree to counterbalance the chagrin he had felt at
discovering that his chief prey had escaped him.

Father William had set out only the day before his return,
on a visit to London, and there was too much reason to fear
that by the connivance of friends, he might escape to
Germany. But here was a notable prey to be taken at once,
and he was not the man to let the grass grow under his
feet. He commended Anne for her faithfulness, though he
gave her less praise and paid less attention to the rest of
her confession than she thought she deserved. However, he
told her she had taken the best means to get rid of her
trouble of mind, and confirmed her in the idea that it had all
been owing to her having wickedly concealed her brother's
errors. A watch was at once set upon Jack's movements,
and he was apprehended, as we have seen.

Anne returned to her home with a strange feeling of


exultation. She had done the deed. She had sacrificed what
was nearest to her, and shown plainly that nothing was so
dear to her as the cause of the Church and true religion.
Surely, surely all must now be right with her. There would
be an end forever of these haunting doubts, these wild
temptations to go to Jack, own herself convinced, and beg
for instruction. This feeling lasted her all day and till she
saw her brother finally carried away to a fate which she
knew too well, and heard her father's voice commanding
her to her chamber. Thus she went to her room.

Lo! Her enemy was there awaiting her, armed with tenfold
power.

She had done the deed. She had betrayed her brother to
shame and death, she had incurred her father's hatred and
curse, which was withheld only for the sake of his son; and
all for what? Was she any nearer to the quiet of mind she
had so ardently desired? She did not find it so. Instead
thereof, her doubts returned with tenfold power. They were
no longer doubts, they were certainties—demonstrated
truths. She did not reason upon them; she could not.

She felt, rather than knew, that it was Jack who was the
martyr for the truth, and she was the Judas who had
betrayed him. She had denied her Lord, belied her own
conscience, and sacrificed her family to a monstrous lie.
What would she not have given to recall the events of the
last few hours? But it was too late—forever too late; and
the thought filled her with inexpressible anguish and
despair.

Anne rose at last from the floor, where she had thrown
herself at the foot of the crucifix, and in the sheer
restlessness of misery wandered into Jack's room. There
were all his treasures; his strings of birds' eggs, his shells
and other foreign curiosities derived from traders and
sailors, his Latin books and exercises. The blackbird and
squirrel he had brought from the country were hopping
about their cages, and seemed to wonder why they were
neglected. Anne took down the cages and ministered to the
wants of the occupants. The action, simple as it was,
seemed to bring her some relief, and as the blackbird tuned
up its mellow whistle, she leaned her head beside the cage,
and wept long and bitterly.

The little cupboard where Jack had hidden his precious


books stood open. Anne bent down, and looking into it she
saw something in a far dark corner, for the recess extended
deep into the wall beside the chimney. She drew it out, and
looked at it. It was a small copy of the New Testament.
Arthur had received from London a number of these new
books, and had given one to Jack. Jack had put it away with
the rest, but it had been overlooked by the searchers in
their haste and triumph at finding their great prize. Anne
stood looking at it for a few minutes, and then returning to
her room and once more fastening her door, she sat herself
down to read, nor did she move from her place till it was
too dark for her to see.

At dark, Cicely herself brought her a light.


"Where is my father?" Anne ventured to ask.

"He is below, poor dear man!" returned Cicely sobbing. "He


has been to the prison to see—" here her voice was lost in
tears. "Your brother is better lodged than we had hoped,"
she continued presently, "along with old Thomas Sprat and
some of the townspeople, and we are permitted to send him
bedding and refreshment. Your father says you are to use
your pleasure as to staying in your room or coming down to
supper. He does not desire to make a prisoner of you!"
added Cicely, with emphasis.

"Return my thanks to my father," said Anne sorrowfully but


calmly, "and say to him that, with his good leave, I will
remain here. Tell him I thank him for his goodness, and if
he will but add this much, to pray for me, I can ask nothing
more."

Cicely repeated the message, adding that she hoped Anne


was not going out of her mind, or meditating anything
desperate, for she looked as if she had seen a ghost.

CHAPTER XXII.

THE TRIAL.

When Jack arrived at the jail where he was to be confined,


he found a great crowd gathered round the door, and was
greeted from the midst of it with more than one cry of,
"God speed thee, dear lad!" "Be of good courage, brother,
and God bless thee! Our prayers are with thee!" And he
read in most of the faces surrounding him only pity and
sympathy.

Father Barnaby frowned ominously on the assemblage, and


hurried his prisoner as soon as possible into the jail.

"Let this young man be shut up by himself," said he to the


jailer.

"Your reverence must needs build him a cell, then,"


returned the jailer, who seemed to have no special pleasure
in his task. "Every place is full and overflowing, except the
dungeon, where there are only two. Shall I put him therein?
I think he were best out of sight of this crowd."

"Do so, then," replied the father. "Youth, I advise thee to


take the time of thy imprisonment to consider and repent of
thine errors. Thou art but young, and thou hast been misled
by more crafty heads than thine own. Thou hast also good
parts, and I would fain serve thee, and make thee an
instrument of good in the Church."

"I thank your reverence," replied Jack, in a steady tone, and


then raising his voice he said, "Good people, pray for me
and mine, and be steadfast in the truth, you who own it."

"We will! We will!" shouted several voices in return; and one


man added, "Let the Jack Priest look to it. If old Harry
quarrels with the Pope, we will pull down their crow's nest
about their ears ere long."

Jack was hurried into the jail and the doors shut upon him,
so he heard no more, but he noted even then the look of
furious wrath mingled with confusion on Father Barnaby's
face. He had no time for further observations before he
found himself pushed into the cell of which the jailer had
spoken, and the door locked upon him.

It was some minutes before his dazzled eyes could


distinguish anything in the dim dungeon, which was lighted
only by a small grated aperture near the ceiling. As he grew
more accustomed to the place, however, he saw that it was
a small room about twelve feet square, with stone walls and
floor. The furniture consisted of a stool or two, a rude table,
and two pallet beds, on one of which lay stretched a
sleeping man. Another man, apparently just aroused from
slumber, rose to his feet and advanced a step to meet him.

"I cannot say thou art welcome, friend, to this dungeon,"


said a voice Jack knew right well; "but to such slight
entertainment as we have, I do bid thee welcome."

"Dear uncle," exclaimed Jack, recovering his dazed senses


and springing forward, "dearest uncle, do you not know
me?"

"My son, my son!" cried the old man. "Is it indeed my son?
I feared this, but hoped you might have timely warning.
And is it to this I have brought thy youth?"

"Nay, dearest uncle," returned Jack; "not you, but the


malice of our enemies, and the enemies of the truth of God.
You brought me to the knowledge of that truth and
goodness, which shall make all their wrath to praise Him.
But who is our companion?"

"It is Master James Dennett, a ship-owner and merchant


here in Bridgewater. Disturb him not, for he hath been
sorely tried in spirit, and unable to sleep the whole night.
Truly, I am glad to be eased of his lamentations. But sit you
down here on the bedside, and tell me how all this has
chanced. I had hoped you would have had timely warning."

Jack told the story of his betrayal and arrest.

"Alas! Poor maid, was she so far left to herself?" said the
shepherd, when he heard of Anne's part in the transaction.
"We must put up many prayers for her. And how is your
father disposed?"

"He gave me his blessing ere I left him, and do not think he
is angry with me. I left him with old Father John, who rode
all the way from Holford to give me warning, but he was too
late. But how were you taken, dear uncle?"

"Even as I would have desired—on my knees," replied the


old man smiling. "I was in the little thicket whither I have
long resorted for prayer and reading, as my father did
before me, when a band of men, headed by Brother Joseph
the sacristan, broke in on me. I told them it was paying a
fair compliment to an old man-at-arms, that at nearly
ninety, he should need six men to secure him."

"But surely Sir John Brydges will take your part?" said Jack.

"I believe he can do nothing," replied Thomas Sprat. "They


have raked up the old matter of Lollardie, and Father
Barnaby assures me that as a relapsed heretic, I have no
chance of being admitted to mercy, though if I will recant
my errors I may perhaps, in time, be delivered from
purgatory."

"Many thanks to him," said Jack. "He hath been profuse in


his promises to me if I will recant, even to promising me
church advancement. But do you know aught of Arthur?"
"They have not apprehended him, but more than that I do
not know," replied the shepherd.

"But here comes the jailer with our bread and water."

"Methinks on a feast day they might offer us better fare,"


said Jack. "It is scarce canonical to fast upon St. Michael's
day."

"Don't cry out before you are hurt, young sir," said the
jailer, depositing a jug of broth on the table. "I have so far
stretched my orders as to bring you the same breakfast as
the other prisoners who are only confined for highway
robbery, murder, and the like."

"Many thanks for your courtesy, Master Davis," said Jack.


"When I am again at liberty, I will do as much for you."

"I would you were at liberty to do it," said the jailer bluntly.
"This turning the key on old friends and neighbors is no
pleasure to me, I can tell you. What then? A man must do
his duty, be he jailer or mayor; but he need not have a
heart as hard as the nether millstone. I judged you and the
old man would like to be together, so I clapped you in here;
but do not you tell yonder monk so."

"Never fear," said Jack. "I do not love him so well as all
that. Again I thank you, Master Davis, and so will my father.
Be assured you shall be no loser. Come, we are better than
we might be," said he after the man had closed the door. "I
am heartily glad we have fallen into such good hands. Shall
we awaken our companion? He sleeps soundly."

"He has not slept all night," said Thomas Sprat. "I fear
much he will not stand the trial. The goods and ties of this
world are over-near his heart, poor man. What, brother!
Will you awake and break your fast?"
"Where am I?" said Master Dennett, sitting up and gazing
round him with a bewildered expression. "What has
happened? Alas, I know too well!" he added, sinking back
again. "That I should ever live to find myself here in
Bridgewater jail! And who is this new companion in misery?
Surely, it is Master Lucas's son. Alas, young man, what has
brought you hither?"

"The fear of God and the love of His Word," said Jack. "But
come, sir, arise and eat, that you may be strengthened for
the day's trial."

"And what will strength avail?" asked the ship-owner


somewhat peevishly. "Can we break out of the dungeon by
dint of strength? Or can we bend the hard hearts of our
enemies?"

"The God we serve can do both, brother," said the old


shepherd; "or, failing that, He can give us strength to
confess that truth which shall minister to us an entrance
into His Eternal Kingdom. But come, arise, and eat at all
events. There is no use in refusing such good things as we
have."

Master Dennett essayed to eat, but desisted after a few


mouthfuls, and threw himself upon his pallet again.

Jack made a tolerable meal, and then bestirred himself to


render the place as comfortable as might be. The rest of the
day passed quietly enough.

Master Dennett lay on his pallet and wept over his hard
fate.

Jack and his uncle talked quietly together, recalling many


passages of Scripture, and encouraging each other to
steadfastness in the trial which they knew was awaiting
them. Towards night, the jailer brought in their evening
meal, and a large bundle.

"Here are some matters sent you from home," said he to


Jack, "bedding and such like, as I guess. Your father hath
been here, and has begged me to be kind to you, as why
should I not? You never harmed me, I trow."

Jack warmly thanked the jailer, who, surly as he was,


seemed disposed, indeed, to be as kind as his duty allowed.

The bundle contained bedding and linen, and artfully


concealed in the centre of a great loaf, some paper, a
pencil, and the means of striking a light, together with two
wax tapers. There was also a Psalter, in which Jack
perceived a leaf doubled down. He opened the book, and
found underlined the passage, "Be of good courage;" "Fear
not," and others of similar import, and doubly underscored
the word "Wait." He turned to the first page and read the
name of Father John. There were glad tears in the boy's
eyes as he showed the book to his uncle.

"The good, kind, old man!" said Thomas Sprat. "I know not
what he can do, and yet I thank him with all my heart. I
would not have believed anything would lead him to make
such an exertion. For myself, I hope nothing in this world
save a speedy passage out of it, and that my age gives me
warrant to expect: but I would gladly have you, my son,
saved from the fiery trial, if it might be done without your
denying the faith."

"Better death an hundred times than that!" said Jack.

"Be not confident, young man," said Master Dennett,


apparently somewhat displeased. "Better bethink yourself
how you will answer when you are brought before the
council."
"I am not over-confident, I trust," replied Jack; "but I trust
in Him who says, 'I will never leave thee nor forsake thee,'
and therefore I am bold to say, 'The Lord is my helper: I will
not fear what man may do unto me.' As to meditating how I
shall answer, I make bold to refer you to the words of our
Lord: 'When they take you up, take no thought how or what
ye shall speak: for it shall be given you in that same hour
what ye shall say. For it is not you that speak, but the Spirit
of your Father which speaketh in you.'"

"Ay, but those words were not spoken to men like us," said
Master Dennett. "They were spoken to apostles and saints."

"And what were the apostles and saints but common simple
men like to us?" asked Thomas Sprat. "Are not all God's
children called to be saints, and does He not promise the
same grace freely to all if we are but faithful?"

"Alas, my faith is not like yours," said Master Dennett. "You


are, besides, an old man, and must soon die at any rate;
but I cannot but bethink me of my young wife and her
babes, and the happy fireside I left but yesterday, with my
old mother sitting in the chimney corner with my youngest-
born on her knees. Little did I think as I bade them farewell
and went out to my business, that the evening would find
me here."

And the poor man threw himself on the pallet again in an


agony of grief.

"It is indeed hard for flesh and blood," said the old man.
"The spirit is willing, but the flesh is weak. We will pray for
and with you, brother, that you may have strength in the
evil day."

The night passed without disturbance, and in the morning


came another basket of provisions from home.
"Your father has sent meat and alms to all the prisoners—
debtors and all," said the jailer; "and a handsome present
to my wife as well. He might have spared that, but he is a
kind and liberal man. Truly, you have no cause to thank
them who brought you into this scrape."

"Nobody led me into it, good Master Davis," said Jack. "I
thank you heartily for bringing me these things. Have you
heard whether we are to be brought to trial this day?"

"Nay, I am in none of their secrets," growled the jailer, and


withdrew.

Jack made haste to examine the provisions. In one loaf, he


found a short letter from his father, full of affection. In the
other, he discovered what astonished him beyond measure.
It was a small book carefully wrapped up, which, on being
opened, proved to be the Testament lately given him by
Arthur Brydges. In the envelope was written in Anne's hand,
"Forgive and pray for me! A. L."

Master Dennett had also received a missive from his wife,


and while he was reading it, Jack took the opportunity to
show Anne's gift and note to his uncle. "I know not what to
think," said he. "It is Anne's hand, I am sure. I cannot
wonder so much at what she hath written, but that she
should send me the Testament passes my comprehension."

"It is indeed strange," said Thomas. "Can she have


repented of what she has done?"

"I cannot but hope so," replied Jack, "if only for her own
sake. I have all the time thought she was fighting against
her inward convictions. Poor maiden! I forgive her with all
my heart. I suppose I had better destroy this writing,
though I should love to keep it."
"Destroy it by all means," said the shepherd hastily, "lest it
bring the poor girl into trouble."

With the next morning came Brother Joseph and a


summons to the prisoners.

"Nay, not so fast, my young scholar," said the sacristan,


with a sneering laugh, as Jack rose to accompany his uncle.
"Your time will come soon enough."

"Am I not then to go with my uncle?" asked Jack. "You are


to stay where you are till you are called, when, mayhap,
you may wish yourself back again."

"Farewell, then, dearest son of my love!" said the old


shepherd, embracing and kissing Jack. "Fear nothing, but
remain in prayer and meditation of that goodness and
faithfulness which will fail neither of us. Master Dennett, let
us this day play the man for our Master. Once more,
farewell, my dear lad. Pray earnestly for me, but have no
fears. I am not alone in this matter, but One goes hence
with me who will not suffer me to fall."

"Enough of these blasphemies!" said Brother Joseph


harshly. "And spare your breath for your own porridge. It
will be hot enough to need it all. As for you, young sir,
bethink you well, for I tell you unless you wholly recant and
confess who were your movers in this thing, not all your
Greek and Latin can save you from the fire, here or
hereafter."

"You do but throw away your words," returned Jack. "I


would rather be in my place than yours."

The whole of that day Jack was left alone. It was the
longest day of his life. The little book which Anne had so
strangely sent him was his greatest comfort, and he read till
his eyes ached with the dim light, striving to impress on his
memory the words of the sacred text, lest the book should
be found and taken from him.

When he could see no more, he found a bit of wood which


had once formed a part of a rude bench, and busied himself
in carving some crosses to be sent as farewell gifts to his
father, sister, and other friends. He was still so engaged
when the jailer came to pay his evening visit.

"Where are my uncle and Master Dennett?" was Jack's first


question.

"Ask me no questions; you will know soon enough," was the


gruff answer.

"I pray you, Master Davis," said Jack, in some agitation,


"tell me how it has fared with mine uncle! Hath he been
condemned?"

"Yes, then, if you must know," returned the jailer. "There


was no chance for him. They said he had been respited
once before—that his father was burned for a Lollard, while
he was pardoned for his youth, and by the intercession of
the old knight. Brother Joseph, as they call him, testified
that he had overheard the old man instructing you in
matters of heresy, and that you had both read from the
Lutheran books. He was especially bitter against yourself.
Then they went about with the old man to learn who had
purveyed him the Testament, but they could get no
satisfaction from him. I promise you he answered them
roundly. Well, the end of it all is, the poor old father is to be
burned tomorrow, and you are to be carried to see the
show. So there! It is a shame. I care not who hears me say
it, and he like a father to you."
"So said one of the priests. ''Tis like seething the kid in its
mother's milk,' said he, and old Thomas, who disdained to
say a word for himself, plead earnestly for you that you
might be spared the sight, but they said it was for your
soul's sake, and they would not hear him. What now! Keep
up like a man! I have more for you to hear. See, drink this,"
said the jailer, with rough kindness, holding a cup to Jack's
lips. "I have a message for you, and I promised to deliver
it."

Jack made an effort to overcome the faintness which was


stealing over him, and roused himself to hear the rest.

"The old man bade me tell you to be of good courage and


care not for what was to happen to him; 'for,' says he, 'my
pain will be but short and my happiness eternal, and so will
yours be, so you be but faithful.' There, I had no business
to tell it you, but I am not one to refuse a request to a
dying man."

"Master Dennett?" asked Jack.

"Oh, he hath recanted and confessed all," answered the


jailer, with a touch of scorn. "He was a cock of another sort,
I promise you. He is to do penance tomorrow in face of the
people, and suffer some fine. But I pray you consider well
what you are about, for this monk is in fiery earnest, and it
were pity of your father's son to suffer such a death."

"And will you not let me see my uncle again?" Jack asked.

"I could not, if I would," replied the jailer.

"The old man is not here, but confined in the room in the
church tower yonder. Fare you well."
When Jack was left alone, he sat down on his bedside like
one stunned. Burned! That good, innocent old man! That
one whom he loved like a father—who had been truly, and
not in mere name, a spiritual father to him. Burned alive!
And he was to see it! There was no escape. He was in hands
which knew not how to show mercy, and which would never
spare him one pang.

He said to himself that he had expected this—that he had


known all along that it would come at last; but none the
less did it come on him with the suddenness of a hard blow.
There are certain things for which no amount of preparation
will prepare us. Then would come the old horrible thought—
was it worth while after all? Was he not sacrificing life and
reputation for a mere dream—a figment of the imagination?
Was not one religious belief as good as another—were they
not alike the inventions of men? Then, how many good men
had believed that which he was about to die for denying!
His father believed it still—so did Father John and my lady.
Might it not be true, after all? And if it were not strictly so,
was it not at any rate as true as the rest? Might he not
profess his own belief, and so escape till better times—those
times which Master Fleming believed would surely come,
when the storm should have spent itself and passed away?

He might keep his Bible and read it in secret, or he might


slip away and go abroad to Wittenburg, where he could
confess the truth without fear.

But Jack had learned already that the devil is never to be


conquered by listening to and arguing with him, but by
taking refuge from his malice and sophistry in the presence
of God.

He threw himself on his knees, and then on his face, and


there poured out the bitterness of his soul. At first, he could
say little more than "Lord help me! Lord deliver me!" over
and over again, but by degrees he grew calmer, and the
quieting and comforting influence of the Holy Spirit made
itself felt in his soul.

Promise after promise came thronging to his mind, full of


beauty and force as he had never known them before, and
at last the full crowning work of Divine grace was wrought
in his soul, and he was able to say for his friend as well as
for himself, "Thy will be done on earth as it is in heaven."
He had never felt any fear for his uncle's steadfastness, and
he no longer had any as regarded his own. He felt sure that
the Lord was faithful who had promised; and that strength
would be given him according to the work he had to do.

He rose at last, and, lighting his candle, he took out the


precious little book which had so strangely come to him, but
he had read barely one chapter before he heard footsteps
approaching, and hastily extinguishing his light, he thrust
that and his book far into the straw of his bed. He had
hardly done so before his door was unlocked and Father
Barnaby entered his cell.

"You watch late, my son," was his first greeting; "methinks


you should be glad to sleep."

Jack simply inclined his head.

The priest put down the lantern he carried, and sat himself
down on the pallet opposite to Jack, as if prepared to enter
into conversation. Jack quietly waited for him to begin.

"You have heard the result of the trial to-day, I suppose,"


said Father Barnaby, after some minutes silence.

Jack assented.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

Вам также может понравиться