Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (1 vote)
13 views

Beginning Ethereum Smart Contracts Programming: With Examples in Python, Solidity, and JavaScript, 2nd Edition Wei-Meng Lee pdf download

The document is a promotional listing for the book 'Beginning Ethereum Smart Contracts Programming' by Wei-Meng Lee, which covers programming with examples in Python, Solidity, and JavaScript. It includes links to download the book and other related titles on blockchain and smart contract development. The content also outlines the book's structure, including chapters on blockchain fundamentals, implementing a blockchain, and creating smart contracts.

Uploaded by

testuzweu30
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
13 views

Beginning Ethereum Smart Contracts Programming: With Examples in Python, Solidity, and JavaScript, 2nd Edition Wei-Meng Lee pdf download

The document is a promotional listing for the book 'Beginning Ethereum Smart Contracts Programming' by Wei-Meng Lee, which covers programming with examples in Python, Solidity, and JavaScript. It includes links to download the book and other related titles on blockchain and smart contract development. The content also outlines the book's structure, including chapters on blockchain fundamentals, implementing a blockchain, and creating smart contracts.

Uploaded by

testuzweu30
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

Beginning Ethereum Smart Contracts Programming:

With Examples in Python, Solidity, and


JavaScript, 2nd Edition Wei-Meng Lee download

https://ebookmeta.com/product/beginning-ethereum-smart-contracts-
programming-with-examples-in-python-solidity-and-javascript-2nd-
edition-wei-meng-lee/

Download more ebook from https://ebookmeta.com


We believe these products will be a great fit for you. Click
the link to download now, or visit ebookmeta.com
to discover even more!

Beginning Swift Programming 1st Edition Wei Meng Lee

https://ebookmeta.com/product/beginning-swift-programming-1st-
edition-wei-meng-lee/

Building Games with Ethereum Smart Contracts:


Intermediate Projects for Solidity Developers Kedar
Iyer

https://ebookmeta.com/product/building-games-with-ethereum-smart-
contracts-intermediate-projects-for-solidity-developers-kedar-
iyer/

Blockchain and Ethereum Smart Contract Solution


Development: Dapp Programming with Solidity 1st Edition
Weijia Zhang

https://ebookmeta.com/product/blockchain-and-ethereum-smart-
contract-solution-development-dapp-programming-with-solidity-1st-
edition-weijia-zhang/

Fresh Produce Shipping: Damages and Compensation 1st


Edition Rex C. Tester

https://ebookmeta.com/product/fresh-produce-shipping-damages-and-
compensation-1st-edition-rex-c-tester/
Emergency War Surgery Fifth Edition Borden Institute

https://ebookmeta.com/product/emergency-war-surgery-fifth-
edition-borden-institute/

Private Associations in the Pontic Greek Cities 6th


Century BC 3rd Century AD Volume 35 Colloquia Antiqua
1st Edition A.-I. Pazsint

https://ebookmeta.com/product/private-associations-in-the-pontic-
greek-cities-6th-century-bc-3rd-century-ad-volume-35-colloquia-
antiqua-1st-edition-a-i-pazsint/

Wilkins Clinical Practice of the Dental Hygienist 14th


Edition Linda D Boyd Lisa F Mallonee

https://ebookmeta.com/product/wilkins-clinical-practice-of-the-
dental-hygienist-14th-edition-linda-d-boyd-lisa-f-mallonee/

Flexible Electronics Volume 2 Thin film transistors 1st


Edition Vinod Kumar Khanna

https://ebookmeta.com/product/flexible-electronics-volume-2-thin-
film-transistors-1st-edition-vinod-kumar-khanna/

Hot Dog Summer Hot H E A Summer 1st Edition Lola West

https://ebookmeta.com/product/hot-dog-summer-hot-h-e-a-
summer-1st-edition-lola-west/
Machine Hallucinations Architecture and Artificial
Intelligence Architectural Design 1st Edition Neil
Leach (Editor)

https://ebookmeta.com/product/machine-hallucinations-
architecture-and-artificial-intelligence-architectural-
design-1st-edition-neil-leach-editor/
Beginning Ethereum
Smart Contracts
Programming
With Examples in Python, Solidity,
and JavaScript
Second Edition

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-9270-9 ISBN-13 (electronic): 978-1-4842-9271-6


https://doi.org/10.1007/978-1-4842-9271-6
Copyright © 2023 by Wei-Meng Lee
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the
material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information
storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now
known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the
trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not
identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the
material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Joan Murray
Development Editor: Laura Berendson
Editorial Assistant: Gryffin Winkler
Copy Editor: Mary Behr
Cover image designed by eStudioCalamar
Distributed to the book trade worldwide by Springer Science+Business Media New York, 1 New York Plaza,
Suite 4600, New York, NY 10004-1562, USA. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@
springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole
member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc
is a Delaware corporation.
For information on translations, please e-mail booktranslations@springernature.com; for reprint,
paperback, or audio rights, please e-mail bookpermissions@springernature.com.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and
licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales
web page at www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to
readers on GitHub (github.com/apress). For more detailed information, please visit www.apress.com/
source-code.
Printed on acid-free paper
Table of Contents
About the Author����������������������������������������������������������������������������������������������������� xi

About the Technical Reviewer������������������������������������������������������������������������������� xiii


Acknowledgments���������������������������������������������������������������������������������������������������xv

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

Chapter 1: Understanding the Science Behind Blockchain: Cryptography��������������� 1


What Is Cryptography?������������������������������������������������������������������������������������������������������������������ 1
Types of Cryptography������������������������������������������������������������������������������������������������������������� 2
Hash Functions����������������������������������������������������������������������������������������������������������������������������� 3
Uses of Hashing����������������������������������������������������������������������������������������������������������������������� 5
Implementing Hashing in Python��������������������������������������������������������������������������������������������� 6
Symmetric Cryptography�������������������������������������������������������������������������������������������������������������� 7
Generating the Shared Key in Python�������������������������������������������������������������������������������������� 8
Performing Symmetric Encryption������������������������������������������������������������������������������������������ 9
Performing Symmetric Decryption������������������������������������������������������������������������������������������ 9
Asymmetric Cryptography���������������������������������������������������������������������������������������������������������� 10
Generating and Saving the Public/Private Key Pairs������������������������������������������������������������� 12
Encrypting Using the Public Key�������������������������������������������������������������������������������������������� 14
Decrypting Using the Private Key������������������������������������������������������������������������������������������ 14
Digital Signature: Signing Using Private Key������������������������������������������������������������������������� 15
Verifying the Digital Signature Using a Public Key���������������������������������������������������������������� 18
How Cryptography Is Used in Blockchain����������������������������������������������������������������������������������� 18
Hashing��������������������������������������������������������������������������������������������������������������������������������� 19
Symmetric and Asymmetric Cryptography���������������������������������������������������������������������������� 19
Digital Signature�������������������������������������������������������������������������������������������������������������������� 20
Summary������������������������������������������������������������������������������������������������������������������������������������ 21

iii
Table of Contents

Chapter 2: Understanding Blockchain�������������������������������������������������������������������� 23


Motivations Behind Blockchain��������������������������������������������������������������������������������������������������� 24
Placement of Trust����������������������������������������������������������������������������������������������������������������� 24
Trust Issues��������������������������������������������������������������������������������������������������������������������������� 25
Solving Trust Issues Using Decentralization�������������������������������������������������������������������������� 26
Example of Decentralization�������������������������������������������������������������������������������������������������� 26
Blockchain As a Distributed Ledger��������������������������������������������������������������������������������������� 29
How a Blockchain Works������������������������������������������������������������������������������������������������������������� 30
Chaining the Blocks��������������������������������������������������������������������������������������������������������������� 31
Immutability of Blockchains�������������������������������������������������������������������������������������������������� 34
Consensus Protocols������������������������������������������������������������������������������������������������������������� 35
Proof of Work������������������������������������������������������������������������������������������������������������������������� 37
Proof of Stake (PoS)�������������������������������������������������������������������������������������������������������������� 41
Blockchain in More Detail����������������������������������������������������������������������������������������������������������� 43
Types of Nodes���������������������������������������������������������������������������������������������������������������������� 44
Merkle Tree and Merkle Root������������������������������������������������������������������������������������������������� 47
Uses of Merkle Tree and the Merkle Root������������������������������������������������������������������������������ 48
Summary������������������������������������������������������������������������������������������������������������������������������������ 49

Chapter 3: Implementing Your Own Blockchain Using Python������������������������������� 51


Your Conceptual Blockchain Implementation����������������������������������������������������������������������������� 51
Obtaining the Nonce�������������������������������������������������������������������������������������������������������������� 53
Installing Flask���������������������������������������������������������������������������������������������������������������������� 55
Importing the Various Modules and Libraries������������������������������������������������������������������������ 56
Declaring the Class in Python������������������������������������������������������������������������������������������������ 56
Finding the Nonce����������������������������������������������������������������������������������������������������������������� 57
Appending the Block to the Blockchain��������������������������������������������������������������������������������� 58
Adding Transactions�������������������������������������������������������������������������������������������������������������� 59
Exposing the Blockchain Class as a REST API����������������������������������������������������������������������� 60
Obtaining the Full Blockchain������������������������������������������������������������������������������������������������ 60
Performing Mining����������������������������������������������������������������������������������������������������������������� 60
Adding Transactions�������������������������������������������������������������������������������������������������������������� 61

iv
Table of Contents

Testing Your Blockchain�������������������������������������������������������������������������������������������������������������� 62


Synchronizing Blockchains��������������������������������������������������������������������������������������������������������� 67
Testing the Blockchain with Multiple Nodes�������������������������������������������������������������������������� 72
Full Listing for the Python Blockchain Implementation��������������������������������������������������������������� 78
Summary������������������������������������������������������������������������������������������������������������������������������������ 85

Chapter 4: Creating Your Own Private Ethereum Test Network������������������������������ 87


Downloading and Installing Geth, the Ethereum Client��������������������������������������������������������������� 87
Installing Geth for macOS������������������������������������������������������������������������������������������������������ 88
Installing Geth for Windows��������������������������������������������������������������������������������������������������� 89
Installing Geth for Linux��������������������������������������������������������������������������������������������������������� 89
Creating the Private Ethereum Test Network������������������������������������������������������������������������������ 90
Creating the Genesis Block��������������������������������������������������������������������������������������������������� 91
Creating a Folder for Storing Node Data�������������������������������������������������������������������������������� 92
Initiating a Blockchain Node�������������������������������������������������������������������������������������������������� 93
Starting Up the Nodes����������������������������������������������������������������������������������������������������������� 94
Managing Accounts������������������������������������������������������������������������������������������������������������������� 107
Removing Accounts������������������������������������������������������������������������������������������������������������� 109
Setting the Coinbase����������������������������������������������������������������������������������������������������������� 109
Summary���������������������������������������������������������������������������������������������������������������������������������� 110

Chapter 5: Using the MetaMask Crypto-Wallet����������������������������������������������������� 111


What Is MetaMask?������������������������������������������������������������������������������������������������������������������ 111
How MetaMask Works Behind the Scenes�������������������������������������������������������������������������� 112
Installing MetaMask������������������������������������������������������������������������������������������������������������ 113
Setting Up the Accounts������������������������������������������������������������������������������������������������������ 115
Using the MetaMask Extension������������������������������������������������������������������������������������������� 119
Selecting Ethereum Networks�������������������������������������������������������������������������������������������������� 121
Getting Test Ethers�������������������������������������������������������������������������������������������������������������� 122
Creating Additional Accounts����������������������������������������������������������������������������������������������� 126
Transferring Ethers�������������������������������������������������������������������������������������������������������������� 129
Recovering Accounts����������������������������������������������������������������������������������������������������������� 135

v
Table of Contents

Importing and Exporting Accounts�������������������������������������������������������������������������������������������� 138


Exporting Accounts�������������������������������������������������������������������������������������������������������������� 138
Importing Accounts������������������������������������������������������������������������������������������������������������� 142
Summary���������������������������������������������������������������������������������������������������������������������������������� 144

Chapter 6: Getting Started with Smart Contracts������������������������������������������������� 145


What Is a Smart Contract?�������������������������������������������������������������������������������������������������������� 145
How Smart Contracts Are Executed������������������������������������������������������������������������������������� 146
Your First Smart Contract���������������������������������������������������������������������������������������������������������� 148
Using the Remix IDE������������������������������������������������������������������������������������������������������������ 148
Compiling the Contract�������������������������������������������������������������������������������������������������������� 152
Testing the Smart Contract Using the JavaScript VM���������������������������������������������������������� 154
Getting the ABI and Bytecode of the Contract��������������������������������������������������������������������� 158
Testing the Smart Contract Using the Goerli Testnet����������������������������������������������������������� 162
Summary���������������������������������������������������������������������������������������������������������������������������������� 166

Chapter 7: Storing Proofs Using Smart Contracts������������������������������������������������ 167


A Smart Contract as a Store of Proofs�������������������������������������������������������������������������������������� 167
Creating the Smart Contract������������������������������������������������������������������������������������������������ 168
Compiling the Contract�������������������������������������������������������������������������������������������������������� 174
Deploying the Contract�������������������������������������������������������������������������������������������������������� 176
Testing the Contract������������������������������������������������������������������������������������������������������������ 177
Making Further Changes to the Smart Contract����������������������������������������������������������������������� 180
Restricting Access to Functions������������������������������������������������������������������������������������������ 181
Accepting Payments in Smart Contracts����������������������������������������������������������������������������� 182
Events in Smart Contracts��������������������������������������������������������������������������������������������������� 188
Cashing Out������������������������������������������������������������������������������������������������������������������������� 191
Destroying a Contract���������������������������������������������������������������������������������������������������������� 193
Summary���������������������������������������������������������������������������������������������������������������������������������� 194

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


What Is web3.js?����������������������������������������������������������������������������������������������������������������������� 195
Installing web3.js���������������������������������������������������������������������������������������������������������������� 196

vi
Table of Contents

Testing the web3.js Using MetaMask���������������������������������������������������������������������������������� 197


Interacting with a Contract Using web3.js�������������������������������������������������������������������������� 202
Summary���������������������������������������������������������������������������������������������������������������������������������� 214

Chapter 9: Developing Web3 dapps using Python������������������������������������������������ 215


Interacting with Ethereum Using Python���������������������������������������������������������������������������������� 216
Registering with Infura�������������������������������������������������������������������������������������������������������� 217
Connecting to Infura������������������������������������������������������������������������������������������������������������ 220
Fetching a Block������������������������������������������������������������������������������������������������������������������ 221
Setting Up the Accounts������������������������������������������������������������������������������������������������������ 223
Getting the Balance of an Account�������������������������������������������������������������������������������������� 225
Transferring Ethers Between Accounts������������������������������������������������������������������������������� 225
Creating a Dapp Using Python�������������������������������������������������������������������������������������������������� 227
Loading the Contract����������������������������������������������������������������������������������������������������������� 230
Base64 Encoding����������������������������������������������������������������������������������������������������������������� 231
Saving Credentials on the Blockchain��������������������������������������������������������������������������������� 231
Verifying the Result������������������������������������������������������������������������������������������������������������� 234
Summary���������������������������������������������������������������������������������������������������������������������������������� 239

Chapter 10: Project: Online Lottery���������������������������������������������������������������������� 241


How the Lottery Game Works���������������������������������������������������������������������������������������������������� 241
Defining the Smart Contract������������������������������������������������������������������������������������������������ 243
Betting a Number���������������������������������������������������������������������������������������������������������������� 246
Setting the Winning Number and Announcing the Winners������������������������������������������������� 249
Getting the Game Status and Winning Number������������������������������������������������������������������� 253
Cashing Out from the Contract�������������������������������������������������������������������������������������������� 253
Testing the Contract������������������������������������������������������������������������������������������������������������������ 254
Announcing the Winner������������������������������������������������������������������������������������������������������� 258
Saving the ABI of the Contract��������������������������������������������������������������������������������������������� 260
Deploying the Contract to the Testnet��������������������������������������������������������������������������������� 262
Creating the Web Front End������������������������������������������������������������������������������������������������������ 263
Announcing the Winning Number���������������������������������������������������������������������������������������� 269
Cashing Out������������������������������������������������������������������������������������������������������������������������� 271
vii
Table of Contents

The Complete Contract������������������������������������������������������������������������������������������������������������� 272


Summary���������������������������������������������������������������������������������������������������������������������������������� 277

Chapter 11: Creating Your Tokens������������������������������������������������������������������������ 279


What Are Tokens?���������������������������������������������������������������������������������������������������������������������� 279
How Tokens Are Implemented?������������������������������������������������������������������������������������������� 281
Minting New Tokens������������������������������������������������������������������������������������������������������������ 282
Burning Tokens�������������������������������������������������������������������������������������������������������������������� 282
Units Used Internally in Token Contracts����������������������������������������������������������������������������� 283
ERC-20 Token Standard������������������������������������������������������������������������������������������������������� 285
Creating Token Contracts���������������������������������������������������������������������������������������������������������� 287
Overriding the Number of Decimal Places of Precision������������������������������������������������������� 288
Deploying the Token Contract���������������������������������������������������������������������������������������������� 289
Adding the Token to MetaMask������������������������������������������������������������������������������������������� 291
What Can You Do with the Token?��������������������������������������������������������������������������������������� 291
Using Tokens for Smart Contract Payments������������������������������������������������������������������������ 292
Selling Tokens Programmatically���������������������������������������������������������������������������������������������� 300
Calculating the Amount of Tokens Bought��������������������������������������������������������������������������� 302
Deploying the Contract�������������������������������������������������������������������������������������������������������� 304
Summary���������������������������������������������������������������������������������������������������������������������������������� 310

Chapter 12: Creating Non-Fungible Tokens Using ERC-721���������������������������������� 311


What Is an NFT?������������������������������������������������������������������������������������������������������������������������ 311
Ownership vs. Copyright����������������������������������������������������������������������������������������������������� 313
Where Do You Buy or Sell NFTs?����������������������������������������������������������������������������������������� 313
Creating NFTs Using Token Contracts��������������������������������������������������������������������������������������� 314
Who Deploys the NFT Token Contract?�������������������������������������������������������������������������������� 315
Using ERC-721 for Creating NFTs���������������������������������������������������������������������������������������� 315
Deploying the NFT Token Contract��������������������������������������������������������������������������������������� 316
Testing the NFT Contract����������������������������������������������������������������������������������������������������� 318
Summary���������������������������������������������������������������������������������������������������������������������������������� 327

viii
Table of Contents

Chapter 13: Introduction to Decentralized Finance���������������������������������������������� 329


Limitations of Traditional Finance��������������������������������������������������������������������������������������������� 329
Decentralized Finance��������������������������������������������������������������������������������������������������������� 330
Components in DeFi������������������������������������������������������������������������������������������������������������ 331
Stablecoins������������������������������������������������������������������������������������������������������������������������������� 331
Fiat-Backed Stablecoins������������������������������������������������������������������������������������������������������ 333
Crypto-Backed Stablecoins������������������������������������������������������������������������������������������������� 334
Non-Collateralized Stablecoins������������������������������������������������������������������������������������������� 340
Crypto Exchanges��������������������������������������������������������������������������������������������������������������������� 340
Creating a Decentralized Exchange������������������������������������������������������������������������������������� 342
Creating the Token Contract������������������������������������������������������������������������������������������������ 343
Deploying the Token Contract���������������������������������������������������������������������������������������������� 343
Creating the DEX Contract��������������������������������������������������������������������������������������������������� 345
Funding the DEX������������������������������������������������������������������������������������������������������������������ 351
Swapping WML Tokens for LWM Tokens������������������������������������������������������������������������������ 354
Summary���������������������������������������������������������������������������������������������������������������������������������� 359

Index��������������������������������������������������������������������������������������������������������������������� 361

ix
About the Author
Wei-Meng Lee is the founder of Developer Learning
Solutions, a technology company specializing in hands-on
training of blockchain and other emerging technologies.
He has many years of training expertise and his courses
emphasize a learn-by-doing approach. He is a master at
making learning a new programming language or technology
less intimidating and more fun. He can be found speaking
at conferences worldwide such as NDC, and he regularly
contributes to online and print publications such as Medium
(https://weimenglee.medium.com) and CoDe Magazine.
He is active on social media, on his blog calendar.learn2develop.net, on Facebook
(www.facebook.com/DeveloperLearningSolutions), on Twitter as @weimenglee, and
on LinkedIn (linkedin.com/leeweimeng).

xi
About the Technical Reviewer
Prasanth Sahoo is a Blockchain Certified Professional,
Professional Scrum Master, and Microsoft Certified
Trainer who is passionate about helping others
learn how to use and gain benefits from the latest
technologies. He is a thought leader and practitioner
in blockchain, cloud, and Scrum. He also handles the
Agile methodology, cloud, and blockchain technology
community initiatives within TransUnion through
coaching, mentoring, and grooming techniques.
Prasanth is an adjunct professor and a technical speaker. He was selected as a speaker
at the China International Industry Big Data Expo 2018 by the Chinese government and
also to the International Blockchain Council by the governments of Telangana and Goa.
He also received accolades for his presentation at China International Industry Big Data
Expo 2018 by the Chinese government. Prasanth has published a patent titled "Digital
Educational Certificate Management System using IPFS Based Blockchain."
To date, Prasanth has reached over 50,000 students, mostly within the technical
domain. He is a working group member of the CryptoCurrency Certification
Consortium, Scrum Alliance, Scrum Organization, and International Institute of
Business Analysis.

xiii
Acknowledgments
Writing a book is immensely exciting, but along with it comes long hours of hard work
and responsibility, straining to get things done accurately and correctly. To make a book
possible, a lot of unsung heroes work tirelessly behind the scenes.
For this, I would like to take this opportunity to thank a number of special people
who made this book possible. First, I want to thank my acquisitions editor, Joan Murray,
for giving me this opportunity. Thanks for suggesting that I update this book with the
latest happenings in the crypto world!
Next, a huge thanks to Jill Balzano, my associate editor, who was always very patient
with me, even though I missed several of my deadlines for the revision of this book.
Thanks, Jill, for your guidance. I could not finish the book without your encouragement
and help!
Equally important is my project coordinator, Shobana Srinivasan. Shobana has been
very patient with me during the whole project while I struggle between work and writing.
Thanks, Shobana, for the assistance rendered during the project!
Last, but not least, I want to thank my parents and my wife, Sze Wa, for all
the support they have given me. They have selflessly adjusted their schedules to
accommodate my busy schedule when I was working on this book. I love you all!

xv
Introduction
Welcome to Beginning Ethereum Smart Contracts Programming, Second Edition!
This book is a quick guide to getting started with Ethereum smart contracts
programming. It starts off with a discussion of blockchain and the motivations behind it.
You will learn what a blockchain is, 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. Since the publication of the
first edition of this book, a lot of things have changed. In particular, Ethereum has been
updated to use Proof of Stake (PoS) (instead of Proof of Work) as its consensus algorithm.
This book has been updated to include a discussion of how PoS works.
Once that is out of the way, you dive into the Ethereum blockchain. You will learn
how to use an Ethereum client (Geth) to create a private Ethereum blockchain and
perform simple transactions such as sending Ethers to another account.
The next part of this book discusses smart contract programming, a unique feature of
the Ethereum blockchain. You will jumpstart 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 should be able to write smart contracts, test them, deploy them, and create web
applications to interact with them. In this second edition, I have added more examples
to make it easy for you to explore more complex smart contracts.
The last part of this book touches on tokens and DeFi (decentralized finance),
something that has taken the cryptocurrency market by storm. You will be able to create
your own tokens, launch your own ICO, and write token contracts that allow buyers
to buy tokens using Ethers. As a bonus, I show you how to write a DEX (decentralized
exchange) smart contract to exchange two different tokens!
This book is designed 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 enjoy working on the sample projects as much as I enjoyed creating them!

xvii
CHAPTER 1

Understanding the
Science Behind
Blockchain: Cryptography
The reason you are reading this book is because you want to understand what a
blockchain is, how it works, and how you can write smart contracts on it to do cool
things. And while I perfectly understand that you are excited to get started in this first
chapter, we need to take a step back and look at one fundamental technology that makes
blockchain possible: cryptography.
In this chapter, I will explain what cryptography is, the different types of
cryptographic algorithms, how they work, and how they play a vital role in the world
of blockchain. I will also show you how to experiment with the various cryptographic
algorithms using the Python programming language. Even if you are familiar with
cryptography, I suggest scanning through this chapter so that you have a firm foundation
for the subsequent chapters.

What Is Cryptography?
Whether you are trying to build a web application to store users’ credentials or writing
a network application to securely transmit encrypted messages, or even trying to
understand how blockchain works, you need to understand one important topic:
cryptography.
So, what exactly is cryptography? Put simply, cryptography (or cryptology) is the
practice and study of hiding information. It is the science of keeping information secret
and safe.

1
© Wei-Meng Lee 2023
W.-M. Lee, Beginning Ethereum Smart Contracts Programming, https://doi.org/10.1007/978-1-4842-9271-6_1
Another Random Scribd Document
with Unrelated Content
some form or other, all men are called on to pay for the privileges
they enjoy, nor could it be expected that the slave would be an
exception to this general rule. If the marriage bond could be
legalized and rendered more sacred, and families not allowed to be
separated by sale, many cases of hardship would be prevented. This
is a matter for the serious consideration of the slaveholder, if he
would manifest to the world a desire to place the dependent race in
the best possible condition, consistent with its safety.
Of the possibility of such reforms, they are the best judges, however,
who have the burden upon them, and are best acquainted with the
wants and capacities of the African race. It is easy for those at a
distance to give advice, in regard to a social system, the practical
working of which they are quite ignorant of, but those who are born
and bred under such system can only know the difficulties that lie in
the way of reform, especially when those difficulties are aggravated
by interference from abroad.
Slavery may finally come to an end in the United States, by the
operation of natural causes, such as the rapid increase and constant
encroachment of free labor, and the fact that slave labor is so
expensive and tends so greatly to the impoverishing of the soil. As
Slavery dies out, the colored race will disappear from the scene
forever. It is not for us, I think, to hasten that time by revolution and
servile insurrection, to put torches and pikes into the hands of such
a population to be used against the whites, in re-enacting all the
horrors of a St. Domingo massacre, and at the same time sealing its
own fate as suddenly and as rapidly as the dew disappears before
the rising sun.
Public sentiment has undergone a marked change in England, on the
subject of Slavery, within the last few years. The Anti-Slavery
sentiment, like an epidemic, swept over the whole length and
breadth of Great Britain, and in its course swept away Slavery in the
British West Indies. The natural and inevitable re-action has already
taken place in England, and happy will it be for us if it comes in this
country before it is too late. That such a re-action is already taking
place in the United States, hastened by the foray of John Brown,
there is great reason to believe.
The following extracts from the London Times are very significant:—

Effect of Emancipation on the African Race.—There is no blinking


the truth. Years of bitter experience; years of hope deferred; of
self-devotion unrequited; of poverty; of humiliation; of prayers
unanswered; of sufferings derided; of insults unresented; of
contumely patiently endured,—have convinced us of the truth.
It must be spoken out loudly and energetically, despite the wild
mockings of "howling cant." The freed West India slave will not
till the soil for wages; the free son of the ex-slave is as obstinate
as his sire. He will not cultivate lands which he has not bought
for his own. Yams, mangoes, and plantains—these satisfy his
wants; he cares not for yours. Cotton, sugar and coffee, and
tobacco—he cares but little for them. And what matters it to
him that the Englishman has sunk his thousands and tens of
thousands on mills, machinery and plants, which now totter on
the languishing estate that for years has only returned beggary
and debt. He eats his yams, and sniggers at "Buckra."
We know not why this should be, but it is so. The negro has
been bought with a price—the price of English taxation and
English toil. He has been redeemed from bondage by the sweat
and travail of some millions of hard-working Englishmen. Twenty
millions of pounds sterling—one hundred millions of dollars—
have been distilled from the brains and muscles of the free
English laborer, of every degree, to fashion the West Indian
negro into a "free and independent laborer." "Free and
independent" enough he has become, God knows; but laborer
he is not; and, so far as we can see, never will be. He will sing
hymns and quote texts; but honest, steady industry he not only
detests but despises. We wish to Heaven that some people in
England—neither Government people nor parsons nor
clergymen, but some just-minded, honest-hearted and clear-
sighted men—would go out to some of the islands (say Jamaica,
Dominica, or Antigua)—not for a month or three months, but for
a year—would watch the precious protege of English
philanthropy, the freed negro, in his daily habits; would watch
him as he lazily plants his little squatting; would see him as he
proudly rejects agricultural or domestic services, or accepts it
only at wages ludicrously disproportionate to the value of his
work. We wish, too, they would watch him while, with a hide
thicker than that of a hippopotamus, and a body to which fervid
heat is a comfort rather than an annoyance, he droningly
lounges over the prescribed task on which the intrepid
Englishman, uninured to the burning sun, consumes his
impatient energy, and too often sacrifices his life. We wish they
would go out and view the negro in all the blazonry of his
idleness, his pride, his ingratitude, contemptuously sneering at
the industry of that race which made him free, and then come
home and teach the memorable lesson of their experience to
the fanatics who have perverted him into what he is.
* * * * * * * *
The Abolitionists in America would have the population of the
Southern States turned into a mixed race, whites, blacks, and
mulattoes being on terms of equality, and constantly
intermarrying; but if one thing more than another has tended to
give to the Anglo-Saxon race in the New World the victory over
the Spanish, it is that it has kept itself apart from the red and
negro races, and lodged power constantly in the hands of men
of European origin. It has been fully proved, not only on the
American continent, but in our own colonies, that the enforced
equality of European and African tends, not to the elevation of
the black, but the degradation of the white man. We cannot find
any sympathy for those who would try, in the United States, the
plan of a half-caste Republic, and we trust that the Federal
Government and the right-thinking part of the community will
protect the South from the repetition of such outrages as that at
Harper's Ferry.

Our own race is boastful as well as intolerant and aggressive. This is


especially true of the New England type, and hence it is that we are
prone to regard ourselves in many, if not all respects, superior to the
people of the South. In some respects, undoubtedly, we have the
advantage of those who have been born and educated under a very
different social system; but, on the other hand, according to the law
of compensation, we lack much that is valuable in the Southern
character and mental constitution.
The nature of our climate and more especially of our institutions, has
given to our English blood a new and most powerful stimulus, so
that we develope an immense amount of intellectual energy and
activity, which constantly seeks vent, and which constantly tends to
run into some extreme or excess. Having lived for many years in a
state of great material prosperity, we are prone to wax fat and kick.
We have known no real evils, no invasion from without, or civil war
within, and for want of any real danger we conjure up those that are
imaginary. We torment ourselves with evils which have no existence
but in our own brain. I think it was Judge Marshall who speaks of
those imaginary evils, which as they are without cause, are also
without remedy.
The Southern mind is less active and more conservative, sometimes
erratic, but generally disposed to take a common sense and rational
view of things, and is, in some respects, more reliable than our own.
It forms an admirable check in our political system, and preserves us
from a natural tendency to run into the extreme of radicalism, and
that spirit of agrarianism which has destroyed all former Republics.
The constant tendency in a Republic is to remove all constitutional
checks intended for the security of individual rights, and reduce
everything to the rule of the majority. It is obvious that the Senate
of the United States and the Supreme Court, though intended as
checks upon popular impulse and outbreaks, are yet but very
imperfect barriers when opposed to what is termed the will of the
people. It requires but a few years to change the political character
of the Senate so that it shall reflect the prevailing sentiments of the
day, and the same is true of the Supreme Court. In some of our
States the judges are already elected from year to year, and must
become to a greater or less extent political partizans. When these
checks are removed and the rights of the individual are dependant
on the bare will of the majority, then we have a pure democracy,
which is pure despotism, and a despotism so dreadful that it soon
gives way to despotism of a milder form in the person of a military
Dictator. We have no landed aristocracy which, in England, stands
between the people and the throne, keeping each from encroaching
upon the other, nor any real check in our system of government,
unless it is the fixed fact of a large number of States, whose
population is naturally and necessarily conservative, and which
stands like a rock against the surging waves of popular excitement
of agrarianism and radicalism from whatever quarter they may
come. The assertion that Slavery was the corner-stone of American
liberty, made some years ago by a statesman from South Carolina,
was looked upon with amazement as a most absurd paradox, but
time may show that it contained a truth which we have as yet failed
to see and comprehend.
The Southern character is more impulsive, but also more open and
genial than our own. If it shows a hasty spark, it is also soon cold
and rational again. It is not brooding and intolerant, nor easily led
away into excesses, such as too often befall us of a more Northern
clime. One prominent cause for such difference is, no doubt, to be
found in the fact that, while we, at the North, live in towns and cities
where men are in a constant state of action and reaction upon each
other, and the masses can be suddenly and extensively roused and
excited, the Southern Planters live remote from each other, and, in
many cases, in almost entire seclusion. Such a population is less in
danger from these moral epidemics that from time to time sweep
over communities, because it is sparse, and therefore not so much
exposed to exciting causes; thus, while it loses many good
influences which flow from a more compact society, escaping also
many serious evils to which the latter is subject. It is not France, but
Paris, the great centre of population, the seat of all that is luxurious
and refined, of science and of art, of everything in short which can
serve to adorn and embellish social life; it is this Paris alone that
makes and unmakes kings and emperors, that overthrows one
dynasty during the night and sets up another the next morning, and
then gives the law to the nation which stands looking on. Some
editor or some orator touches that sympathetic telegraphic chord
which passes through each individual of this vast living mass, and in
an instant, as it were, the gutters run with blood, a ferocious mob
rushes through every avenue, seeking vengeance for wrongs, which,
if they have no existence, in fact, exist not the less really in the
excited and inflamed imagination. Then comes a satiety of blood,
then a re-action, and then a state of things too often far worse than
the first. Our own city of New York is considered by many to have
become incapable of intelligent self-government, and to exhibit
those evils which, especially under a government like our own, flow
from the collection of a very large population at one point. A sparse
and widely scattered population, which is also by necessity highly
consecutive, may supply the very check we most need and which is
not to be found in paper constitutions, courts or senates.
In the gradual progress of time, free labor will doubtless overrun the
more Northern Slave States, bringing fertility to the soil, and
improving in many respects the condition of the white race, though
fraught with ruin to all of African descent. My sympathies are with
the latter as well as the former, and I cannot wish to see our
swelling, aggressive, Northern Anglo-Saxon tide, overflowing the
Southern States, sweeping away perhaps the most conservative and
useful element in our republican system, and at the same time
utterly destroying in its course that helpless race which, in the
providence of God, has been cast upon our shores. There is room
enough for us all to live together in peace and harmony. The two
races can co-exist in their present relative condition, but in no other
way. This is the great lesson of history, experience, statistics, and
the observation of every day.

FOOTNOTES:
[1] Our English common law is said to be the perfection of human
wisdom. It is founded in right, and its object is to ascertain and
establish the right. The sources from which it is drawn have been
thus enumerated. "The law of nature; the revealed law of God;
Christianity, morality, and religion; common sense, legal reason,
justice, natural equity, humanity."
[2] Since the above was written, I find that the same theory is
advanced by Mr. Buckle, in his History of Civilization, a very obvious
theory, it would seem, and the result of the most common
observation, viz: that where two distinct races come together there
can be no amalgamation, but the inferior must die out in presence of
the superior.
*** END OF THE PROJECT GUTENBERG EBOOK SLAVERY ***

Updated editions will replace the previous one—the old editions


will be renamed.

Creating the works from print editions not protected by U.S.


copyright law means that no one owns a United States
copyright in these works, so the Foundation (and you!) can copy
and distribute it in the United States without permission and
without paying copyright royalties. Special rules, set forth in the
General Terms of Use part of this license, apply to copying and
distributing Project Gutenberg™ electronic works to protect the
PROJECT GUTENBERG™ concept and trademark. Project
Gutenberg is a registered trademark, and may not be used if
you charge for an eBook, except by following the terms of the
trademark license, including paying royalties for use of the
Project Gutenberg trademark. If you do not charge anything for
copies of this eBook, complying with the trademark license is
very easy. You may use this eBook for nearly any purpose such
as creation of derivative works, reports, performances and
research. Project Gutenberg eBooks may be modified and
printed and given away—you may do practically ANYTHING in
the United States with eBooks not protected by U.S. copyright
law. Redistribution is subject to the trademark license, especially
commercial redistribution.

START: FULL LICENSE


THE FULL PROJECT GUTENBERG LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK

To protect the Project Gutenberg™ mission of promoting the


free distribution of electronic works, by using or distributing this
work (or any other work associated in any way with the phrase
“Project Gutenberg”), you agree to comply with all the terms of
the Full Project Gutenberg™ License available with this file or
online at www.gutenberg.org/license.

Section 1. General Terms of Use and


Redistributing Project Gutenberg™
electronic works
1.A. By reading or using any part of this Project Gutenberg™
electronic work, you indicate that you have read, understand,
agree to and accept all the terms of this license and intellectual
property (trademark/copyright) agreement. If you do not agree
to abide by all the terms of this agreement, you must cease
using and return or destroy all copies of Project Gutenberg™
electronic works in your possession. If you paid a fee for
obtaining a copy of or access to a Project Gutenberg™
electronic work and you do not agree to be bound by the terms
of this agreement, you may obtain a refund from the person or
entity to whom you paid the fee as set forth in paragraph 1.E.8.

1.B. “Project Gutenberg” is a registered trademark. It may only


be used on or associated in any way with an electronic work by
people who agree to be bound by the terms of this agreement.
There are a few things that you can do with most Project
Gutenberg™ electronic works even without complying with the
full terms of this agreement. See paragraph 1.C below. There
are a lot of things you can do with Project Gutenberg™
electronic works if you follow the terms of this agreement and
help preserve free future access to Project Gutenberg™
electronic works. See paragraph 1.E below.
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright
law in the United States and you are located in the United
States, we do not claim a right to prevent you from copying,
distributing, performing, displaying or creating derivative works
based on the work as long as all references to Project
Gutenberg are removed. Of course, we hope that you will
support the Project Gutenberg™ mission of promoting free
access to electronic works by freely sharing Project Gutenberg™
works in compliance with the terms of this agreement for
keeping the Project Gutenberg™ name associated with the
work. You can easily comply with the terms of this agreement
by keeping this work in the same format with its attached full
Project Gutenberg™ License when you share it without charge
with others.

1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside
the United States, check the laws of your country in addition to
the terms of this agreement before downloading, copying,
displaying, performing, distributing or creating derivative works
based on this work or any other Project Gutenberg™ work. The
Foundation makes no representations concerning the copyright
status of any work in any country other than the United States.

1.E. Unless you have removed all references to Project


Gutenberg:

1.E.1. The following sentence, with active links to, or other


immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project
Gutenberg™ work (any work on which the phrase “Project
Gutenberg” appears, or with which the phrase “Project
Gutenberg” is associated) is accessed, displayed, performed,
viewed, copied or distributed:

This eBook is for the use of anyone anywhere in the United


States and most other parts of the world at no cost and
with almost no restrictions whatsoever. You may copy it,
give it away or re-use it under the terms of the Project
Gutenberg License included with this eBook or online at
www.gutenberg.org. If you are not located in the United
States, you will have to check the laws of the country
where you are located before using this eBook.

1.E.2. If an individual Project Gutenberg™ electronic work is


derived from texts not protected by U.S. copyright law (does not
contain a notice indicating that it is posted with permission of
the copyright holder), the work can be copied and distributed to
anyone in the United States without paying any fees or charges.
If you are redistributing or providing access to a work with the
phrase “Project Gutenberg” associated with or appearing on the
work, you must comply either with the requirements of
paragraphs 1.E.1 through 1.E.7 or obtain permission for the use
of the work and the Project Gutenberg™ trademark as set forth
in paragraphs 1.E.8 or 1.E.9.

1.E.3. If an individual Project Gutenberg™ electronic work is


posted with the permission of the copyright holder, your use and
distribution must comply with both paragraphs 1.E.1 through
1.E.7 and any additional terms imposed by the copyright holder.
Additional terms will be linked to the Project Gutenberg™
License for all works posted with the permission of the copyright
holder found at the beginning of this work.

1.E.4. Do not unlink or detach or remove the full Project


Gutenberg™ License terms from this work, or any files
containing a part of this work or any other work associated with
Project Gutenberg™.

1.E.5. Do not copy, display, perform, distribute or redistribute


this electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1
with active links or immediate access to the full terms of the
Project Gutenberg™ License.

1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if
you provide access to or distribute copies of a Project
Gutenberg™ work in a format other than “Plain Vanilla ASCII” or
other format used in the official version posted on the official
Project Gutenberg™ website (www.gutenberg.org), you must,
at no additional cost, fee or expense to the user, provide a copy,
a means of exporting a copy, or a means of obtaining a copy
upon request, of the work in its original “Plain Vanilla ASCII” or
other form. Any alternate format must include the full Project
Gutenberg™ License as specified in paragraph 1.E.1.

1.E.7. Do not charge a fee for access to, viewing, displaying,


performing, copying or distributing any Project Gutenberg™
works unless you comply with paragraph 1.E.8 or 1.E.9.

1.E.8. You may charge a reasonable fee for copies of or


providing access to or distributing Project Gutenberg™
electronic works provided that:

• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”

• You provide a full refund of any money paid by a user who


notifies you in writing (or by e-mail) within 30 days of receipt
that s/he does not agree to the terms of the full Project
Gutenberg™ License. You must require such a user to return or
destroy all copies of the works possessed in a physical medium
and discontinue all use of and all access to other copies of
Project Gutenberg™ works.

• You provide, in accordance with paragraph 1.F.3, a full refund of


any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.

• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project


Gutenberg™ electronic work or group of works on different
terms than are set forth in this agreement, you must obtain
permission in writing from the Project Gutenberg Literary
Archive Foundation, the manager of the Project Gutenberg™
trademark. Contact the Foundation as set forth in Section 3
below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on,
transcribe and proofread works not protected by U.S. copyright
law in creating the Project Gutenberg™ collection. Despite these
efforts, Project Gutenberg™ electronic works, and the medium
on which they may be stored, may contain “Defects,” such as,
but not limited to, incomplete, inaccurate or corrupt data,
transcription errors, a copyright or other intellectual property
infringement, a defective or damaged disk or other medium, a
computer virus, or computer codes that damage or cannot be
read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except


for the “Right of Replacement or Refund” described in
paragraph 1.F.3, the Project Gutenberg Literary Archive
Foundation, the owner of the Project Gutenberg™ trademark,
and any other party distributing a Project Gutenberg™ electronic
work under this agreement, disclaim all liability to you for
damages, costs and expenses, including legal fees. YOU AGREE
THAT YOU HAVE NO REMEDIES FOR NEGLIGENCE, STRICT
LIABILITY, BREACH OF WARRANTY OR BREACH OF CONTRACT
EXCEPT THOSE PROVIDED IN PARAGRAPH 1.F.3. YOU AGREE
THAT THE FOUNDATION, THE TRADEMARK OWNER, AND ANY
DISTRIBUTOR UNDER THIS AGREEMENT WILL NOT BE LIABLE
TO YOU FOR ACTUAL, DIRECT, INDIRECT, CONSEQUENTIAL,
PUNITIVE OR INCIDENTAL DAMAGES EVEN IF YOU GIVE
NOTICE OF THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you


discover a defect in this electronic work within 90 days of
receiving it, you can receive a refund of the money (if any) you
paid for it by sending a written explanation to the person you
received the work from. If you received the work on a physical
medium, you must return the medium with your written
explanation. The person or entity that provided you with the
defective work may elect to provide a replacement copy in lieu
of a refund. If you received the work electronically, the person
or entity providing it to you may choose to give you a second
opportunity to receive the work electronically in lieu of a refund.
If the second copy is also defective, you may demand a refund
in writing without further opportunities to fix the problem.

1.F.4. Except for the limited right of replacement or refund set


forth in paragraph 1.F.3, this work is provided to you ‘AS-IS’,
WITH NO OTHER WARRANTIES OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of
damages. If any disclaimer or limitation set forth in this
agreement violates the law of the state applicable to this
agreement, the agreement shall be interpreted to make the
maximum disclaimer or limitation permitted by the applicable
state law. The invalidity or unenforceability of any provision of
this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the


Foundation, the trademark owner, any agent or employee of the
Foundation, anyone providing copies of Project Gutenberg™
electronic works in accordance with this agreement, and any
volunteers associated with the production, promotion and
distribution of Project Gutenberg™ electronic works, harmless
from all liability, costs and expenses, including legal fees, that
arise directly or indirectly from any of the following which you
do or cause to occur: (a) distribution of this or any Project
Gutenberg™ work, (b) alteration, modification, or additions or
deletions to any Project Gutenberg™ work, and (c) any Defect
you cause.

Section 2. Information about the Mission


of Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new
computers. It exists because of the efforts of hundreds of
volunteers and donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project
Gutenberg™’s goals and ensuring that the Project Gutenberg™
collection will remain freely available for generations to come. In
2001, the Project Gutenberg Literary Archive Foundation was
created to provide a secure and permanent future for Project
Gutenberg™ and future generations. To learn more about the
Project Gutenberg Literary Archive Foundation and how your
efforts and donations can help, see Sections 3 and 4 and the
Foundation information page at www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-
profit 501(c)(3) educational corporation organized under the
laws of the state of Mississippi and granted tax exempt status
by the Internal Revenue Service. The Foundation’s EIN or
federal tax identification number is 64-6221541. Contributions
to the Project Gutenberg Literary Archive Foundation are tax
deductible to the full extent permitted by U.S. federal laws and
your state’s laws.

The Foundation’s business office is located at 809 North 1500


West, Salt Lake City, UT 84116, (801) 596-1887. Email contact
links and up to date contact information can be found at the
Foundation’s website and official page at
www.gutenberg.org/contact
Section 4. Information about Donations to
the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission
of increasing the number of public domain and licensed works
that can be freely distributed in machine-readable form
accessible by the widest array of equipment including outdated
equipment. Many small donations ($1 to $5,000) are particularly
important to maintaining tax exempt status with the IRS.

The Foundation is committed to complying with the laws


regulating charities and charitable donations in all 50 states of
the United States. Compliance requirements are not uniform
and it takes a considerable effort, much paperwork and many
fees to meet and keep up with these requirements. We do not
solicit donations in locations where we have not received written
confirmation of compliance. To SEND DONATIONS or determine
the status of compliance for any particular state visit
www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states


where we have not met the solicitation requirements, we know
of no prohibition against accepting unsolicited donations from
donors in such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot


make any statements concerning tax treatment of donations
received from outside the United States. U.S. laws alone swamp
our small staff.

Please check the Project Gutenberg web pages for current


donation methods and addresses. Donations are accepted in a
number of other ways including checks, online payments and
credit card donations. To donate, please visit:
www.gutenberg.org/donate.

Section 5. General Information About


Project Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could
be freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose
network of volunteer support.

Project Gutenberg™ eBooks are often created from several


printed editions, all of which are confirmed as not protected by
copyright in the U.S. unless a copyright notice is included. Thus,
we do not necessarily keep eBooks in compliance with any
particular paper edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg
Literary Archive Foundation, how to help produce our new
eBooks, and how to subscribe to our email newsletter to hear
about new eBooks.

You might also like