Ethereum For Dummies - Michael G. Solomon - E-Book

Ethereum For Dummies E-Book

Michael G. Solomon

0,0
19,99 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Dive into a secure future Professionals look to Ethereum as a blockchain-based platform to develop safe applications and conduct secure transactions. It takes a knowledgeable guiding hand to understand how Ethereum works and what it does -- and Ethereum For Dummies provides that guidance. Written by one of the leading voices in the blockchain community and best selling author of Blockchain For Dummies, this book demystifies the workings of Ethereum and shows how it can enhance security, transactions, and investments. As an emerging application of blockchain technology, Ethereum attracts a wide swath of professionals ranging from financial pros who see it as a way to enhance their business, security analysts who want to conduct secure transactions, programmers who build apps that employ the Ethereum blockchain, or investors interested in cashing in on the rise of cryptocurrency. Ethereum For Dummies offers a starting point to all members of this audience as it provides easy-to-understand explanation of the tools and techniques of using Ethereum. * Understand the fundamentals of Ethereum * Build smart contracts * Create decentralized applications * Examine public and private chains If you need to get a grip on one of the biggest applications of blockchain technology, this book makes it easier.

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 395

Veröffentlichungsjahr: 2019

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Ethereum™ For Dummies®

Published by: John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030-5774, www.wiley.com

Copyright © 2019 by John Wiley & Sons, Inc., Hoboken, New Jersey

Published simultaneously in Canada

No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without the prior written permission of the Publisher. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions.

Trademarks: Wiley, For Dummies, the Dummies Man logo, Dummies.com, Making Everything Easier, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and may not be used without written permission. Ethereum is a trademark of Ethereum Foundation. All other trademarks are the property of their respective owners. John Wiley & Sons, Inc. is not associated with any product or vendor mentioned in this book.

LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY SITUATION. THIS WORK IS SOLD WITH THE UNDERSTANDING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PROFESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENT PROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGANIZATION OR WEBSITE IS REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE OF FURTHER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFORMATION THE ORGANIZATION OR WEBSITE MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE. FURTHER, READERS SHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAPPEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ.

For general information on our other products and services, please contact our Customer Care Department within the U.S. at 877-762-2974, outside the U.S. at 317-572-3993, or fax 317-572-4002. For technical support, please visit https://hub.wiley.com/community/support/dummies.

Wiley publishes in a variety of print and electronic formats and by print-on-demand. Some material included with standard print versions of this book may not be included in e-books or in print-on-demand. If this book refers to media such as a CD or DVD that is not included in the version you purchased, you may download this material at http://booksupport.wiley.com. For more information about Wiley products, visit www.wiley.com.

Library of Congress Control Number: 2019936125

ISBN 978-1-119-47412-8 (pbk); ISBN 978-1-119-47411-1 (ebk); ISBN 978-1-119-47406-7 (ebk)

Ethereum™ For Dummies®

To view this book's Cheat Sheet, simply go to www.dummies.com and search for “Ethereum For Dummies Cheat Sheet” in the Search box.

Table of Contents

Cover

Introduction

About This Book

Foolish Assumptions

Icons Used in This Book

Beyond the Book

Where to Go from Here

Part 1: Getting to Know Blockchain and Ethereum

Chapter 1: Introducing Ethereum

Describing Blockchain Technology

Introducing Ethereum

Exploring Ethereum’s Consensus, Mining, and Smart Contracts

Buying, Spending, and Trading Ether

Getting Started with DAO and ICO

Exploring the Ethereum Ecosystem

Delving into Development Tools

Building Blockchain Apps

Chapter 2: Learning about Blockchain

Exploring Distributed Applications

Examining the Bitcoin Solution to the Distributed Dilemma

Describing Blockchains

Building Blockchains

Understanding How Blockchains and Databases Store Data Differently

Effectively Using Blockchains

Chapter 3: Exploring Use Cases for Ethereum

Diving Into Ethereum Applications

Exploring Financial Services

Establishing Digital Identity Management

Examining Industry Applications

Enabling Effective Governance

Part 2: Setting Up Your Ethereum Development Environment

Chapter 4: Examining the Ethereum Ecosystem and Development Lifecycle

Exploring the Ethereum Blockchain Block Structure

Describing Smart Contracts

Introducing Solidity, the Language of Smart Contracts

Working with the Ethereum Virtual Machine

Fueling Your Code with Gas

Surveying Tools for Developing, Testing, and Deploying Ethereum Apps

Describing the Ethereum Development Lifecycle

Introducing Smart Contract Development Tools

Chapter 5: Getting and Configuring Ethereum Development Tools

Examining Why Multiple Ethereum Development Tools Are Available

Downloading, Installing, and Configuring All the Pieces

Chapter 6: Establishing an Ethereum Wallet

Unlocking the Secrets of an Ethereum Wallet

Examining the Types of Ethereum Wallets

Choosing an Ethereum Wallet

Installing MetaMask, an Ethereum Wallet

Part 3: Building Ethereum Distributed Blockchain Apps

Chapter 7: Building Your First Ethereum Apps

Validating Your Ethereum Development Environment

Exploring the Ganache Test Environment

Designing Simple Smart Contracts

Coding Your First Smart Contract

Running Your First Smart Contract

Paying as You Go

Chapter 8: Learning about Smart Contracts

Introducing Supply Chain and Common Challenges

Examining How Blockchain Can Help Resolve Supply Chain Problems

Describing a Blockchain Supply Chain Solution

Digging into Solidity

Describing Basic Smart Contract Syntax

Handling Data in Solidity

Learning about Computation and Gas

Exploring Access Modes and Visibility of Smart Contract Functions and Data

Controlling Execution Flow

Handling Errors and Exceptions

Chapter 9: Writing Your Own Smart Contracts with Solidity

Reviewing Supply Chain Design Specification

Creating New Smart Contracts

Coding Primary Functions

Using Events

Introducing Ownership

Designing for Security

Implementing Minimal Functionality

Part 4: Testing and Deploying Ethereum Apps

Chapter 10: Testing Ethereum Apps

Understanding Ethereum dApp Testing

Deploying a dApp to a Test Ethereum Blockchain

Writing Tests for Ethereum dApps

Logging and Handling Errors

Fixing Bugs in a dApp

Chapter 11: Deploying and Maintaining Ethereum Apps

Test Blockchain Options versus Live Blockchains

Anticipating Differences in Live Environments

Preparing Your Configuration for Deploying to Different Networks

Deploying a dApp

Chapter 12: Integrating Non-Blockchain Apps with Ethereum

Comparing Blockchain and Database Storage

Contrasting Execution and Flow in Blockchain dApps and Traditional Applications

Designing Goals for Incorporating Blockchain into an Existing Application

Identifying Interface Data and Transaction Requirements

Creating or Modifying Contracts to Provide Data Interface

Testing Integrated dApps

Deploying Integrated dApps

Part 5: The Part of Tens

Chapter 13: Ten Free Ethereum Resources

Exploring Alternative Ethereum Development Frameworks

Selecting a Free Integrated Development Environment

Exploring Ethereum Clients and APIs

Focusing on Wallets and Security

Learning More About Developing Ethereum dApps

Chapter 14: Ten Design Principles for Distributed Blockchain Apps

Designing for Trust

Enforcing Consistency

Removing Doubt through Transparency

Providing Feedback, Guidance, and Setting Expectations

Handling Mistakes with Class

Designing Functions that Focus on User Actions, Not Data

Storing Data Based on User Actions, Not Data Structures

Keeping It Simple

Expecting Blockchain Access to Be Expensive

Staying Out of the User's Way

Chapter 15: Top Ten Ethereum Projects

Predicting Future Events with Gnosis

Crowdsourcing Event Predictions in Augur

Managing Decentralized Organizations with Aragon

Breeding and Collecting Cryptokitties

Exchanging Tokens with IDEX

Creating Your Digital Identity with uPort

Sharing Your Thoughts on the Blockchain with EtherTweet

Searching for Jobs with EthLance

Using TenX to Pay with Cryptocurrency

Buying and Selling Computing Power with Golem

Index

About the Author

Connect with Dummies

End User License Agreement

List of Tables

Chapter 2

TABLE 2-1 Differences between Databases and Blockchain

Chapter 4

TABLE 4-1 Ethereum Clients

TABLE 4-2 Ethereum Development and Testing Blockchains

TABLE 4-3 Ethereum Compilers and Testing Frameworks

TABLE 4-4 Source Code Editors/IDEs

Chapter 6

TABLE 6-1 Popular Web Wallets

TABLE 6-2 Popular Desktop Wallets

TABLE 6-3 Popular Mobile Wallets

TABLE 6-4 Popular Hardware Wallets

TABLE 6-5 Popular Hardware Wallets

Chapter 8

TABLE 8-1 Supply Chain Obstacles

TABLE 8-2 Ethereum Solutions to Supply Chain Obstacles

TABLE 8-3 Connecting Physical Assets to Digital Assets

TABLE 8-4 Solidity Data Types

TABLE 8-5 Ethereum Gas Charges

TABLE 8-6 Solidity Visibility Modifiers

TABLE 8-7 Solidity Conditional and Iteration Statements

TABLE 8-8 Error-handling Guard Functions

Chapter 9

TABLE 9-1 Common Ethereum Security Mistakes

Chapter 10

TABLE 10-1 Smart contract test blockchain options

Chapter 12

TABLE 12-1 Database Storage versus Blockchain Storage

List of Illustrations

Chapter 1

FIGURE 1-1: Purchase ether using coinbase.com.

FIGURE 1-2: Purchasing ether with cash.

FIGURE 1-3: Current cryptocurrency prices.

FIGURE 1-4: coindesk ICO Tracker.

Chapter 2

FIGURE 2-1: Distributed processing architectures.

FIGURE 2-2: Blockchain architecture.

FIGURE 2-3: Public versus private blockchains.

Chapter 4

FIGURE 4-1: Ethereum block header.

FIGURE 4-2: Contents of an Ethereum transaction.

FIGURE 4-3: Smart contract software development lifecycle.

Chapter 5

FIGURE 5-1: The Go Ethereum (Geth) Download web page.

FIGURE 5-2: Geth Setup: Installation Options window.

FIGURE 5-3: Geth light node startup command.

FIGURE 5-4: Geth runtime messages.

FIGURE 5-5: The Ganache Download web page.

FIGURE 5-6: Support Ganache Analytics window.

FIGURE 5-7: Ganache Accounts window.

FIGURE 5-8: Ganache Settings window’s Server tab.

FIGURE 5-9: Truffle installation requirements.

FIGURE 5-10: Error message in PowerShell when NodeJS isn’t installed.

FIGURE 5-11: The NodeJS Download web page.

FIGURE 5-12: The NodeJS version message.

FIGURE 5-13: Installing Truffle.

FIGURE 5-14: Initializing a new Truffle project.

FIGURE 5-15: Microsoft Visual Studio Code download web page.

FIGURE 5-16: Visual Studio Code install options window.

FIGURE 5-17: Visual Studio Code IDE desktop.

FIGURE 5-18: Visual Studio Code IDE with the Solidity extension.

Chapter 6

FIGURE 6-1: A paper Ethereum wallet.

FIGURE 6-2: The MetaMask website.

FIGURE 6-3: The MetaMask Create Account window.

FIGURE 6-4: The MetaMask list of supported networks.

Chapter 7

FIGURE 7-1: Initiating a Truffle project.

FIGURE 7-2: Ganache Settings window.

FIGURE 7-3: Visual Studio Code in myProject.

FIGURE 7-4: Modified Truffle project configuration file.

FIGURE 7-5: Ganache accounts list.

FIGURE 7-6: Truffle deployment results.

FIGURE 7-7: Ganache blocks after deploying smart contracts.

FIGURE 7-8: Contents of a smart contract block.

FIGURE 7-9: Smart contract instance information.

Chapter 8

FIGURE 8-1: Ethereum supply chain flow.

FIGURE 8-2: Smart contract return values.

Chapter 9

FIGURE 9-1: Supply chain starting smart contracts in VS Code.

FIGURE 9-2: Editing SupplyChain.sol in VS Code.

FIGURE 9-3: Defining an event in VS Code.

FIGURE 9-4: Compiler output.

FIGURE 9-5: Compiler problems.

Chapter 10

FIGURE 10-1: Ganache settings window.

FIGURE 10-2: Modified Truffle project configuration file.

FIGURE 10-3: Deployment output.

FIGURE 10-4: Ganache accounts list.

FIGURE 10-5: Results of

getParticipantDetails()

.

FIGURE 10-6: Truffle test results.

Chapter 11

FIGURE 11-1: Ganache settings window with Automine disabled.

FIGURE 11-2: Ropsten network Ethereum faucet.

FIGURE 11-3: Rinkeby network Ethereum faucet.

FIGURE 11-4: Kovan network Ethereum faucet.

FIGURE 11-5: MetaMask Ethereum network choices.

FIGURE 11-6: MetaMask Copy Address to Clipboard option.

FIGURE 11-7: Kovan account balance in MetaMask.

FIGURE 11-8: The result of the Truffle

deploy

command.

Chapter 13

FIGURE 13-1: Atom IDE main desktop.

FIGURE 13-2: Remix web-based IDE.

FIGURE 13-3: EthFiddle web-based IDE.

FIGURE 13-4: Parity UI.

Chapter 14

FIGURE 14-1: Help ⇒   About menu item in VS Code.

FIGURE 14-2: VS Code About dialog box.

Chapter 15

FIGURE 15-1: Cryptokitties website.

FIGURE 15-2: IDEX website.

FIGURE 15-3: EtherTweet web interface.

FIGURE 15-4: EthLance website with participation description.

FIGURE 15-5: TenX debit card.

FIGURE 15-6: Golem website.

Guide

Cover

Table of Contents

Begin Reading

Pages

i

ii

1

2

3

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

261

262

263

Introduction

Blockchain technology is one of the most talked about disruptive technologies of the decade, and Ethereum is the most popular blockchain implementation. Blockchain technology holds the promise of making business interactions faster, cheaper, and more trustworthy.

Ethereum For Dummies introduces blockchain and Ethereum, covers their effect on today’s ways of doing business, and teaches you how to design and develop your own Ethereum decentralized applications. You learn how to set up a development environment and write smart contracts that create and control transactions on the Ethereum blockchain.

About This Book

Blockchain technology has the potential to change how business operates. The unprecedented opportunities blockchain promises to provide include easy data sharing among large groups, transparency, trusted transactions, and complete historical audit trails. Today, most organizations protect transaction data as a valued asset, but sharable data could change everything. Sharing trusted data with many participants in a business process has the potential of revolutionizing how organizations interact with one another, reducing the need and cost of middlemen and providing unprecedented transparency to business processes.

Staying current and pertinent means becoming part of this emerging blockchain business model. Ethereum For Dummies gives you the foundation of blockchain and Ethereum, and teaches you, in clear language, how to design and write your own software for the Ethereum blockchain environment.

Foolish Assumptions

I don’t make many assumptions about your experience with blockchain technology, application programming, or cryptography, but I do assume the following:

You have a computer and access to the Internet.

You know the basics of using your computer and the Internet, and how to download and install programs.

You know how to find files on your computer’s disk and how to create folders.

You’re new to blockchain and you aren’t an experienced software developer. If you already know how to write software applications, you can skip the sections on programming basics.

Icons Used in This Book

The Tip icon marks tips (duh!) and shortcuts that you can use to make learning and using Ethereum and Solidity easier.

Remember icons mark the information that’s especially important to know. To siphon off the most important information in each chapter, just skim through these icons.

The Technical Stuff icon marks information of a highly technical nature that you can normally skip over.

The Warning icon tells you to watch out! It marks important information that may save you headaches when writing your own blockchain applications.

Beyond the Book

In addition to the material in the print or e-book you’re reading right now, this product also comes with some access-anywhere goodies on the web. Check out the free cheat sheet for more on Ethereum and Solidity at www.dummies.com/cheatsheet/ethereumfd.

You’ll find summary information on Ethereum and Solidity tools as well as tips on how to use them effectively. The cheat sheet is a reference to use over and over as you gain experience in developing Ethereum decentralize applications.

In addition, if you’d rather download the code you see in this book instead of typing it, go to www.dummies.com/go/ethereumfd. You can download zip files for each of the projects you’ll create to develop and test smart contracts.

Where to Go from Here

The Dummies series tells you what you need to know and how to do the things you need to do to get the results you want. Readers don’t have to read the entire book to just learn about some topics. For example, if you just want to learn about smart contracts, you can jump right to Chapters 8 and 9. On the other hand, if you need to set up your own development environment, read Part 2, which tells you how to do that with clear, step-by-step instructions.

Part 1

Getting to Know Blockchain and Ethereum

IN THIS PART …

Get a big-picture overview of the Ethereum blockchain and how it works.

Discover how blockchain technology addresses distributed application problems.

Explore use cases that are good fits for blockchain technology.

Chapter 1

Introducing Ethereum

IN THIS CHAPTER

Getting to know Ethereum

Understanding ether and trading

Exploring DAOs and ICOs

Setting up an Ethereum development environment

Developing blockchain applications

Blockchain technology is the most disruptive technology introduced in our generation, and Ethereum is by far the most popular blockchain implementation in use today. You can’t read many technology articles or blogs without seeing something about how blockchain changes everything. Although some claims seem to be a little far-fetched, blockchain technology really is a game-changer.

Blockchain, which first burst on the scene in 2008, has gained global notoriety for what it has already changed and what is coming. At first, blockchain was all about a new type of electronic currency. But now, partially thanks to Ethereum, blockchain is so much more than a new way to pay for things. It’s a new way to think about things. It enables people and businesses to conduct business without many of the obstacles that have existed in trade relations for centuries.

In this book you learn about what blockchain is and why it is viewed as so radical. You discover how powerful Ethereum is in diverse domains and how you can harness its promise and power in your own organizations. If you want to learn what Ethereum is and how it can work for you without having to trudge through hundreds of pages of theory and background, this is the book for you.

Describing Blockchain Technology

You learn a lot more about blockchain technology in Chapter 2, but before you meet Ethereum, you need to know a little of Ethereum’s backstory.

If you already know what blockchain is, this section will be like watching yet another depiction of why Bruce Wayne became Batman. Feel free to skim it and move on to the next section. There are only so many ways you can kill Thomas and Martha Wayne.

Blockchain technology was introduced to support a new type of digital currency that you can trade in a trustless environment. Traditional currency exchanges require a trusted third party between the parties. Even if a buyer provides coins or bills to a seller at the point of transaction, some government provides the guarantee of the currency’s value. There is always a middleman. If the exchange involves a payment card or check, other financial institutions participate to handle the transfer of funds between parties.

In 2008, Satoshi Nakamoto published a paper that changed everything. Nakamoto’s paper described a new way to store and distribute data with verifiable integrity among a group of nodes that don’t trust one another. You learn more about how Nakamoto’s proposal works, and about bitcoin, the cryptocurrency proposed in the paper, in Chapter 2. At this point, the most important takeaway is that this paper showed how to take the requirement for a trusted (and omnipotent) central authority out of the mix. Using this new technology, called blockchain, application developers can create environments in which nodes that do not trust one another can share data that they can trust.

The idea is based on several concepts that are simple to consider but difficult to put into practice. First, data is logically presented as a ledger. The data isn’t really stored that way; you can just think of it as a ledger. A ledger is a way of recording data as transactions occur. One interesting feature of this ledger is that you can only add data to it. You can’t change anything after you’ve added it. So, the only two operations you can perform on this ledger are add and read. We refer to the “add only” property as the immutability property. In short, blockchains are immutable. As you’ll see, immutability is crucial for the technique to work.

Another feature is that data is added to this ledger in blocks. Blocks are collections of transactions, each with an owner’s address. Addresses are the unique IDs of accounts in our ledger system. When there are enough transactions to make a new block, some of the blockchain participants begin a process of adding a new block to the ledger. Each new block is linked to the previous block, making a chain. That’s where the term blockchain comes from. A blockchain is basically a bunch of blocks where each block is connected to its predecessor.

Then, the entire set of blocks, or the entire blockchain, is shared with other participants. These participants are called nodes. These nodes communicate with one another and each stores an exact copy of the blockchain. Many blockchain networks are made up of thousands of nodes, and keeping all of the copies of the blockchain in sync (that is, ensuring that every copy is the same) is another revolutionary feature of blockchain technology.

Blockchain technology is built on a democracy governance mode. Before any new block is added to the blockchain, a majority of nodes must agree that the new block is valid. All nodes agree to accept the majority decision. That’s how the blockchain stays in sync. Nodes essentially vote on all new blocks. Different blockchains use different voting methods, but one of the more common ones requires nodes to solve very hard mathematical puzzles to earn the right to add a new block to the blockchain. As an incentive for doing the hard work, the node that solves the puzzle first gets a reward. The reward encourages nodes to pitch in and help do the hard work of solving verification puzzles.

Part of the puzzle solution involves creating a mathematical hash of the previous block. By storing the previous block’s hash in the current block, every node can quickly determine if any block has changed. Each node periodically scans the blockchain to ensure that nothing has changed. This is how nodes can be sure that the blockchain is the same across the entire network. And, because no block can change after it is added to the blockchain, you never have to worry about overwriting data.

Putting it all together, a blockchain makes it possible to share a set of data with many nodes that you don’t trust. You can trust the democracy of the network, though. As long as you can trust that more than half of the nodes on the blockchain network are going to be honest, you can trust the blockchain.

The last big advantage to blockchain technology is that you can put rules of operation in blocks on the blockchain as well. These rules are called smart contracts. A smart contract is just a program that lives in a blockchain block and governs how data is added to the blockchain. Because all blockchain data is immutable, even the smart contract code is immune from changes. That’s how you can exchange currency without a bank. As long as there are rules that dictate how a currency exchange is carried out, transaction data can be recorded on the blockchain and be part of the permanent ledger.

For example, suppose you want to buy a car. You have enough digital currency in your blockchain account to buy the car, and the car owner has the car’s title stored in the blockchain. You can offer to buy the car and if the seller accepts your offer, a smart contract handles the transaction. The smart contract would verify that the title is owned by the seller and that you have enough money in your account to make the purchase. If those two requirements are met, the smart contract would transfer the sales amount into the seller’s account and transfer the title to your account. Without any middleman, you have purchased a car and paid for it without carrying a wad of cash around.

Of course, you really purchased a title to a car. Blockchain handles digital assets. You still have to physically get the keys and the car from the seller.

Introducing Ethereum

Bitcoin was the first blockchain technology application. It was revolutionary and defined the first widely used digital currency, called cryptocurrency. The crypto part of the name refers to the use of cryptographic hashes to ensure the integrity of the blockchain. The shared ledger literally keeps a copy of every cryptocurrency transaction that gets verified by all nodes. Using this approach, bitcoin created a permanent record of every exchange of their cryptocurrency. And, because account owners are identified only by an address, bitcoin has always enjoyed a measure of anonymity.

Although bitcoin addresses aren’t linked directly to people, many exchanges have records of identities that are related to addresses. At some point, you have to exchange your cryptocurrency for real currency. That switchover point is where many law enforcement officials focus when they’re trying to track down criminals using cryptocurrency.

As bitcoin became more and more popular, researchers began to see more applications for blockchain technology beyond cryptocurrency. In 2013, Vitalik Buterin, the cofounder of Bitcoin Magazine, published a whitepaper that proposed a new, more functional blockchain implementation. This new proposal was for the Ethereum blockchain. After gaining interest and attracting technical and financial support, the Ethereum Foundation, a Swiss non-profit organization, was founded and became the developer of Ethereum.

Ethereum wasn’t created just to exchange cryptocurrency. In fact, it was designed from the beginning to be different. The core features of Ethereum are the smart contract and ether. Ether is the native cryptocurrency that Ethereum supports, although you can create your own tokens to exchange value in many other forms. Smart contracts provide an execution environment that ensures integrity across all nodes. Any code that executes on one node executes the same way on all nodes. This guarantee makes it possible to deploy a wide range of applications across untrusted environments.

The foundational guarantees Ethereum provides support many types of value exchanges without the concern about fraud, censorship, or any involvement by a third party. When you interact with an Ethereum application, you don’t have to rely on any intermediary to broker your transactions. You don’t need a bank, wholesaler, or transaction broker to provide trust. As a result of Ethereum’s disintermediation, you can often complete transactions faster, with far lower service fees and without requiring approval from external authorities.

Ethereum is a comprehensive, decentralized application platform that expands the range of capabilities beyond what was possible before blockchain technology. Whereas legacy solutions to data and process sharing required third-party authorities to enforce integrity, Ethereum provides process and data integrity, along with disintermediation. The possibilities are just beginning to be explored.

Exploring Ethereum’s Consensus, Mining, and Smart Contracts

Ethereum provides integrity in the way it implements immutability and smart contracts. Immutability isn’t actually a blockchain guarantee. You can change data in any block — even after other blocks are added to the blockchain. However, as soon as you change a block, that block and all subsequent blocks fail integrity checks and your node is out of sync. Instead of saying that the blockchain is immutable, it is more accurate to say that any changes (mutations) to the blockchain are easily and immediately detected.

Ethereum is based on democracy. Each node gets an equal vote. Every time nodes get a new block to add to the blockchain, they validate the block and its transactions, and then vote whether to accept or reject the block. If several different blocks are submitted by different nodes, only one of the blocks can receive votes from a majority. The block that gets more than half of the network node’s votes gets to join the blockchain as its newest block.

One of the first problems is to determine when a new block is ready for the blockchain. When too many conflicting blocks are submitted, the voting process slows down. Ethereum makes it hard to add new blocks to keep the number of new block collisions low and to make voting faster. Ethereum uses a consensus protocol called Proof of Work (PoW), which sets the rules for validating and adding new blocks. PoW makes add blocks to the blockchain difficult but profitable.

Ethereum defines ether as its cryptocurrency. You can transfer ether between accounts or earn it by doing the hard work of adding blocks to the Ethereum blockchain. The Ethereum PoW mechanism requires that nodes find a number that, when combined with the block’s header data, produces a cryptographic hash value that matches the current target, which is a value that is adjusted to keep new block production at a steady rate. Finding a hash value that matches the current target is hard. You have to try on average more than a quadrillion values to find the right one. That’s the point. Using a PoW mechanism makes it so hard to submit a block that fewer blocks are submitted, which reduces the number of collisions. The node that finds the right value gets a small ether payment for the effort. This process is called mining, and the node that wins the prize is that block’s miner.

Mining regulates the speed at which new blocks get submitted as candidate blocks, and results in a number that is easy to validate. Finding the right number to solve the puzzle is difficult, but verifying the number is fast and easy. Another interesting aspect of mining is that each block’s header contains a hash from the previous block. Ethereum nodes use the hash to easily detect unauthorized block changes. If a block changes, the hash result doesn’t match and the block becomes invalid.

Mining is also a way to make money using blockchain technology. Mining has become competitive, and most of today’s miners invest in high-performance hardware with multiple GPUs to carry out the complex operations. To keep the mining process fair, Ethereum uses a complexity value that makes the mining process even harder as miners get faster. Adjusting the complexity allows Ethereum to regulate the new block frequency to an average of one new block every 14 seconds.

The glue that holds the Ethereum environment together is the smart contract. Ethereum is much more than just a financial ledger, and smart contracts provide much of its rich functionality. Each Ethereum node runs a copy of the Ethereum virtual machine (EVM). The EVM runs smart contract code in a way that guarantees that smart contracts execute the same way on all nodes and produce the same output. Running smart contract code is not optional. Smart contracts execute based on specific rules and cannot be subverted or halted. The EVM smart contract guarantees provide a stable platform for automated transaction processing that you can trust. Smart contracts provide the primary power of the Ethereum environment.

One of the known weaknesses with software is that attackers can sometimes bypass its controls and carry out unintended actions. That type of attack is more difficult in Ethereum, primarily due to its smart contract implementation. Attackers can’t directly attack the blockchain and make unauthorized changes because any such changes will be immediately detected. The next most likely attack vector is the smart contract interface to the blockchain data. Ethereum guarantees that smart contract code, which is translated into bytecode before it is written to the blockchain, executes on every EVM instance the same way. Also, the EVM determines when code executes and what code executes. Attackers have few opportunities to leverage smart contract code, which makes Ethereum an even more secure environment.

Buying, Spending, and Trading Ether

Ethereum runs on ether (ETH), its main cryptocurrency. The majority of all existing ether was pre-mined when Ethereum first went live on July 30, 2015. Miners continually create ether, but the amount of mined ether is less than 30 percent of all ether in existence. The lifecycle of Ethereum transactions requires that you first acquire ether to participate in Ethereum. Many exchanges support exchanging legal tender, also called fiat currency, for cryptocurrency, including ether. You can navigate to https://99bitcoins.com/best-ethereum-exchange-review-comparison for an independent comparison of several popular exchanges.

Before you can interact with the Ethereum blockchain, you need to create at least one account. Creating an Ethereum account is essentially just creating a cryptographic private and public key pair, and generating the associated address, which is based on your public key. The software that handles this process is called an Ethereum wallet. You learn about different options for Ethereum wallets in Chapter 6. You can use a wallet provided by an exchange or a standalone wallet. After you create your Ethereum account, you’ll need to select an exchange to purchase ether.

After you select an exchange, you set up an exchange account and provide a funding source. Your main funding source is generally a bank account. The most common way to buy ether is to withdraw funds from your bank account and use that money to exchange for ether. Figure 1-1 shows the purchase ether web page for the coinbase.com exchange. Note that the funding source for this account is a Bank of America account.

FIGURE 1-1: Purchase ether using coinbase.com.

You can also purchase ether using cash. A growing number of cryptocurrency ATMs allow you to exchange cash for different types of cryptocurrency. All you need is the private key you generated using your Ethereum wallet and cash. However, you will pay for this convenience. Cryptocurrency ATMs often use exchange rates that are less favorable than more traditional exchanges. One current service, localcoin ATM, works just like a regular ATM. Navigate to https://localcoinatm.com to see where you can find ATMs and how to use them. Figure 1-2 shows several steps in the process of purchasing ether with cash from an ATM.

FIGURE 1-2: Purchasing ether with cash.

After you own ether, you can interact with other Ethereum accounts and send them some of your ether in exchange for good or services. Or you can simply hold on to your ether in hopes that is goes up in price. Ether, along with other cryptocurrencies, fluctuates in price continuously. Many investors buy and sell cryptocurrencies as investments, just like trading fiat currencies or commodities. Figure 1-3 shows the main coinbase.com dashboard with popular cryptocurrency prices.

FIGURE 1-3: Current cryptocurrency prices.

At its highest price, ether sold for around $1,400. At the time of this writing, it was down near $100. Whether cryptocurrency is a good investment depends on your appetite for risk and belief in its long-term value.

In addition to buying and trading ether, you can spend it just like any other currency. Of course, you generally have to buy from a vendor that accepts ether. Several service providers make it easy to accept payments with ether, such as Pay with Ether. This company provides the software and the services to make it easy for vendors of any size to accept ether as payment. Visit www.paywithether.com/ to find out more about this payment option.

There are ways to spend cryptocurrency at vendors that don’t directly accept it. Several companies are planning to offer Visa cards that you fund with cryptocurrency. One company, Wirex, allows users to convert their cryptocurrency to USD, GPB, or EUR and use their card at any vendor that accepts Visa.

Cryptocurrency is growing rapidly, but only a small number of vendors accept it. If you really want to pay with ether or other cryptocurrencies, take a look at TenX. This company offers a popular Visa card funded by cryptocurrency. The card isn’t available everywhere, but the company expects to increase its availability over time. Navigate to https://tenx.tech/en for more information on TenX and their cryptocurrency payment card.

Getting Started with DAO and ICO

Blockchain technology has given rise to new classes of organizations and opportunities. You’ll often hear about decentralized autonomous organization (DAO) and initial coin offering (ICO). These terms simply describe endeavors that Ethereum makes possible. You’ll read a lot about these terms as you learn more about Ethereum, so it makes sense to cover them here.

A DAO is an organization that operates only on the rules set forth in its smart contracts. In reality, most DAOs require some human interaction, but the majority of the functionality is automated. For example, assume in just a few years that autonomous vehicles (driverless cars) are more common. A DAO would be like a driverless Uber or Lyft car. The car waits for a passenger, and then drives to the pickup location when someone needs a ride. The autonomous car completes the trip and the passenger pays with cryptocurrency. The car just earned some money. However, the car’s maintenance smart contract detects that the brakes need replacing. So the car drives itself to a mechanic and pays for new brakes, using the profits of previous rides. The autonomous vehicle does not need human interaction to carry out its primary business function or to get necessary service. The autonomous vehicle is the same idea as a DAO.

A DAO conducts business and engages in transactions without requiring human interaction. Today’s DAOs are relatively simple, but it is expected that they will grow in complexity and eventually replace (or at least compete with) some existing human-based businesses.

Like all businesses, Ethereum-based or Ethereum-related businesses need funding to operate. Many traditional methods for raising funds exist, including soliciting private investors, securing loans, or selling shares in the company. In addition, Ethereum opens new options for funding businesses.

Businesses that use Ethereum often create their own tokens, also called coins, that represents value associated with the business ventures. Businesses sell these tokens to raise funds to launch the business. These ICOs essentially exchange one type of currency for a digital item of value. Tokens may represent an expected future value as ownership in a new venture or current value that entitles the holder to some benefit. Either way, tokens are similar in some ways to stock shares. An ICO is a popular method to fund a new blockchain-based business. If you want to learn more about the most popular ICOs, navigate to www.coindesk.com/ico-tracker to explore coindesk’s ICO Tracker, shown in Figure 1-4.

FIGURE 1-4: coindesk ICO Tracker.

Exploring the Ethereum Ecosystem

The Ethereum environment, or ecosystem, is made up of several different parts. You’ve already learned about most of these pieces, but it helps to put those pieces together in one place. Starting from the lowest level of the blockchain, Ethereum is made up of the following components:

Blockchain:

The collection of data blocks that is the core of Ethereum. Each block contains data and smart contract code, and is cryptographically linked to its predecessor, creating a chain of blocks.

EVM:

The Ethereum virtual machine, which runs smart contract bytecode. Each Ethereum node runs an instance of the EVM.

Wallet:

Software, hardware, or physical paper that stores the public and private keys that correspond to an Ethereum account. The wallet stores the capability to access crypto-assets on the Ethereum blockchain.

Exchange:

A service the allows its users to exchange fiat currency for cryptocurrency.

Development environment:

The set of tools to write, compile, and perform unit tests on smart contract software.

Testing environment:

A simulated Ethereum blockchain used to perform integration testing on smart contracts and complete decentralized applications (dApps).

Client interface:

The client user interface’s software and libraries used to interact with Ethereum smart contracts.

You learn much more about the details of each of these components in Chapter 4.

Delving into Development Tools

Developing decentralized applications (dApps) for Ethereum requires several types of tools. Each of these tools provides support for various phases of software development and is necessary to create dApps for the Ethereum blockchain environment. In Chapter 4, you find out the different categories of development tools and learn about several alternatives for each type of tool.

Tools that you’ll use when developing Ethereum dApps are in the following categories:

Blockchain client:

When developing Ethereum dApps, you’ll need to implement a local EVM. A blockchain client launches a local EVM and executes your smart contract code. It also interacts with your Ethereum blockchain.

Development and testing blockchain:

Deploying to the live Ethereum blockchain, also called

mainnet,

is the last step in the development process. Before deployment, you want to interact with a local version of an Ethereum blockchain. Because live blockchain access costs ether, you should carry out development and testing on a local blockchain to avoid costs and errors.

Compiler and testing framework:

After you have a local EVM and local blockchain, you’ll need a way to interact with your smart contract code and place it on your test blockchain for test execution. A development and testing framework provides the tools you need to carry out development and testing tasks.

Source code editor/IDE:

Although you can use any text editor to write smart contract source code, an editor or integrated development environment (IDE) that is designed or extended to support Ethereum smart contract source code development will be very helpful. IDEs can increase developer efficiency and make it easier to create good smart contract code.

As you work through the exercises in this book, you’ll learn more about each of these tools and install an example from each category.

Building Blockchain Apps

The process of building blockchain applications is not radically different from developing traditional applications. You have a few additional considerations and a few additional steps. As you work through the chapters in this book, you’ll learn each of the tasks required to develop effective and efficient blockchain applications for the Ethereum environment.

The main differences between traditional applications and blockchain applications is the distributed, transparent nature of the data and the fact that writing data to the blockchain costs money. Distributed and transparent data means that you can’t rely on the blockchain to provide any confidentiality. Anything you write to the blockchain is visible by users on any node. That should affect how you design your applications and data. Be careful when collecting data from users and storing it on the blockchain. Always assume that any blockchain data is available to the public.

The other main difference is that writing to the blockchain costs money. The development and testing processes normally occur with simulated blockchains that use only fake cryptocurrency, but live blockchain I/O has a real cost. Most developers aren’t used to calculating computation and access costs. Because this is generally a new concept, many developers may put this consideration off until later in the development cycle. This decision is a mistake. It is always easier and cheaper to address blockchain access cost problems early in the development process. If you wait until the end, any changes will likely have cascading effects and costs.

As with any good development practices, do everything you can to fully understand what your users want and need. Design your software with the users in mind and always cater to their needs first. Then make you software meet their needs in ways that are the most effect and economical. Stick with good software design and development principles, while incorporating blockchain-specific considerations, and you’ll be on your way to developing a good blockchain dApp.

Chapter 2

Learning about Blockchain

IN THIS CHAPTER

Understanding distributed applications

Examining Bitcoin’s solution to the distributed dilemma

Building blockchains

Contrasting blockchains and databases

Describing ways to use blockchain

Blockchain technology is basically a distributed ledger that is shared between lots of computers and can run verifiable software to control how data is added. Blockchain technology depends on the capability to distribute data and software to many computers, using a technique called distributed processing. Distributed processing is the practice of spreading applications across multiple computers, and is a different way of looking at where data is stored and where application code is run from the more traditional centralized model.