Building Ethereum Dapps
Decentralized applications on the Ethereum blockchain
Roberto Infante
Foreword by Thomas Bertani
  • March 2019
  • ISBN 9781617295157
  • 504 pages
  • printed in black & white

Blockchain is about interoperability, and Roberto understands this innately. He arms you with the tools of experts while keeping you aware of the bigger picture.

From the Foreword by Thomas Bertani, CEO of Oraclize

Building Ethereum Dapps introduces you to decentralized applications based on the Ethereum blockchain platform. In this book, you'll learn the principles of Dapps development by rolling up your sleeves and actually building a few!

About the Technology

Imagine unbreakably secure applications that handle personal and business transactions without any central agency controlling the process. Decentralized applications, or Dapps, do just this, shifting power to users. The Ethereum blockchain platform provides the tools you need to build Dapps, including an innovative “smart contracts” model and Solidity, a Dapp-aware JavaScript-like programming language.

About the book

Building Ethereum Dapps teaches Dapps development on the Ethereum blockchain platform. You’ll begin with a mental model of how Dapps operate, and then dive into designing and implementing smart contracts in Ethereum’s Solidity language. You’ll explore Ethereum smart contract development tools, like Truffle and Web3, and pick up best practices for design and security. Practical exercises throughout give you valuable hands-on experience.

Table of Contents detailed table of contents

Part 1

1 A first look at decentralized applications

1.1 What is a Dapp?

1.1.1 Dapps vs conventional centralized applications

1.1.2 Structural view: anatomy of a Dapp

1.1.3 Transactional view: through the lifecycle of a transaction

1.1.4 Let’s get familiar with some Dapp terminology

1.2 Good and bad Dapps

1.2.1 Good use cases

1.2.2 Pointless Dapps

1.3 A five-minute Dapp implementation

1.3.1 Let’s start building SimpleCoin, a basic cryptocurrency

1.3.2 Let’s run the contract

1.3.3 Let’s interact with the contract


2 Understanding the blockchain

2.1 A deeper look at decentralized applications

2.1.1 Stepping into an Ethereum node

2.1.2 Revisiting the lifecycle of a transaction

2.1.3 Development view: deploying the voting smart contract

2.2 What technologies make Dapps viable?

2.2.1 Blockchain technologies

2.2.2 Ethereum technologies

2.3 Ethereum’s history and governance

2.3.1 Who created Ethereum?

2.3.2 Who controls Ethereum’s development?


3 The Ethereum platform

3.1 Connecting to Ethereum through the wallet

3.1.1 Getting started with the Ethereum wallet

3.1.2 Performing common operations with the wallet

3.2 Smart contracts: the brain of Dapps

3.2.1 Accounts

3.2.2 Ether

3.2.3 Gas

3.2.4 Calls and transactions

3.2.5 The Ethereum Virtual Machine

3.3 Connecting to Ethereum with geth

3.3.1 Getting started with geth

3.3.2 A first look at the geth interactive console

3.3.3 A first look at JSON-RPC

3.3.4 Mining with geth console

3.3.5 Other clients

3.4 Managing accounts with geth

3.4.1 Ethereum accounts

3.4.2 Managing accounts with the geth command

3.4.3 Managing accounts with Web3 on the geth console

3.4.4 Managing accounts with JSON-RPC

3.5 Revisiting SimpleCoin’s contract

3.5.1 Improving SimpleCoin’s contract

3.5.2 Trying out the amended code


4 Deploying your first smart contract

4.1 Deploying a contract onto the network

4.1.1 Ethereum public networks

4.1.2 Deploying SimpleCoin with the Ethereum Wallet

4.2 Interacting with the contract

4.2.1 Checking coin balances

4.2.2 Transferring coins

4.3 Nodeless deployment through Metamask

4.3.1 Installing metamask

4.3.2 Deploying SimpleCoin through Metamask

4.3.3 Interacting with SimpleCoin through Metamask


Part 2

5 Programming smart contracts in Solidity

5.1 EVM contract languages

5.1.1 LLL

5.1.2 Serpent and Viper

5.2 High-level contract structure

5.2.1 Contract declarations

5.3 Solidity language essentials

5.3.1 Value types

5.3.2 Reference types

5.3.3 Global namespace

5.3.4 State variables

5.3.5 Functions

5.3.6 Function modifiers

5.3.7 Variable declaration, initialization and assignment

5.3.8 Events

5.3.9 Conditional statements

5.4 Time to improve and refactor SimpleCoin

5.4.1 Implementing an allowance facility

5.4.2 Restricting operations only to the contract owner


6 Writing more complex smart contracts

6.1 Introducing SimpleCrowdsale, a crowdsale contract

6.1.1 State variables

6.1.2 Constructor

6.1.3 Implementing invest()

6.1.4 Implementing finalize()

6.1.5 Small detour: introducing inheritance

6.1.6 Implementing finalize() - take 2

6.1.7 Implementing refund()

6.1.8 Eliminating code duplication with inheritance

6.1.9 Running SimpleCrowdsale

6.2 Extending functionality with inheritance

6.2.1 Implementing a new token pricing contract with inheritance

6.2.2 Composing functionality with multiple inheritance


7 Generalizing functionality with abstract contracts and interfaces

7.1 Making a contract abstract

7.1.1 Implementing funding limit with inheritance

7.1.2 Generalizing funding limit strategy with an abstract contract

7.1.3 Improving also the token pricing strategy with an abstract contract

7.1.4 Reimplementing capped crowdsales with no duplication

7.2 Allowing multiple contract implementations with interfaces

7.2.1 Setting functional requirements with interfaces

7.2.2 Referencing a contract through an interface

7.3 Real-world crowdsale contracts

7.4 Recap on Solidity’s object-oriented features

7.4.1 Inheritance

7.4.2 Abstract contracts

7.4.3 Interfaces

7.5 Libraries

7.5.1 Library function invocation

7.5.2 Deployed libraries

7.5.3 Library function execution

7.6 Making SimpleCoin ERC20 compliant


8 Managing smart contracts with Web3.js

8.1 Revisiting deployment through geth’s interactive console

8.1.1 Contract build and deployment process

8.1.2 Deploying SimpleCoin through geth’s console

8.2 Interacting with SimpleCoin through geth’s console

8.2.1 Checking coin balances

8.2.2 Transferring coins

8.2.3 Referencing a running contract

8.3 Simplifying command-based deployment with nodejs

8.3.1 Installing Web3 and solc on node.js

8.3.2 Building and deploying interactively through the node.js console

8.3.3 Creating a build and deployment script

8.3.4 Interacting with a contract from node.js.

8.4 Deploying on a private network

8.4.1 How geth accesses the blockchain

8.4.2 Setting up a private test network

8.4.3 Deploying SimpleCoin on the private network

8.5 Making development more efficient by deploying on mock networks

8.5.1 Installing and starting up TestRPC

8.5.2 Deploying SimpleCoin on TestRPC

8.6 Smoother interaction with SimpleCoin through a web UI

8.6.1 Building a minimalistic web UI for SimpleCoin

8.6.2 Running the SimpleCoin web UI


Part 3

9 The Ethereum ecosystem

9.1 The core components

9.2 A bird eye view of the full ecosystem

9.3 Decentralized address resolution with ENS

9.3.1 ENS design

9.3.2 Registering a domain name

9.3.3 Resolving a domain name

9.4 Decentralized content storage

9.4.1 Swarm overview

9.4.2 Uploading and downloading content to and from Swarm

9.4.3 IPFS overview

9.4.4 Swarm vs IPFS

9.5 Accessing external data through oracles

9.5.1 Feeding oracles

9.5.2 Building a data-aware contract with Oraclize

9.5.3 Running the data-aware contract

9.6 Dapp frameworks and IDEs

9.6.1 Development IDEs

9.6.2 Development frameworks

9.6.3 Testing frameworks

9.6.4 Web UI frameworks


10 Unit testing contracts with Mocha

10.1 Installing mocha

10.2 Setting up SimpleCoin in mocha

10.3 Writing unit tests for SimpleCoin

10.3.1 The testing plan

10.3.2 Unit testing the constructor

10.3.3 Testing only authorized callers can invoke a function

10.3.4 Testing input constraints are met

10.3.5 Testing invocation from authorized account with valid input

10.3.6 A little challenge

10.3.7 The full testing suite


11 Improving the development cycle with truffle

11.1 Setting up Truffle

11.2 Moving SimpleCoin under Truffle

11.2.1 Setting up SimpleCoin in Truffle

11.2.2 Compiling SimpleCoin

11.2.3 Deploying SimpleCoin onto a mock network client through migrations

11.2.4 Deploying SimpleCoin onto a public test or production network

11.2.5 Testing SimpleCoin

11.2.6 Writing Solidity tests

11.2.7 Writing JavaScript tests


12 Putting it all together: building a complete voting Dapp

12.1 Defining the requirements of a voting Dapp

12.2 The development plan

12.3 Starting the truffle project

12.4 Implementing the voting contract

12.4.1 Modelling proposal, voter and workflow

12.4.2 Contract state

12.4.3 Function modifiers

12.4.4 Events

12.4.5 Constructor

12.4.6 Functions

12.4.7 The full voting contract

12.5 Compiling and deploying SimpleVoting

12.6 Writing unit tests

12.7 Creating a web UI

12.7.1 Preparing the UI dependencies

12.7.2 Setting up a minimalistic web server with node.js

12.7.3 Writing the admin page HTML

12.7.4 Writing the admin page JavaScript

12.7.5 Writing the voter page HTML

12.7.6 Writing the voter page Javascript

12.7.7 Running the admin and voter web pages

12.7.8 Deploying to the public network

12.8 Food for thought

12.8.1 Possible technical improvements

12.8.2 Possible functional improvements


Part 4

13 Making a Dapp production ready

13.1 Event logging

13.1.1 Retrieving past events

13.1.2 Event indexing

13.2 Designing an upgradeable library

13.3 Designing an upgradable contract

13.3.1 Connecting to the upgraded contract through a proxy

13.3.2 Inheriting from an abstract Upgradable contract


14 Security considerations

14.1 Understanding general security weak spots

14.1.1 Private information

14.1.2 Randomness

14.1.3 Calling view functions

14.1.4 Gas limits

14.2 Understanding risks associated with external calls

14.2.1 Understanding external call execution types

14.2.2 What external function can be called?

14.2.3 Is an exception thrown in case of failure of the external call?

14.2.4 In which context is the external call executed?

14.2.5 What’s the msg object received?

14.2.6 What’s the gas limit?

14.3 How to perform external calls more safely

14.3.1 Implementing pull payments

14.3.2 Implementing a minimal fallback function

14.3.3 Beware of ether coming to you through selfdestruct ()

14.4 Avoiding known security attacks

14.4.1 Reentrancy

14.4.2 Cross-function race conditions

14.4.3 Front-running attacks

14.4.4 Denial of Service based on revert() in fallback

14.4.5 Denial of Service based on gas limits

14.5 General security guidelines


15 Conclusions

15.1 Evolution of Ethereum

15.1.1 Evolution of EVM

15.1.2 Evolution of Solidity

15.1.3 Evolution of Web3.js

15.1.4 Evolution of the consensus algorithm

15.1.5 Evolution of the ecosystem

15.2 Alternative Ethereum implementations

15.2.1 Enterprise Ethereum Alliance

15.2.2 Quorum

15.3 Beyond the Ethereum blockchain

15.3.1 Hyperledger

15.3.2 Corda



Appendix A: SimpleCoin inherited from Ownable

Appendix B: Full SimpleCrowdsale application

Appendix C: SimpleCoin Mocha unite testing suite

Appendix D: SimpleVoting contract

What's inside

  • Ethereum’s key components
  • Implementing smart contracts in Solidity
  • Communicating with a smart contract in Web3
  • Developing Dapps with Truffle
  • Best practices for design and security improvement

About the reader

For developers with intermediate experience in JavaScript or an OO language. Familiarity with blockchain concepts is helpful.

About the author

Roberto Infante is a software development consultant who specializes in finance. He currently works on financial risk management systems and on blockchain technology.

We interviewed Roberto as a part of our Six Questions series. Check it out here.

placing your order...

Don't refresh or navigate away from the page.
print book $23.99 $39.99 pBook + eBook + liveBook
Additional shipping charges may apply
Building Ethereum Dapps (print book) added to cart
continue shopping
go to cart

eBook $25.59 $31.99 3 formats + liveBook
Building Ethereum Dapps (eBook) added to cart
continue shopping
go to cart

Prices displayed in rupees will be charged in USD when you check out.
customers also reading

This book 1-hop 2-hops 3-hops

FREE domestic shipping on three or more pBooks