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

Where Can Buy Beginning Ethereum Smart Contracts Programming: With Examples in Python, Solidity, and JavaScript Lee Ebook With Cheap Price

Smart

Загружено:

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

Where Can Buy Beginning Ethereum Smart Contracts Programming: With Examples in Python, Solidity, and JavaScript Lee Ebook With Cheap Price

Smart

Загружено:

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

Download the full version of the textbook now 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/

Explore and download more textbook at https://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/

textbookfull.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/
textbookfull.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/
textbookfull.com

The Visual Elements Design A Handbook for Communicating


Science and Engineering 1st Edition Frankel

https://textbookfull.com/product/the-visual-elements-design-a-
handbook-for-communicating-science-and-engineering-1st-edition-
frankel/
textbookfull.com
Problems in organic structure determination : a practical
approach to NMR spectroscopy First Issued In Hardback
2017. Edition Linington
https://textbookfull.com/product/problems-in-organic-structure-
determination-a-practical-approach-to-nmr-spectroscopy-first-issued-
in-hardback-2017-edition-linington/
textbookfull.com

2015 ASME Boiler and Pressure Vessel Code Section V


Nondestructive Examination 1st Edition American Society Of
Mechanical Engineers
https://textbookfull.com/product/2015-asme-boiler-and-pressure-vessel-
code-section-v-nondestructive-examination-1st-edition-american-
society-of-mechanical-engineers/
textbookfull.com

Civil Society Second Edition The Critical History of an


Idea John R. Ehrenberg

https://textbookfull.com/product/civil-society-second-edition-the-
critical-history-of-an-idea-john-r-ehrenberg/

textbookfull.com

Love and Marriage Across Social Classes in American Cinema


1st Edition Stephen Sharot (Auth.)

https://textbookfull.com/product/love-and-marriage-across-social-
classes-in-american-cinema-1st-edition-stephen-sharot-auth/

textbookfull.com

Framework for Improving Critical Infrastructure


Cybersecurity National Institute Of Standards And
Technology
https://textbookfull.com/product/framework-for-improving-critical-
infrastructure-cybersecurity-national-institute-of-standards-and-
technology/
textbookfull.com
The Oxford Handbook Of Plato Gail Fine

https://textbookfull.com/product/the-oxford-handbook-of-plato-gail-
fine/

textbookfull.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.
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
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
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
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
Random documents with unrelated
content Scribd suggests to you:
banished after it had been put in force went away and made no
attempt to come back; but in June 1659 four who were more resolute
and determined appeared in Boston with the avowed intention of
defying the law. They were William Robinson, Marmaduke
Stevenson, Nicholas Davis, and Mary Dyer. They were arrested and
sentenced to banishment (September 12th), with the threat that they
should suffer death if they remained or returned to the colony.
Nicholas Davis and Mary Dyer “found freedom to depart; but the
other two were constrained in the love and power of the Lord not to
depart, but to stay in the jurisdiction, and to try the bloody law unto
20
death.” They withdrew to the New Hampshire settlements, but in
about four weeks returned to Boston prepared to die, and were
joined there by Mary Dyer, who had decided to share their fate. They
were arraigned before the General Court, which was then in session,
and admitting that they were the persons banished by the last Court
of Assistants, were sentenced to be hanged in a week from that time
21
(October 19th). The authorities evidently were afraid of popular
sympathy, for they gave orders for a military guard of one hundred
men to conduct them to the gallows, while another military force was
charged to watch the rest of the town, and the selectmen were
instructed to “press ten or twelve able and faithful persons every
night to watch the town and guard the prison.”
Neither side would yield: the Quakers had come back with the
declared purpose of dying for their faith and for the principle of
religious liberty; the authorities did not dare to withdraw from the
position in which they had rashly placed themselves, and the leaders
do not seem to have had any desire to do so. They felt that the
question of their authority was at stake, and that if they yielded their
power over the people would be gone. They were willing to claim for
themselves and their institutions the protection of the laws of
England, but they would not admit any appeal to those laws when
they conflicted with the colonial regulations. They claimed to own the
colony in full sovereignty, in virtue of their charter on the one hand
and their deeds from the Indians on the other, and they argued that
they had the same right to exclude obnoxious and dangerous
persons, and to destroy them if they persistently thrust themselves
upon them, that a householder has of resisting a burglar, or a
shepherd of killing the wolves that break into his sheepfold.
It is a great mistake to say that they had come to the colony from
a zeal for religious liberty. What they had come for was to be in a
place where they could order religious affairs to suit themselves. As
Besse, the Quaker historian, shrewdly remarks: “They appear not so
inconsistent with themselves as some have thought, because when
under oppression they pleaded for liberty of conscience, they
understood it not as the natural and common right of all mankind, but
22
as a peculiar privilege of the orthodox.”
The tragedy was performed on the twenty-seventh day of
October 1659; the prisoners, walking hand in hand, were brought to
the gallows by the soldiers. They were insulted in their last moments
by the bigoted Wilson, and when they tried to address the people
their voices were drowned by the beating of the drums. Robinson
and Stevenson died bravely, and Mary Dyer mounted the ladder to
meet her fate; her skirts were tied, the rope was about her neck, and
she was on the point of being “turned off,” when she was released by
the magistrates in consideration of the intercession of her son, who
had come up from Rhode Island to try to save his mother’s life. She
unwillingly accepted the grudging gift, and went back to Rhode
23
Island.
The popular feeling was so strong against the magistrates for
their severity, that they thought it best to put forth a declaration, in
which they argued that their proceedings were justified by the law of
self-defence, and by the precedent of the English laws against the
Jesuits; and they calmly stated that what they had done was only to
present the point of their sword in their own defence, that the
Quakers who had rushed upon it had become “felons de se,” and
that their former proceedings and their mercy to Mary Dyer upon the
“inconsiderable intercession” of her son “manifestly evinced that they
24
desired their lives absent rather than their death present.”
The bodies of the unfortunate men were treated with indecent
brutality, and were buried naked beneath the gallows. Mrs. Dyer
remained away for six months, and then the spirit moved her to
return once more and die. Her husband wrote to Endicott to beg her
life, but without avail. No mercy could be shown her as long as she
defied the law. It is said that her life was offered her if she would
promise to keep out of the colony henceforth, but she declined to
25
receive the favor. “In obedience to the will of the Lord I came,” said
she, “and in his will I abide faithful to the death.”
Meanwhile the prisons and the house of correction had been the
fate of other delinquents, and the jailer and executioner had had
plenty of employment with the scourge. The Southwicks, with their
eldest son Josiah, were whipped, fined, and imprisoned for
withdrawing from the public services and worshipping by
themselves, and their two younger children were ordered to be sold
26
as slaves to the West Indies in satisfaction of the fines imposed.
W. Shattuck was whipped, fined, and imprisoned. Sarah Gibbons
and Dorothy Waugh were whipped. Hored Gardner, a woman with a
sucking babe, and a young girl who came into the colony with her,
were scourged with the “three-fold knotted whip, and during her
tortures she prayed for her persecutors.”
William Brand was thrown into the House of Correction, and,
refusing to work, was beaten constantly by the brutal jailer with a
tarred rope an inch thick. The pathetic record says: “His back and
arms were bruised black, and the blood was hanging as in bags
under his arms, and so into one was his flesh beaten that the sign of
27
a particular blow could not be seen, for all became as a jelly.”
William Leddra and Rouse, whose ears had been cut off, were
ordered to be whipped twice a week with increasing severity until
they consented to work, and were at last dismissed from the colony
under pain of death if they returned.
Patience Scott, a girl eleven years old, was imprisoned as a
Quaker, but discharged, after a period of detention, in consideration
of her youth; but her mother, Catherine Scott, for reproving the
magistrates for a deed of darkness, was whipped ten stripes,
although she was admitted by them to be otherwise of blameless life
and conversation.
Christopher Holden, who, in spite of losing his ears in 1658, had
returned once more, was banished upon pain of death by the same
28
court that had hanged Robinson and Stevenson. Seven or eight
persons were fined, some as high as ten pounds, for entertaining
Quakers, and Edward Wharton, for piloting them from one place to
another, was ordered to be whipped twenty stripes, and bound to his
good behavior. Divers others were then brought upon trial, “for
adhering to the cursed sect of Quakers, not disowning themselves to
be such, refusing to give civil respect, leaving their families and
relations, and roaming from place to place vagabonds like”; and
Daniel Gold was sentenced to be whipped thirty stripes, Robert
Harper fifteen, and they, with Alice Courland, Mary Scott, and Hope
Clifton, banished upon pain of death; William Kingswill whipped
fifteen stripes; Margaret Smith, Mary Trask, and Provided Southwick
29
ten stripes each, and Hannah Phelps admonished. In November,
William Leddra, who had been released, returned, and was at once
arrested. On his trial the opportunity of withdrawal was again
extended, but he refused to accept it, and was executed March 1,
1661. As he ascended the ladder he was heard to say: “All that will
be Christ’s disciples must take up the cross,” and just as he was
being thrown from its rounds, he cried in the words of Stephen, “Lord
Jesus, receive my spirit.” Wenlock Christison, who had been before
this sentenced to death, but allowed to leave the colony, had
returned, and during Leddra’s trial he came boldly before the Court
and told the astonished judges: “I am come here to warn you that ye
shed no more innocent blood.” He was at once arrested, and was
brought up for trial three months later. There was an unusual
difference of opinion in regard to the case, and the condemnation
was only secured by the violence of Endicott, who was able to
browbeat the others into consent. But the sentence they passed was
never executed. The people were tired of bloodshed, and the
opposition which was shown in the General Court to any further
proceedings was so great as to make a change in the law
30
necessary.
The humanity of the delegates to the Court was probably
considerably quickened by a sense of the dangerous position in
which the colony stood since the restoration of Charles II., who, they
might naturally fear, would call them to an account for their
proceedings, especially as the colony had allowed nearly a year to
pass without any recognition of the change in the political situation.
The General Court attempted to save its dignity by interposing a
still greater number of shameful and unusual punishments between
the first offence and the death penalty, and declared that, “being
desirous to try all means with as much lenity as might consist with
safety to prevent the intrusions of the Quakers, who had not been
restrained by the laws already provided, they would henceforth order
that such intruders should be tied to a cart’s tail and whipped from
town to town toward the borders of the jurisdiction. Should they
return after being dealt with thus thrice, they were to be branded with
the letter R on their left shoulder, and be severely whipped and sent
away again at the cart’s tail. Should they again return, they were to
31
be liable to the former law of banishment under pain of death.”
It is quite possible that this appeared to be lenity to men like
Endicott and Norton, but it is very doubtful whether the Quakers so
considered it. It did not prevent, though it anticipated, an order from
the king directing that any Quakers imprisoned or under sentence
32
should be released and sent to England for trial. To make this still
more galling to the pride of the colony, it was sent by Samuel
Shattuck, a Salem Quaker, who had been banished from the colony
under pain of death if he should return, and who, we cannot doubt,
thoroughly enjoyed his mission and the humiliation of Endicott. For a
short time the order was obeyed and then the “lenient” laws were put
in force again; and, as many delicately nurtured Quaker women
found to their cost, the “tender mercies” of the saints were cruel.
Palfrey remarks, with great gratification apparently, that “no hanging,
no branding, ever took place by force of this law,” but that “under its
provisions for other penalties the contest was carried on for a
considerable time longer.”
It would be wearisome to cite all of the subsequent proceedings;
a few of them will suffice to show that the treatment of the Quakers
still continued to be extremely severe, and that in spite of it all they
persisted in braving the threats of the magistrates. It was not until
1679, when religious toleration was forced against their wills upon
the good Christians of Massachusetts, that the Quakers found any
safety within the boundaries of the colony.
In 1661, when the Quakers were set free at the command of the
king, some of them were whipped at the cart’s tail twenty stripes
33
apiece, on the ground that they were vagabonds.
In 1662, Josiah Southwick, who had returned from his
banishment, was whipped at the cart’s tail in Boston, Roxbury, and
Dedham, and dismissed into the woods with a warning not to return.
The magistrates apparently had found that their old style of whipping
was too humane; for the whip used on this and several subsequent
occasions was made, not of cord, “but of dried guts like the bass
strings of a bass viol,” with three knots at each end—a weapon
which, according to contemporary testimony, made holes in the back
34
that one could put pease into.
In December 1662 Ann Coleman, Mary Tompkins, and Alice
Ambrose were stripped to the waist and whipped at the cart’s tail in
Dover, Hampton, and Salisbury, and were forced to walk the entire
distance in slush and snow up to their knees. The “lenient” sentence
required indeed that they should be whipped in each town in the
jurisdiction, but the constable at Newbury found in the warrant some
flaw by which he was able to release them. On their return to Dover,
they were seized by the constables by night, dragged face
downwards over snow and stumps to the river, one of them at least
was doused in the stream and dragged after a canoe, and they were
only released because the storm was too severe for their tormentors
35
to brave. Ann Coleman, again, with four friends, was whipped
36
through Salem, Boston, and Dedham. Elizabeth Hooton, a woman
of over sixty years of age, Fox’s first convert, was first imprisoned,
and then carried two days’ journey into the wilderness, “among
wolves and bears,” and left there to shift for herself. On returning,
she was kept in a dungeon at Cambridge two days without food, tied
to the whipping-post and flogged there, then taken to Watertown,
where she was flogged with willow rods, flogged again at Dedham,
and then carried into the woods as before. Coming back once more
to fetch her clothes from Cambridge, she and a companion, “an
ancient woman,” and her daughter were whipped in private, in spite
of which we find her coming once more to Boston, and on that
37
occasion she was whipped again at the cart’s tail. Mary Tompkins,
Alice Ambrose, and Ann Needham also appear again and again in
the records of suffering. One Edward Wharton, who was most
resolute in defying the authorities, was constantly under arrest, and
even a bare enumeration of his floggings would fill a page.
In 1665 Deborah Wilson, for going naked through the streets of
Salem “for a sign,” was whipped; but the constable executed his
office so mercifully that he was displaced. There is a pathetic
incident mentioned by Bishop, the Quaker historian, that “her tender
husband, though not altogether of her way, followed after,” as she
underwent her punishment, “clapping his hat sometimes between the
38
whip and her back.”
Eliakim Wardwell, at Newbury, was fined heavily in 1665 for
entertaining Wenlock Christison; and this injustice in addition to the
other cruel acts, so affected his wife Lydia that, although a modest
and delicate woman, she came naked into the meeting at Newbury,
as a testimony against them. She was seized and hurried away to
the court at Ipswich, which sentenced her to be whipped at the
nearest tavern post. Bishop says:

Without Law or President they condemned her to be tyed to


the fence Post of the tavern, where they sat, which is usually
their Court places, where they may serve their ears with Musick,
and their bellies with Wine and gluttony; whereunto she was tyed
stript from the Waste upwards, with her naked breasts to the
splinters of the Posts and there sorely lashed, with twenty or
thirty cruel stripes, which though it miserably tore and bruised
her tender body, yet to the joy of her Husband and Friends that
were Spectators, she was carried through all these inhumane
cruelties, quiet and chearful, and to the shame and confusion of
these unreasonable bruit beasts, whose name shall rot, and their
39
memory perish.

Eliakim, her husband, some time after, for vindicating her


character, was by order of the court at Hampton bound to a tree and
whipped fifteen lashes. In 1675 a law was passed which made it the
duty of the constables, under heavy penalties, to break up all Quaker
meetings and to commit those present to the House of Correction,
there to have the discipline of the house and be kept to work on
bread and water, or else to pay five pounds.
In 1677 an order was passed requiring an oath of fidelity to the
country, and legal liabilities were imposed upon all who refused the
oath. This struck directly at the Quakers, and was believed by them,
whether justly or not, to have been made for the purpose of vexing
40
and plundering them. A vigorous protest against it was made in
writing by Margaret Brewster, who came from Barbadoes to bear her
testimony against the law and to declare the evils that were coming
upon the colony. Having, as she declared, “a foresight given of that
grievous calamity called the Black Pox, which afterwards spread
there to the cutting off of many of the People. Wherefore she was
constrained in a prophetic manner to warn them thereof, by entering
into their publick assembly clothed in sackcloth and ashes, and with
her face made black.” For this she and four of her friends were
arrested and cast into prison upon the charge of “making a horrible
disturbance, and affrighting the people in the South Church in
Boston in the time of the public dispensing of the Word, whereby
several women ... are in danger of miscarrying.” She was whipped at
the cart’s tail twenty lashes, and the young women who were with
her were forced to accompany her during her punishment. Twelve
Quakers, who were arrested the same day at a Quaker meeting,
41
were whipped, and fifteen the week following.
In the other colonies the sufferings of the Quakers were not so
severe, though in Plymouth they had to endure banishment, fines,
and whippings. In Connecticut, thanks probably to the wisdom of
John Winthrop, the only cases which occurred were met with
banishment, and the Quakers seem to have respected the
jurisdiction where they were mercifully treated. In New Haven there
were several prosecutions; Southold on Long Island seems to have
been the place most frequented by the Quakers, though they also
appeared in Greenwich. The only case of extreme severity was that
of Humphrey Norton, who had already borne his torturing in
Massachusetts, where he had enraged the magistrates by his appeal
to the laws of England. He was arrested at Southold and taken to
New Haven, where he was “cast into Prison and chained to a Post,
and kept night and day for the space of twenty Days with great
Weights of Iron in an open Prison without Fire or Candles in the
bitter cold Winter (December 1657), enough (reasonably) to have
starved him,” as Bishop writes. When he attempted to reply to
Davenport in the Court, he was not suffered to speak, but was
gagged with “a great Iron Key, tied athwart his mouth.” After his trial
42
was over he was whipped thirty stripes and branded H in the hand.
Several who sympathized with or who entertained Quakers were
punished with heavy fines. In New Netherlands they fared little
43
better; and in Virginia the much-flogged Mary Tompkins and Alice
Ambrose found little mercy from the cavaliers, being put in the pillory
and whipped with a cat-of-nine-tails so severely that blood was
drawn by the very first stroke; and George Wilson, “in cruel irons that
rotted his flesh, and long imprisonment, departed this life for his
44
testimony to the Lord.” In Maryland they were subjected to fine and
imprisonment for refusing to take an oath or to serve in the militia.
45
Liberty of conscience was granted in 1688.
It was in New England, and especially in Massachusetts, that the
persecution was general and severe. The magistrates, as a rule,
defended their action, as necessary to the maintenance of their
authority and to the preservation of order and orthodoxy; and their
conduct has been extenuated and excused, if not actually defended,
by modern New England historians.
It is not a pleasant history, but there is something to be said upon
the side of the authorities even by one who has no admiration for
them or sympathy with them. The Puritans had not come to New
England for liberty of thought, but for liberty of action. Having failed,
as they thought at the time, to secure the triumph of their views in
the church and state of England, they preferred to leave the struggle
and come to New England, where they could live under their own
system without being obliged to contend or suffer for their faith—a
point upon which the Quaker controversialists make some very
46
sharp remarks.
They considered the territory which they held to be their own
peculium, and claimed that by their charter they had acquired
absolute sovereignty in its limits, subject to no appeal to England;
and they realized that if appeal to England was granted, their
absolute authority was at an end. One of the leading colonists is
reported to have said: “If we admit appeal to the Parliament this year,
next year they will send to see how it is, and the third year the
government will be changed.” The settlement also had in their eyes a
religious character; it was founded, as they boasted, for religion and
not for trade, and they held that they had a right to dictate the
religious usages and practices therein, as was shown by their
treatment of Mrs. Hutchinson and Wheelwright, Roger Williams and
Gorton, Child and Maverick, not to mention Morton of Merry Mount.
They believed the Quakers to be a pernicious sect, confounding
them with other fanatical bodies which they resembled, and they
feared that the natural consequence of the claim which they made to
immediate revelation would be communistic attempts at the
overthrow of the established order, such as had been seen a
hundred years before in Germany. From these premises the
conclusion was a natural one, that their duty was to nip the evil in the
bud, to crush the Quakers before they became strong enough to be
dangerous to the state. Their action in banishing the first that arrived,
before any overt acts were committed, was undoubtedly technically
illegal; but if the Quakers had been in reality what they fancied them,
no one would have blamed them for their prompt decision. Besides,
they had a law by which they were accustomed to banish heretics,
and the Quakers might very well come under that description.
As regards the compelling shipmasters to carry them back to the
port from which they had come, such a custom had prevailed from a
very early date in the case of undesirable immigrants. Winthrop, in
his History mentions the reshipping to England of a crazy pauper
woman whom the parish of Willesden had sent over to the colonists
in Massachusetts. The Quakers came in spite of banishment, and
the more they were imprisoned and beaten the more daring became
their defiance, the more violent their abuse. They spared neither
priest nor magistrate, and the floods of denunciation which they
poured out were portentous. It is not to be wondered at that a stern
and severe people, living a hard and cruel life of constant struggle
with the elements, and in the constant dread lest their privileges
should be assailed, should have been cruel in their treatment of
these incorrigible offenders.
Judged by the common standard of the age, the cruelty of the
treatment of the Quakers is not so remarkable as to be singled out
above all other cruelties for reprobation. The Quakers themselves
were cruel at times. George Fox himself is said to have been a
witch-finder; and a son of the Samuel Shattuck who bore the king’s
mandate to Endicott appears in the Salem witchcraft trials as a
47
prominent witness against some of the unfortunates. The folly and
fatuity of the treatment adopted is more of a point to notice. In the
colonies where the Quakers were let alone they caused no trouble.
Palfrey’s sneer, that there was no order to disturb in Rhode Island,
may be justified perhaps as regards that colony, but Connecticut
certainly was a well-ordered commonwealth. In Massachusetts, on
the contrary, the same persons kept coming again and again, and
the severer the punishments the madder became their actions. It
should be remembered that the acts usually mentioned as justifying
the Puritans’ severity, such as the performances of the naked
women at Salem and Newbury, of the men who broke bottles on the
pulpit steps, and of the woman who smeared her face with black and
frightened the matrons in the Old South church, were not committed
until after the persecution had been carried on for years, until scores
of women had been stripped naked and flogged by the authorities,
until men had had their ears cut off, and until three men and one
woman had been put to death upon the gallows. The persecution
was a blunder, and the details of it made it a blunder of the most
atrocious description. Power was put into the hands of local and
irresponsible magistrates to sentence men and women to these
shameful and unusual punishments, and brutal constables and
jailers were entrusted with the enforcement of the law without any
due supervision. The most painful part of the whole history is the
attitude of the Puritan clergy, in Massachusetts especially. They were
bitter and bigoted, hounding on the magistrates to their cruel work,
and insulting the unfortunate wretches when they came to suffer.
Quaker instinct rightly, no doubt, fixed upon John Norton as the
“Fountain and Principal unto whom most of the cruelty and
48
bloodshed is to be imputed.”
For the constancy of the Quakers themselves, their endurance
and their fortitude, one can feel nothing but admiration. One
remembers how, centuries before, men who like them were willing to
die rather than to deny their faith had been called the enemies of
mankind, and accused of a perverse and execrable superstition. It
must be admitted, however, that their behavior was often of a kind
that would not be allowed to-day any more than it was then, although
it is to be hoped that our modern statecraft would find milder and
more efficient means of repression than did our predecessors in New
England; yet when one remembers how the Mormons were treated
in Illinois and Missouri, and how the mob destroyed a Roman
Catholic convent in Massachusetts, within the memories of living
men, we may think it perhaps prudent not to be too sweeping in our
condemnation.
The fundamental difficulty in the Puritans’ position was their
illegal and unconstitutional government. To maintain that, they were
led to deny to other Englishmen their rights, and to assert an
independence of the home authorities which was little short of actual
separation.
The second evil principle in their government was the union of
church and state, or rather the subjection of the state to the church,
a church moreover in which the people had no rights except by favor
of the ministers, a church that was a close corporation and imbued
with the spirit of the law of Moses rather than that of the gospel of
Christ. In church, as well as in state, there was a consciousness that
their existence was illegal and illegitimate; that, in spite of their
protests to the contrary, they had separated from their fellow-
Christians in England and had formed a polity for themselves; hence,
just as they felt it necessary to manifest their political authority by
acts of severity upon any who questioned it, so they deemed it
necessary to maintain their orthodoxy by persecuting those who
differed from them in religion. They were ill at ease both politically
and religiously, and they sought to disguise the fact from themselves,
by making proof of all the power that they possessed. Hence it was
that the conflict arose which has stained with innocent blood the
early history of the land. It is not to be wondered that the Quakers
should see, in the horrible death of Endicott and the miserable end of
49
Norton, the hand of an avenging Providence, or that they should
believe that for a distance of twenty miles from Boston the ground
was cursed so that no wheat could ripen because of a blood-red
50
blight that fastened upon it. But we, who live at a time when we
can view the history of the struggle with calmness and impartiality,
may respect the grim determination of the severe magistrates who
felt it their duty, at whatever cost, to keep that which was committed
to their trust free from the poison of heresy and fanaticism, while we
sorrow at the blindness which hid from their eyes the folly and the
cruelty of their proceedings. We may sympathize with the tortured
Quakers, whom we now know to be harmless enthusiasts, yet
without approving or extenuating their mad actions, their abusive
language, or their grotesque indecencies; and we may hope that,
though at enmity in this life, yet, as Browning wrote of Strafford and
Pym,
“in that world
Where great hearts led astray are turned again,”

both now are able to respect each other’s loyalty of purpose and
fidelity to their respective conceptions of truth.
NOTES.
1
Vide infra, Note 6.
2
George Fox, Journal. It is well to notice that of the ministers
mentioned by Fox by name or parish, Nath. Stevens, the rector
of Fenny Drayton, was a Presbyterian of some eminence, and
was ejected for non-conformity in 1662. So also was Matthew
Cradock, the “priest of Coventry,” who was a distinguished
non-conformist divine. The priest at Mansetter, who advised
tobacco and psalm-singing, kept his living during the whole
period of the Commonwealth, and so may be presumed not to
have been a “Churchman” in the commonly received sense of
the term. “One Macham,” of whom Fox speaks, and who
seems to have treated him with more sympathetic kindness
than any of the others, was a loyal Churchman and was
sequestered in 1645, as a penalty for his adherence to the
bishop and the king to whom he had sworn allegiance. It is
rather surprising to find historians in general, even those who
should be better informed, assuming that, because these men
were filling the parishes of the Church of England, they were,
therefore, Church of England clergymen.
3
Bishop, George, New England Judged, London, 1661, pp. 14–
25.
4
Geo. E. Ellis, Memorial History of Boston, vol. i. p. 181.
5
Hubbard’s History of New England, p. 553.
6
Massachusetts Records, iv. (1), 276.
7
Bishop, 5–13.
8
Hazard, Historical Collections, ii. 349. Rhode Island Records, i.
374.
9
Mass. Records, iv. (1), 277.
10
Bishop, 38, 39.
11
Bishop, 40, 42.
12
Mass. Records, iv. (1), 308. Bishop, 50.
13
Mass. Records, iv. (1), 325.
14
Bishop, 72, 73.
15
Mass. Records, iv. (1), 345, 346.
16
Mass. Archives, vol. x. p. 246.
17
Mass. Records, iv. (1), 348. (In payment for this work Norton
received five hundred acres of land, a good price for a sermon.
Ibid., p. 397.)
18
The Heart of New England Rent at the Blasphemies of the
Present Generation. Printed by Samuel Green, Cambridge in
New England, 1659. The arguments used in this declaration
are so characteristic of the spirit of the times that the following
extract may be useful. The author has been demonstrating that
the Quakers were heretical on various points of the faith, and
that the Scriptures authorize the punishment of false believers.
He continues:
“But other Scriptures omitted, I shall here transcribe only two
more, both of which are eminently pregnant with this truth:
wherein also are cases put between the cause of God and our
near relations, on purpose to provide against obstructions in
this great business of religion.
The first we have Deut. xiii. per totum.
Relating to all times succeeding that constitution; ‘If thy
brother, the son of thy mother, or thy son, or thy daughter, or
the wife of thy bosom, or thy friend, which is as thine own soul,
entice thee secretly, saying, Let us go and serve other gods,
which thou hast not known, thou, nor thy fathers; Thou shalt
not consent unto him, nor hearken unto him; neither shalt thine
eyes pity him, neither shalt thou spare, neither shalt thou
conceal him.’ vers. 6, 8. The second we have Zech. xiii. 1, 3.
Expressly relating unto the times of the Gospel. In that day,
viz.: after the Coming of the Messiah in the time of the Gospel
when the families of the tribes shall mourne Chapt. xii. 11. The
familie of the house of David apart, & the familie of the house
of Nathan apart, etc. There shall be a fountain opened, i. e. the
doctrine of Christ under Moses’ dispensation is compared to a
fountain vailed, 2 Cor. iii. 13, etc. Under the Gospel
dispensation to a fountain opened. The vail of the Temple &
the ceremonial law being taken away. And it shall come to
pass that when any shall yet Prophecie, then his father & his
mother that begat him, shall thrust him through, when he
prophecieth. These words [thrust him through] may be
understood either of a Capital punishment judicially dispensed,
or of any other smart punishment piercing though not Capital.

* * * * *
“Wee through grace abhorre prejudicing the liberty of
conscience the least measure, and account such report of us
to be a slander. And through the same grace; Wee both dread,
and beare witness against, liberty of heresy, liberty to
Blaspheme the Blessed Trinity, the Person and Office of Christ,
the holy-Scripture, the tabernacle of God, and those that dwell
in heaven. Howsoever fallaciously transformed into, and
misrepresented under the plausible vizard of liberty of
conscience falsely so called. We say Religion is to be
perswaded with Scripture-reasons, not Civil weapons: with
Arguments, not with punishments. But blasphemies immediate
and heresies carried on with an high hand, and persisted in are
to be suppressed with weapons and punishments; where
reasons, and arguments cannot prevail.
We distinguish between Heresie (Quiet and alone,
Turbulent, i. e. incorrigible) accompanied with soliciting the
people to apostacy from the Faith of Christ to defection from
the churches, to Sedition in the Commonwealth. And that after
due meanes of conviction, and Authoritative prohibition.
We subject not any to Civil or Corporal punishment for
heresie, if quiet and alone. We do not inflict any Church-
censure in case of heresie, without doctrinal conviction on the
Churche’s part, and contumacy on the delinquent’s part
foregoing.
In case of Heresie incorrigible, in conjunction with
endeavours to seduce others thereunto, and tending to the
disturbing of Publick-order, we acknowledge it to be the pious
Wisdom of the Magistrate to proceed gradually, and where
gentler meanes may rationally be looked at as effectual, there
to abstain from the use of any severer remedie.
And according to this method, hath been the gradual
proceeding of the Magistrate here, with those (hitherto
incorrigible) Quakers, who from England have unreasonably
and insolently obtruded themselves upon us. 1. Instructing
them. 2. Restraining them untill an opportunity for their returne.
3. Publishing a law to warne and prohibite both them and all
others of that sect, from Coming into this jurisdiction: otherwise
to expect the house of Correction. And in case they returned
yet again, then to loose one of their eares, etc.
At last upon experience of their bold contempt of these
inferior restraints, and that after their being sent away again
and again, they continue to return yet again and again; to the
seducing of diverse, the disturbance, vexation and hazard of
the whole Colonie. The Court finding the Law passed, to be an
insufficient fence against these persons, proceeded to a
Sentence of Banishment.
Their restraint before the Law published, was but restraint in
the Prison, until an opportunity of shipping them away. They
who after the Law was published, would that notwithstanding,
break in upon us from England, or other forraign parts, by
Rode-Island, after their correction received, and discharging
their dues, might return again to the Island, if they pleased.
The wolfe which ventures over the wild Sea, out of a ravening
desire to prey upon the sheep, when landed, discovered and
taken, hath no cause to complain, though for the security of the
flock, he be penned up, with the door opening unto the fold fast
shut; but having another door purposely left open, whereby he
may depart at his pleasure either returning from whence he
came, or otherwise quitting the place.
Their Sentence of Banishment as Circumstanced, by an
Impartial and equal eye, may be looked upon as an Act which
the court was forced unto se defendendo, in defence of
Religion, themselves, the Churches, and this poore State and
People from Ruine: which the principles of confusion, daylie
and studiously disseminated by them, threatened to bring all
unto, if not seasonably prevented. Exile from a wilderness,
from a place of exile; though voluntarie, from a place;
confinement whereunto would indeed justly be called exile, is
an easie exile.” (Pages 48, 49, 53, 54.)
19
Rhode Island Records, i. 376–378. See also the letter of the
General Assembly, 378–380.
20
Bishop, 95.
21
Mass. Records, iv. (1), 383.
22
The Sufferings of the People called Quakers, by Jos. Besse,
London, 1753, ii. p. 177.
23
Bishop, 89–95, 109.
24
Hubbard’s History of New England, p. 173. See also an
Address to the King (Charles II.), Dec. 19, 1660, in which the
colonial authorities argue as follows: “Concerning the Quakers,
open and capitall blasphemers, open seducers from the
glorious Trinity, the Lord’s Christ, our Lord Jesus Christ, etc.
the blessed gospell, and from the Holy Scriptures as the rule of
life, open enemies to government itself as established in the
hands of any but men of their oune principles, malignant and
assiduous promoters of doctrines directly tending to subvert
both our churches and state, after all other meanes for a long
time used in vajne, wee were at last constrejned, for our oune
safety, to pass a sentence of banishment against them, vpon
pajne of death. Such was theire daingerous, impetuous, &
desperat turbulency, both to religion & the state civil &
ecclesiastical, as that how vnwillingly soever, could it have binn
avoyded, the magistrate at last, in conscience both to God and
Man, judged himself called for the defense of all, to keep the
passage with the point of the sword held towards them. This
could do no harm to him that would be warned thereby: theire
wittingly rushing themselves therevpon was theire oune act, &
wee, wth all humility, conceive a cryme bringing theire blood on
theire oune head. The Quakers died, not because of theire
other crymes, how capitall soever, but vpon theire superadded
presumptuous & incorrigible contempt of authority; breaking in
vpon vs notwthstanding theire sentence of banishment made
knoune to them. Had they not binn restreigned, so farr as
appeared, there was too much cause to feare that wee
ourselves must quickly haue dyed, or worse; and such was
theire insolency, that they would not be restreined but by
death; nay, had they at last but promised to depart the
jurisdiction, and not to returne wthout leaue from authority, wee
should haue binn glad of such an opportunity to haue sayd
they should not dye.” Mass. Records, iv. (1), 450–453. Bishop,
113.
25
Mass. Records, iv. (1), 419.
26
Mass. Records, iv. (1), 366. Bishop, 90, 91.
27
Bishop, 44–48, 52–54.

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