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

Beginning Ethereum Smart Contracts Programming: With Examples in Python, Solidity, and JavaScript Lee - Get instant access to the full ebook content

Документ представляет собой описание электронной книги 'Beginning Ethereum Smart Contracts Programming', написанной Вей-Менгом Ли, которая охватывает основы программирования смарт-контрактов на Ethereum с примерами на Python, Solidity и JavaScript. В книге рассматриваются ключевые концепции блокчейна, создание частной сети Ethereum, использование MetaMask и тестирование смарт-контрактов с помощью Ganache. Читатели могут получить доступ к дополнительным материалам и исходному коду на GitHub.

Загружено:

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

Beginning Ethereum Smart Contracts Programming: With Examples in Python, Solidity, and JavaScript Lee - Get instant access to the full ebook content

Документ представляет собой описание электронной книги 'Beginning Ethereum Smart Contracts Programming', написанной Вей-Менгом Ли, которая охватывает основы программирования смарт-контрактов на Ethereum с примерами на Python, Solidity и JavaScript. В книге рассматриваются ключевые концепции блокчейна, создание частной сети Ethereum, использование MetaMask и тестирование смарт-контрактов с помощью Ganache. Читатели могут получить доступ к дополнительным материалам и исходному коду на GitHub.

Загружено:

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

Explore the full ebook collection and download it 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/

OR CLICK HERE

DOWLOAD EBOOK

Browse and Get More Ebook Downloads Instantly at https://textbookfull.com


Click here to visit textbookfull.com and download textbook now
Your digital treasures (PDF, ePub, MOBI) await
Download instantly and pick your perfect format...

Read anywhere, anytime, on any device!

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

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

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

textbookfull.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/
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.
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
Another Random Scribd Document
with Unrelated Content
Was she glad or sorry that she had come?
She was glad!
It was one of the moments when good triumphed over evil in the
complex nature of Ethel Winans.
"It was Heaven that sent me here to rescue Precious," she thought
happily, and for awhile Lord Chester was forgotten while the sisters
made mutual explanations.
"So it was Lindsey Warwick, after all. The detectives suspected him
at first, but he hoodwinked them very cleverly," said Ethel.
"Oh, he is a fiend!" cried Precious shudderingly.
"Then you could never accept him as a lover?" Ethel asked curiously.
"Oh, never, never! He is very repulsive to me, with his keen little
eyes, and his thick lips, and his perpetual smirk. If I ever have a
lover I must have a grand, handsome one, as noble as papa, or
perhaps like your lover, Ethel—I do not know his name, but I saw
him at the ball with you, and I thought he was splendid. Well, when
I have a real lover he must be like that, Ethel!" cried Precious
innocently.
A shadow gleamed over Ethel's dusky beauty, and she thought:
"They are mutually attracted to each other. It is fate."
But she said carelessly:
"You are too young to dream of lovers yet, my dear, and when you
get safe home again you must devote yourself to your studies, and
not tease about going to balls. It was your willfulness about the
Inauguration Ball that brought you into this trouble."
"And papa will put that villain into prison for this, I know," cried
Precious, her voice a little stronger from the food and wine she had
taken. Then she hugged Kay around his neck and kissed the top of
his head.
"Darling old fellow, if it had not been for you Ethel would have come
and gone without finding me. Oh, how shall I ever pay you for this?
You shall have a golden collar with your name set in rubies—yes,
you shall. Papa will buy it for you, I know, to pay you for saving his
pet."
Kay showed as much boisterous delight as if he understood every
word, and kept licking her little hands with joy unutterable.
"And now, dear, we must get out of this place, and go home if you
think you are ready," smiled Ethel.
"Ready!" cried Precious gayly. "Well, I know I am very weak from my
long fast, but joy makes me feel like a new girl. I have nothing to
wear home but this blue wrapper over my ball dress, but no matter
—let us start at once. If I am too weak to walk I can crawl there, or
perhaps Kay will let me ride on his back," patting him tenderly.
Ethel turned the handle of the door, but it resisted her efforts, and
she recoiled with a low cry.
"Oh, Heaven, I had forgotten! I heard that old hag lock the door on
the outside as I entered. I am a prisoner too. What shall I do?"
The tears rushed into her sister's blue eyes.
"There is no use in screaming, for I cried that day and night until I
was hoarse as a raven, but no one ever seemed to hear me. And the
only window is nailed down, you see. But, oh, Ethel, they will miss
you at home and come here to look for you presently, won't they
dear?"
"I did not tell them I was coming here. I felt ashamed of going to
see a fortune-teller to find out about you. They would have laughed
at me. I let my maid think that I was going to see a friend. Oh, what
shall I do? Why did I ever come here?" wept Ethel, wringing her
hands in terror, and forgetting that she had told herself just now that
God himself had sent her to the aid of Precious.
She shrieked aloud; she tore at the door with frantic hands.
"It will soon be night, and they will wonder what has become of me.
This double sorrow will drive our poor mother mad. Oh, what shall I
do?" she cried again in agony.
"If we could only get that window open," cried Precious eagerly. "But
I have tried it every day, and my hands bled, but the nails would not
come out. But if we could only open it, Ethel, we could plait a rope
of the bedclothes, and get out."
Kay looked from one to the other, whining in unison with their grief.
Ethel turned a flashing glance on the window, then caught up a thick
wash pitcher of heavy iron-stone ware. She poured the water out,
and rushed at the window, dealing blow after blow on the panes.
Joy! the thin glass and slight framework gave way before her furious
onslaught. Then she attacked the shutters with the same signal
success. They tumbled from their fastenings down to the ground two
stories below. The sash was all gone, too, and the fresh outer air
rushed into their faces—fresh, but full of the fog and damp of early
twilight.
"Quick! now the bedclothes! We will sit at the window while we tear
them in strips, and if we see any one passing we will scream to
them for help," cried Ethel bravely, though her lovely hands were
torn and bleeding from fragments of flying glass. They set to work,
but Precious was so weak from her long fast that she could not help
much. The little hands were strengthless and nerveless.
"She must have heard you breaking in the window, and she will
come up here presently and kill us," she shuddered, with terrified
eyes.
"Don't be a coward, Precious. I think the old wretch has very likely
run off to tell her son what has happened, and we must get away
before they come back, for, of course, he will be very angry, and, as
you suggested, he may kill us," answered Ethel, working away in a
perfect frenzy of fear and excitement.
But Precious was very weak and nervous; she could not bear the
strain of this horrible dread, following on the hope of a few minutes
ago. She dropped back quietly in her chair and fainted.
Ethel would not relax her frantic labor to resuscitate her, but Kay fell
to licking the white face with such a rough, energetic tongue that
presently Precious sighed and revived, pushing him down with feeble
hands.
"Down, sir! down! You must not be so impudent," she sighed faintly.
"Come, Precious, our rope is done. Can you help me to fasten it to
the leg of the bed? Then we will throw it from the window. I will
slide down first, and you will follow. I will catch you at the bottom if
you fall. And Kay can jump out after us. Oh, Heaven, what is that?"
She might well exclaim, for at that moment the wall at the opposite
side of the room was suddenly divided by a burst of smoke and
flame that lighted up the gloom with a lurid glare.
They had thought it was the wind, the strange, crackling noises they
had faintly heard for some time, but now they understood the full
horror of their situation.
The old house was in flames—fired doubtless by the fiendish old hag
who had thus wreaked her vengeance and fled, leaving them to their
fate.
It was a moment of the most sublime horror, the most deadly peril.
The two girls gazed at each other with horror-stricken faces, and the
mastiff lifted up his voice in a prolonged and dismal howl like a
banshee.
"We are trapped," cried Ethel wildly. "She has fired the house and
gone. But we shall escape. Come, dear." She drew Precious to the
window, and climbed upon the sill. "I will go first; you follow."
She grasped the rope, and swung outward, her heart beating wildly,
her eyes watching the face of Precious as it leaned forward against
the awful background of smoke and flame. The small pale face, like
a snowdrop, the luminous blue eyes, the aureole of golden hair,
made Precious look angelic.
Ethel felt herself rushing through the cold March air, and—suddenly
she shot down wildly, and fell on the wet ground where the thick
spongy turf broke the severity of the fall. Safe!
But an awful cry escaped her lips.
The plaited rope had proved treacherous, and broken off midway,
dangling its useless length about a yard below the window sill,
above which that beautiful white face looked down in a frenzy of
despair.
Ethel staggered to her feet; she flung out her arms, she shrieked:
"Come, darling, climb out upon the rope, and drop. I will catch you—
I will break the fall."
But Precious scarcely heard. Her senses had deserted her at sight of
the broken rope. Ethel saw the dilated blue eyes close again, saw
her sister fall backward into the blinding smoke, heard the frenzied
yelp of Kay as he sprang upon the window sill, and felt that no
earthly power could save her doomed sister now.
She held out her arms to Kay, and shrieked wildly:
"Come to me, Kay, come!"
But the poor beast gave a desolate howl, and sprang back into the
room where Precious lay unconscious. Then a great black volume of
smoke poured through the window, and from the front of the house
Ethel saw the red glaring flame shoot quickly.
"The front of the house is all in flames. No one can save my sister
now," she thought. Then something seemed to say in her heart:
"You are to blame. You should have sent her down the rope first.
She was so light and small it would have carried her safely, and both
would have been saved."
It made her angry, that still small voice of conscience, for she knew
that it was a selfish anxiety over her own safety that made her
descend first. Moving away she muttered:
"Why should I run the risk of my life for her? I tried to save her, and
if she had not been so cowardly I would have succeeded. She will
perish, but it is not my fault."
Why did she not run and spread the alarm? Some man might be
found who would be brave enough to scale the window and bring
out the unconscious girl.
But Ethel moved away, going backward, watching with fascinated
eyes the burning building, her sister's funeral pyre.
Shrieks began to fill the air from the occupants of the shanties
around, just discovering the fire. A crowd began to gather. Why did
not the retreating girl pray the people to rescue her sister?
A tempting devil had recalled to her mind her sister's words of
admiration for Lord Chester a little while ago—her longing for just
such a splendid lover.
"Precious dead he would be yours; living she would win him from
you," whispered the tempter, and she turned away muttering, "It is
too late. No one could save her now."
CHAPTER IX.
A FAITHFUL FRIEND.

"I am mad!
The torture of unnumbered hours is o'er,
The strong cord is broken, and my heart
Riots in free delirium! Oh, Heaven!
I struggled with it, but it mastered me!
I fought against it, but it beat me down!
I prayed, I wept, but Heaven was deaf to me,
And every tear rolled backward on my heart,
To blast and poison!"—George Henry Boker.

A crowd soon collected and the fire engines quickly came upon the
scene.
Streams of water began to play on the burning house, but to no
avail. The fire had made too much headway to be checked now. The
old ramshackle building was doomed. In the large crowd that had
collected were two very elegant-looking young men—Earle Winans
and Lord Chester.
The two young men, although acquainted but a few days, had
become fast friends.
It was the nobleman's deep solicitude over the fate of Precious that
had first drawn Earle toward him. Lord Chester's services were
always ready in any new plan for finding Precious; he was as eager
as Earle himself in the search.
The Winans family believed that all this zeal was for the sake of
Ethel, whom the nobleman had seemed to admire so much that
gossip said he would certainly make her Lady Chester at no distant
date.
So Earle had taken the handsome young nobleman warmly into his
heart and confidence.
They had been walking together that chilly afternoon, several blocks
away from the place, when the light of the burning building drew
them to follow the crowd to the spot.
They arrived but a few moments after Ethel had turned away from
the dreadful scene, hardening her jealous heart against the voice of
accusing conscience, and answering to its reproaches: "I tried to
save her, and it was through her own cowardice she perished."
When her brother and Lord Chester came on the scene they heard
some one saying:
"There is a dog shut up in that house. Hear his frightful baying!"
They could hear it distinctly, the prolonged mournful howls, and it
seemed as if the sounds came from an open window.
"The window is open. Why don't the foolish animal come out?" cried
Earle Winans, and just then the streams of water playing on the side
of the wall cleared away the smoke a little, and the animal was seen
a moment dimly, then with another howl he fell back into the room.
"He is bewildered and afraid to jump," cried a fireman, as poor Kay's
dismal wails came distinctly to the ears of the crowd.
"Perhaps there is some person in the room, and he is too faithful to
desert his post. Dogs are often more faithful than friends. Put up a
ladder, and I will go and see," exclaimed Lord Chester suddenly.
"No, no! you must not risk your life for a dog, even a faithful one,"
cried Earle, trying to hold his friend back, for the situation was very
perilous.
"No, no! I must save that poor dog!" Lord Chester cried, breaking
loose and ascending the ladder, while the shouts of the tumultuous
crowd rang to heaven.
Slowly, carefully, through the blinding smoke and heat and
threatening flame he went, and presently his head rose above the
sill of the open window and he peered into the room, which seemed
full of black smoke and leaping flames.
He put out his hand and it touched a big tawny head.
"Come, good fellow, come," he cried, and tried to drag him out.
Then he made a startling discovery.
The faithful mastiff had dragged an unconscious human being to the
window with his teeth, and was holding her up by a mass of golden
hair in a vain effort to get her up to the sill, where she might be
seen and rescued by the crowd.
CHAPTER X.
"HIS HEART WILL TURN BACK TO ME."

"Eyes that loved me once, I pray


Be not crueler than death;
Hide each sharp-edged glance away
Underneath its cruel sheath!
Make me not, sweet eyes, with scorn,
Mourn that I was ever born!"—Alice Cary.

Through the falling twilight of the bleak March day Ethel Winans
sped away like a guilty creature, nor paused until she reached her
home.
Entering by a private door she gained her own room unobserved and
hastened to bathe her face and hands and rearrange her disordered
tresses.
Then she summoned Hetty, and the maid stared in surprise at her
corpse-like pallor and heavy eyes.
"Oh, Miss Ethel, you look awful! Are you sick?"
"I am tired to death," sighed Ethel. "I have had such a long, weary
chase after Kay! Oh, Hetty, I have lost him, but you must never,
never tell, for papa would never forgive me if he knew. He ran off
with some other dogs in a park, and though I ran and ran I could
not get him back."
"You ought not to worry so about the dog, Miss Ethel. Lordy, he'll be
sure to find his way back home," declared the maid cheerfully.
Ethel looked on the verge of tears. She half sobbed:
"Do you think so? I hope he will, for Precious loved him so dearly,
and papa will be so sorry to find him gone, and he will be so angry
with me for taking him out. Please don't say anything about it to any
one, Hetty, and you may have that coral bracelet of mine."
"Thank you kindly, Miss Ethel, and of course it's not my business to
find out that Kay is missing. So now it's time to dress for dinner, if
you please. What dress will you wear, Miss Ethel? That new gold-
colored silk with the black lace draperies, or something plainer?
There's no one to dinner but the two gentlemen of the family. Your
mamma is not well enough to dine."
"Poor mamma! But, Hetty, I am too tired to dress and dine to-night.
I think I will send down excuses and retire. My head is throbbing
with pain. I believe I should like a sedative."
Hetty brought the sedative and helped her to bed, saying as she
tucked in the silken coverlet:
"Miss Miller called for you this afternoon, and I told her you had
gone to keep an engagement with her. She said there must be some
mistake; she hadn't seen you. I thought to myself that maybe you
changed your mind and went to the old clairvoyant after all."
"I didn't have time to go anywhere after I lost Kay and had that long
chase after him, so I hurried home," Ethel answered evasively. Then
she nestled her head in the pillow and closed her eyes.
"Now, Hetty, I don't need you any longer. You can go and tell
mamma I was so weary from my long walk that I retired."
Hetty dimmed the light and went out, but she thought sagely:
"Miss Ethel fibbed when she said she hadn't been anywhere. I'll bet
a dime she's been to the old fortune-teller, and she told her
something she didn't like and she's gone to bed to cry over it."
Ah, Hetty, your young mistress had more to grieve over than you
guessed, and the pillow of down might have been full of thorns for
all the rest she found that night.
For, shut her eyes as she might, there was one vision always before
them—a wan little face like a snowdrop, luminous blue eyes, golden
hair like an aureole of light; then it would fade and fall away into a
cloud of smoke and flame, only to reappear again, until Ethel
writhed in anguish and sobbed:
"It was not my fault. I could have saved her if she had not fainted.
But no one must ever know I was there. They would blame me for
her awful death."
She sat up in bed staring with gloomy eyes and writhing hands,
trying to put from her the horror of her sister's death and to think
what life would be like now when there was no pretty, willful
Precious any more to envy for her fatal power of winning hearts.
"They must learn to love me now, papa, mamma, Earle and—Lord
Chester, for his heart will turn back to me when there is no witching
Precious to distract his thoughts. They loved her too well and fate
has punished them by taking their idol away. It is my turn now," she
thought with a bitter triumph.
Ah, Ethel, could the straining gaze of those somber eyes have
pierced the shadows of the gloomy twilight they would have beheld
a sight to blast them with its surprise.
Down the ladder came Lord Chester bearing the unconscious form of
golden-haired Precious, whom Ethel had forsaken, and who never
would have been saved but for the devotion of the faithful mastiff,
noble Kay.
The shouts that rose from the crowd, as Lord Chester came down
with the girl in his arms and the brave mastiff leaped from the
window might almost have reached Ethel's ears, they were so loud
and ringing.
Lord Chester was so blind and dizzy from the heat and smoke that
as soon as his burden was drawn from his arms he sank exhausted
to the ground.
The next instant the roof of the building fell in, leaving only the
outer walls standing. Lord Chester had saved a life that but for his
bravery must have perished in the raging flames.
Earle Winans pressed forward to his friend's assistance with a pang
of keen remorse as he remembered how he had tried to restrain his
friend from that perilous undertaking.
"How little I dreamed that a human being was in deadly peril within
the house," he thought as he gazed curiously at the girl his friend
had rescued from such an awful fate.
His dark eyes noted the golden hair all tossed and tangled in a curly
mass, the closed eyes, the waxen fair face in its pallid beauty. Then
a loud cry burst from his lips:
"Oh, Heaven! it is my missing sister—little Precious!"
And he reeled and would have fallen but for the restraining arm of a
stranger.
Water was poured on his face and he quickly revived from his
momentary faintness.
He knelt by the silent form of the unconscious girl, crying in anguish:
"It is Precious! my little sister! Oh, do not tell me she is dead."
A physician pushed through the crowd and made a hasty
examination. His face was very grave.
"She is not dead, but her unconsciousness is very deep," he said. "If
it is a simple swoon she may revive, but if asphyxiated by the smoke
and heat, as I greatly fear, she will very likely soon expire."
Lord Chester, recovering from his momentary exhaustion, heard their
words and looked with a bitter heart-pang at the face of Precious.
Never before had he gazed at that face, yet there came a swift
despair at thought of her death—a swift despair that blotted out all
memory of Ethel's sparkling beauty that such a little while ago had
charmed him so.
"We must have a carriage and take her home," cried Earle huskily,
then wrung his friend's hand and thanked him for the rescue of his
sister.
"From this hour you are dear to me as a brother," he cried with deep
emotion.
So it happened that while Ethel sat up in bed staring with wild eyes
into a possible future that held no lovely sister for a rival, a carriage
was pausing at the door that held Earle Winans, his unconscious
sister, and a physician, and presently there came ringing to Ethel's
ear the long cry of anguish wrung from a mother's heart while
bending over her dead.
Ethel started and listened in terror. What did it mean, that long, low
cry of grief in her mother's voice?
Then Hetty Wilkins rushed in, pale and tearful, crying out:
"Oh, Miss Ethel, such dreadful news! They have bought Miss
Precious home dead."
But from behind her came Earle Winans, and he exclaimed angrily:
"Hetty, you are a cruel girl to frighten Ethel so. You had no business
to come to her with such news. My mother sent me to break it to
her gently. Ethel, dear, do not sob so bitterly. We have brought
Precious home, but a little life lingers still and we hope she may not
die."
Ethel had dropped her face in her hands. When her brother lifted it
he was startled at its expression, the ghastly face, the eyes wide and
dark with horror.
He scolded Hetty roundly for her rashness in blurting out the news
to his sister, and the girl stood aside sulkily at his reproof.
"Never mind Hetty; she meant no harm, Earle; but tell me all about
it. Where did you find Precious?" gasped Ethel, clinging to him in
wild excitement.
And holding her head against his arm and smoothing the dark waves
of her hair with a loving hand Earle told the story as far as he knew
it—the story of his young sister's rescue by Arthur, Lord Chester.
Kay, the splendid mastiff, came in for a share of praise too, and
Hetty, the maid, listened intently to it all and nodded excitedly when
Earle said:
"The greatest wonder of all is how Kay came to be there; but of
course if Precious revives she can explain all that."
He felt Ethel shuddering against his arm, and Hetty saw how she
trembled, and said to herself:
"I think Miss Ethel could explain it too, if she would, and if she don't
speak I shall begin to think she has some strange secret worth more
than the gift of a bracelet."
"I must go back to my mother now, for our father is too wretched
himself to comfort her. Ethel, try to come down if you can," he said,
as he left the room.
Ethel dragged herself out of bed, moaning:
"You must dress me, Hetty, and let me go to my poor sister."
Hetty brought her slippers and a pretty wrapper, and while she was
putting them on she exclaimed:
"What a brave young man Lord Chester must be!"
Ethel's heart gave a fierce throb of mingled pride and pain.
"And," pursued the loquacious maid, "he is the rich lord that they all
say you are going to marry, isn't he, Miss Ethel?"
"Yes," answered Ethel carelessly, then added:
"But I don't think I shall accept him."
She turned away from the maid as she spoke and went from her
own apartments toward those of Precious, nearer to her mother.
She opened the door very softly and glided in.
They were all there, her father, mother, brother, and the physician.
Precious lay on her bed, white as a lily, but breathing faintly. She
had revived from her swoon, but she had not yet spoken. Her half-
open blue eyes seemed to know that they were all there, but she
was too exhausted to utter a word.
Ethel bent down and pressed her lips on the wasted little hand, and
when she met the gaze of the half-conscious blue eyes she
whispered, too low for any one to hear:
"Please don't tell any one I was there with you, Precious, until you
get well enough for me to explain."
The little hand she was holding gave hers a weak pressure that
showed her that Precious understood and would not speak.
The others, looking on at the little by-play, thought that Ethel was
only whispering to Precious of her joy at her return.
A week passed and the sick girl slowly gained strength enough to
tell the story of her persecutions at the hands of Lindsey Warwick
and his mother, but the pair of plotters had made good their escape
and were now beyond the senator's vengeance.
There was one thing that always seemed strange to them, and that
was how Kay had found the way to his mistress. The girl always
explained it in an embarrassed, halting fashion.
"The old woman just unlocked the door, pushed Kay in, and went
away again," she said. "And just a little later the flames burst
through the side of the wall. I—I—looked out of the window and saw
that I could not escape, then I fainted."
"Lindsey Warwick probably stole Kay and took him there, thinking to
please you," said the senator, and his black eyes flashed as he
thought of the vengeance he would take on the kidnaper if he ever
found him.
They did not dream of the dark secret that lay behind the reluctance
of Precious to talk of the mastiff's presence in her prison. They could
not guess of the twilight hour when Ethel, sitting alone by her sister
for a little while, had knelt down by Precious and begged her not to
tell of her presence the day of the fire.
"When I saw you fall back in the smoke, Precious, I thought you
were dead, and I ran away in a frenzy of despair and came home,
afraid to tell mamma because I believed the awful news would kill
her. I thought a merciful silence would be best, so I kept the awful
secret. And if you told them now, dear, perhaps they would blame
me. They would say I ought to have sent you down the rope first,
but you know how that was, dear. I wanted to be at the bottom to
catch you if you should fall."
"Yes, I know, dear sister, and I don't think they would blame you if
we told them," sighed Precious; but because Ethel insisted on it she
gave the promise of silence.
CHAPTER XI.
TO FORGET THE LURING BLUE EYES.

"Droop and darken, eyes of blue,


Love hath only tears for you;
Love, begone, and lightly flee,
Since thy smiles are not for me!
Lips of scarlet, quench your fire,
Torches vain of love's desire;
Love, begone, and lightly flee,
Since thy sweets are not for me!"

But Precious improved too slowly to please the careful doctor.


The long fast and the subsequent shock had told severely on her
young frame, and it was almost the last of March when she was able
to come out of her room. Then she looked too thin, too frail, too lily-
like, to please those who loved her best.
"Mrs. Winans, you must take her away from Washington to the
country; she needs mountain air," said Doctor Heron.
"Oh, doctor, what an idea! Leave Washington before the season is
over! How can you tell mamma that?" pouted Ethel.
The selfish, dark-eyed beauty had resumed all the gayeties of the
brilliant Washington season as soon as her sister was declared out of
danger, and dragged her gentle, yielding mother day after day from
receptions to balls, from dinners to operas. Ethel was a belle, and
would not yield her scepter; so Norah nursed the sick girl; and the
mother who, because she loved Precious best, indulged Ethel most,
followed with a sad heart into scenes of revelry, leaving her
tenderest thoughts at home.
So Ethel was almost indignant when the physician ordered Mrs.
Winans to the mountains with her ailing daughter.
At the proud beauty's protest Doctor Heron smiled and answered
carelessly:
"You can remain in Washington, Miss Winans."
"But mamma—my chaperon! Of course I couldn't go into society
without her. Really, I think that Precious can get on here till May,
when we will go away for the summer."
The physician looked disgusted at her selfishness, and turned again
to her mother.
"I repeat that Miss Precious should be taken to the mountains before
the first of April, or her recovery will be very tedious. It is a case of
nervous prostration," he said.
"You can send Norah with her, mamma; that will do very well, don't
you think so?" Ethel cried airily; but there was a look of pain on the
gentle face of Mrs. Winans, and she did not reply.
Earle, who was present at the conclave, broke in:
"How fortunate that your distant relative in Virginia left you her
lovely mountain estate when she died last fall, mother. It is the very
place to take Precious, doctor, and not more than a hundred miles
from here. The kind spinster who left it to us had it elegantly
appointed, and nothing has been changed. I think even the old
family servants are yet in charge."
"Yes," assented his mother. "You see, I intended going there for a
part of this summer. It is a charming mountain country, doctor. The
estate is called Rosemont, and there is a pretty country town of the
same name near by. The air is fine and pure."
"The very place for your drooping daughter," cried Doctor Heron.
"Send her as soon as you can, Mrs. Winans, and if you can't be
spared from Washington just now, let the good nurse Norah take
your place. She will do excellently well."
"And I will go, too, to take care of the little one. I'm tired of the
social whirl," cried Earle Winans, and was rewarded by a beaming
smile of gratitude from his adoring mother. He did not care for
Ethel's sullen brow, and inwardly characterized her as selfish and
unloving.
"To keep mother dancing attendance on her here when she looks so
pale and worn and needs a change almost as much as Precious
does!" the noble young man thought indignantly.
So the plan was carried out. The delicate, drooping girl was sent to
Rosemont with her brother and the good nurse Norah, and Ethel
drew a long breath of relief when they were gone.
"Two months of relief from their silly worship at least, for I shall not
go to Rosemont any sooner if I can possibly avoid it," she cried
angrily.
One thing that pleased her well was that Lord Chester and Precious
had not yet met, for the young lord had gone away from the city as
soon as it was announced that Precious would recover. Washington
had lionized him after his heroic act, and in sheer bashfulness he
had run away to travel round a few weeks until his fame blew over,
he laughingly explained to his friend Earle.
Perhaps there was more in it than he had confessed.
Lord Chester regretted with a bitter pain that he had given Ethel
Winans cause to expect an offer of his hand and heart.
From the day that he had first seen the portrait of Precious his heart
had turned away from proud, queenly Ethel to her gentle younger
sister. The strange chance by which he had saved her sweet young
life only drew her closer to his heart.
Yet in all honor his fealty belonged to dark-eyed Ethel.
In desperation he went away to try to forget the blue eyes that were
luring him from his honor.
And he remained away until he received a letter from Earle Winans,
telling him of all that had happened since he left Washington.

"We are here at Rosemont—Precious and I; the mater and Ethel


are still in the Capitol City. Precious is improving slowly but
surely in the fine mountain air, and I—well, I fear I'm losing my
heart to a village coquette, the daintiest fairy I ever saw.
Rosemont is a very gay little town, with some nice people—old
Virginia stock, you know."

Then Lord Chester resolved to go back to Washington and see Ethel


again. Perhaps now that Precious was gone his heart might return to
its first love.
CHAPTER XII.
"A VILLAGE COQUETTE."

"Laughing eyes, curly hair, dainty robes,


They had crazed his hot, fiery brain, then.
Ah, the silliest maiden can make
A fool of the wisest of men!"

—May Agnes Fleming.

"I am seventeen to-day, and I have thirteen lovers!" cried pretty,


saucy Ladybird, pirouetting on the velvet greensward in front of her
father's house at Rosemont until her short golden-brown locks
danced in fluffy rings all over her round, white, babyish forehead.
"Thirteen is always an unlucky number. Thee ought to jilt thy last
lover," cried Auntie Prue from the porch.
"Ay, but I won't, for I like the thirteenth best of all," laughed the
little beauty.
"You'll rue the day if you marry him," cried Aura Stanley sharply.
She leaned against a rose-wreathed pillar of the porch, a tall girl in
pink, with hard black eyes and thick brown hair in a rich braid. She
lived next door and was the village lawyer's only daughter.
Before the Conways came here to live, five weeks ago, Aura had
been called the prettiest girl in the village, but now the town was
divided into two factions over the rival beauties, and among those
who had gone over to the enemy was one on whom Aura's
passionate heart was set.
"You'll rue the day, Ladybird, if you marry him," repeated Aura
angrily, and held up her shapely white hand, on which glittered a
splendid diamond ring; but, to her surprise and horror, the little
dancing madcap laughed and answered teasingly:
"Nonsense! I'll be wearing that ring in a week, Aura."
"Never! I'll throw it in the river first," flashed Aura, and Aunt Prue
caught the glance of jealous hate in the girl's black eyes.
She exclaimed soothingly:
"Aura, the child is only teasing thee. She does not want thy lover,
dear."
Ladybird Conway turned her laughing hazel eyes on the old lady and
protested gayly:
"But, Auntie Prue, he's my lover now. Doesn't he call on me three
times a week, and send me flowers and books and candy? And
hasn't he promised to escort me to the picnic to-morrow?"
"He asked me first, but I refused," cried Aura triumphantly, and
added spitefully: "I wouldn't take what another girl refused."
"Neither would I!" flashed Ladybird, with such sarcastic emphasis
that Aura flushed burning red at the intimation that she had told a
falsehood.
"Girls, girls, don't thee quarrel over nothing!" cried the old
Quakeress anxiously, but Aura was furious.
"Ladybird Conway, I'll never speak to you again," she cried, and flew
down the graveled path, shutting the front gate with a vicious slam.
Aunt Prue cried out reprovingly:
"Thee has lost thy young friend forever, Ladybird, and thee ought to
be ashamed of thyself, taking another girl's lover so audaciously."
"But he isn't hers—so there! I know, because I asked him. I said she
claimed him, and if that was so not to come to see me any more.
But he denied it. He said he had only known her two weeks when
we moved here, and had no idea of being engaged to her. He lent
her the ring because she asked him to, and she's only trying to claim
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

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