Building Blockchain Projects

Develop real-time practical DApps using Ethereum and JavaScript

Narayan Prusty

e-books shop
e-books shop
Purchase Now !
Just with Paypal

Book Details
 2.00 USD
 259 p
 File Size
 4,674 KB
 File Type
 PDF format
 2017 Packt Publishing 

About the Author
Narayan Prusty is a full-stack developer, with five years of experience in the field. He
specializes in Blockchain and JavaScript. His commitment has led him to build scalable
products for startups, the government, and enterprises across India, Singapore, USA, and UAE.

At present, Ethereum, Bitcoin, Hyperledger, IPFS, Ripple, and so on are some of the things
he uses on a regular basis to build decentralized applications. Currently, he is a full-time
Blockchain SME (Subject-Matter Expert) at Emirates National Bank of Dubai.

He has already written two books on JavaScript titled Learning ECMAScript 6 and Modern
JavaScript Applications. Both these books were reviewed and published by Packt.
He starts working on something immediately if he feels it’s exciting and solves real work
problems. He built an MP3 search engine at the age of 18, and since then, he has built
various other applications, which are used by people around the globe. His ability to to
build scalable applications from top to bottom is what makes him special.

Currently, he is on a mission to make things easier, faster, and cheaper using the blockchain
technology. Also, he is looking at possibilities to prevent corruptions, fraud, and to bring
transparency to the world using blockchain technology.
You can learn more from him from his blog h t t p ://q n i m a t e . c o m and you can reach him
out at LinkedIn h t t p s ://w w w . l i n k e d i n . c o m /i n /n a r a y a n p r u s t y /.

About the Reviewers
Imran Bashir has an M.Sc. degree in Information Security from Royal Holloway, University
of London, and has a background in software development, solution architecture,
infrastructure management, and IT service management. He is also a member of the
Institute of Electrical and Electronics Engineers (IEEE) and the British Computer Society
(BCS). Imran has sixteen years of experience in public and financial sector. He had worked
on large-scale IT projects for the public sector before moving to the financial services
industry. Since then, he worked in various technical roles for different financial companies
in Europe’s financial capital, London. He is currently working for an investment bank in
London as Vice President in the technology department.

Daniel Kraft has studied mathematics and physics and holds a PhD degree in applied
mathematics from the University of Graz in Austria. He has been involved in development
with cryptocurrencies since 2013, has been the lead developer and chief scientist for both
Namecoin and Huntercoin since 2014, and has published two research papers about
cryptocurrency in peer-reviewed journals. He works as a software engineer and is a
cofounder of Crypto Realities Ltd, a start-up that works on building decentralized
multiplayer game worlds with blockchain technology.

Gaurang Torvekar has a master's degree in Information Systems from Singapore
Management University. He is the cofounder and CTO of Attores, a Smart Contracts as a
Service company, based in Singapore. He has extensive experience in Ethereum and
Hyperledger application development. He has been a speaker at several blockchain
conferences, conducted many hands on blockchain courses in Polytechnics in Singapore,
and is also a Blockchain mentor at Angelhack.

Table of Contents
Preface 1
Chapter 1: Understanding Decentralized Applications
What is a DApp? 7
Advantages of decentralized applications 8
Disadvantages of decentralized applications 8
Decentralized autonomous organization 9
User identity in DApps 9
User accounts in DApps 11
Accessing the centralized apps 11
Internal currency in DApps 12
Disadvantages of internal currency in DApps 13
What are permissioned DApps? 13
Popular DApps 13
Bitcoin 14
What is a ledger? 14
What is blockchain? 14
Is Bitcoin legal? 15
Why would someone use Bitcoin? 15
Ethereum 15
The Hyperledger project 16
How does it work? 17
Filecoin 17
Namecoin 18
.bit domains 18
Dash 19
Decentralized governance and budgeting 20
Decentralized service 20
BigChainDB 21
OpenBazaar 21
Ripple 22
Summary 23
Chapter 2: Understanding How Ethereum Works 
Overview of Ethereum 25
Ethereum accounts 25
Transactions 26
Consensus 26
Timestamp 28
Nonce 28
Block time 29
Forking 32
Genesis block 32
Ether denominations 33
Ethereum virtual machine 33
Gas 34
Peer discovery 35
Whisper and Swarm 35
Geth 36
Installing geth 36
OS X 37
Ubuntu 37
Windows 37
JSON-RPC and JavaScript console 37
Sub-commands and options 38
Connecting to the mainnet network 38
Creating a private network 38
Creating accounts 38
Mining 39
Fast synchronization 39
Ethereum Wallet 40
Mist 41
Weaknesses 43
Sybil attack 43
51% attack 43
Serenity 43
Payment and state channels 44
Proof-of-stake and casper 44
Sharding 45
Summary 45
Chapter 3: Writing Smart Contracts
Solidity source files 46
The structure of a smart contract 47
Data location 48
What are the different data types? 49
Arrays 50
Strings 51
Structs 52
Enums 52
Mappings 53
The delete operator 54
Conversion between elementary types 55
Using var 56
Control structures 56
Creating contracts using the new operator 57
Exceptions 58
External function calls 58
Features of contracts 59
Visibility 60
Function modifiers 62
The fallback function 64
Inheritance 64
The super keyword 66
Abstract contracts 67
Libraries 67
Using for 69
Returning multiple values 70
Importing other Solidity source files 71
Globally available variables 71
Block and transaction properties 71
Address type related 72
Contract related 72
Ether units 72
Proof of existence, integrity, and ownership contract 73
Compiling and deploying contracts 74
Summary 76
Chapter 4:  Getting Started with web3.js,
Introduction to web3.js 77
Importing web3.js 78
Connecting to nodes 78
The API structure 79
BigNumber.js 80
Unit conversion 80
Retrieving gas price, balance, and transaction details 81
Sending ether 83
Working with contracts 84
Retrieving and listening to contract events 86
Building a client for an ownership contract 89
The project structure 90
Building the backend 91
Building the frontend 93
Testing the client 98
Summary 101
Chapter 5: Building a Wallet Service
Difference between online and offline wallets 102
hooked-web3-provider and ethereumjs-tx libraries 103
What is a hierarchical deterministic wallet? 107
Introduction to key derivation functions 107
Introduction to LightWallet 108
HD derivation path 109
Building a wallet service 110
Prerequisites 110
Project structure 110
Building the backend 111
Building the frontend 111
Testing 119
Summary 124
Chapter 6: Building a Smart Contract Deployment Platform
Calculating a transaction's nonce 125
Introducing solcjs 127
Installing solcjs 127
solcjs APIs 128
Using a different compiler version 129
Linking libraries 130
Updating the ABI 131
Building a contract deployment platform 131
The project structure 132
Building the backend 132
Building the frontend 138
Testing 143
Summary 144
Chapter 7: Building a Betting App
Introduction to Oraclize 145
How does it work? 146
Data sources 146
Proof of authenticity 147
Pricing 149
Getting started with the Oraclize API 149
Setting the proof type and storage location 150
Sending queries 150
Scheduling queries 151
Custom gas 151
Callback functions 152
Parsing helpers 153
Getting the query price 154
Encrypting queries 154
Decrypting the data source 155
Oraclize web IDE 155
Working with strings 156
Building the betting contract 158
Building a client for the betting contract 161
Projecting the structure 161
Building the backend 162
Building the frontend 164
Testing the client 173
Summary 179
Chapter 8: Building Enterprise Level Smart Contracts
Exploring ethereumjs-testrpc 181
Installation and usage 181
The testrpc command-line application 181
Using ethereumjs-testrpc as a web3 provider or as an HTTP server 183
Available RPC methods 184
What are event topics? 185
Getting started with truffle-contract 187
Installing and importing truffle-contract 188
Setting up a testing environment 189
The truffle-contract API 190
The contract abstraction API 190
Creating contract instances 195
The contract instance API 197
Introduction to truffle 198
Installing truffle 198
Initializing truffle 198
Compiling contracts 200
Configuration files 201
Deploying contracts 202
Migration files 202
Writing migrations 203
Unit testing contracts 205
Writing tests in JavaScript 206
Writing tests in Solidity 208
How to send ether to a test contract 211
Running tests 212
Package management 212
Package management via NPM 213
Package management via EthPM 213
Using contracts of packages within your contracts 214
Using artifacts of packages within your JavaScript code 215
Accessing a package's contracts deployed addresses in Solidity 215
Using truffle's console 216
Running external scripts in truffle's context 217
Truffle's build pipeline 217
Running an external command 218
Running a custom function 218
Truffle's default builder 219
Building a client 221
Truffle's server 225
Summary 227
Chapter 9: Building a Consortium Blockchain
What is a consortium blockchain? 229
What is Proof-of-Authority consensus? 229
Introduction to parity 230
Understanding how Aura works 230
Getting parity running 232
Installing rust 232
Linux 232
OS X 232
Windows 232
Downloading, installing and running parity 233
Creating a private network 233
Creating accounts 233
Creating a specification file 234
Launching nodes 237
Connecting nodes 238
Permissioning and privacy 239
Summary 240
Index 241

e-books shop

Blockchain is a decentralized ledger that maintains a continuously growing list of data
records secured from tampering and revision. Every user is allowed to connect to the
network, send new transactions to it, verify transactions, and create new blocks.

This book will teach you what Blockchain is, how it maintains data integrity, and how to
create real-world Blockchain projects using Ethereum. With interesting real-world projects,
you will know learn how to write smart contracts which run exactly as programmed
without any chance of fraud, censorship or third-party interference, and build end-to-end
applications for Blockchain. You will learn concepts such as cryptography in
cryptocurrencies, ether security, mining, smart contracts, and solidity.

The blockchain is the main technical innovation of bitcoin, where it serves as the public
ledger for bitcoin transactions.

What this book covers
Chapter 1, Understanding Decentralized Applications, will explain what DApps are and
provide an an overview of how they work.
Chapter 2, Understanding How Ethereum Works, explains how Ethereum works.
Chapter 3, Writing Smart Contracts, shows how to write smart contracts and use geth's
interactive console to deploy and broadcast transactions using web3.js.
Chapter 4, Getting Started with web3.js, introduces web3js and how to import, connect to
geth, and explains use it in Node.js or client-side JavaScript.
Chapter 5, Building a Wallet Service, explains how to build a wallet service that users can
create and manage Ethereum Wallets easily, even offline. We will specifically use the
LightWallet library to achieve this.
Chapter 6, Building a Smart Contract Deployment Platform, shows how to compile smart
contracts using web3.js and deploy it using web3.js and EthereumJS.
Chapter 7, Building a Betting App, explains how to use Oraclize to make HTTP requests
from Ethereum smart contracts to access data from World Wide Web. We will also learn
how to access files stored in IPFS, use the strings library to work with strings, and more.
Chapter 8, Building Enterprise Level Smart Contracts, explains how to use Truffle, which
makes it easy to build enterprise-level DApps. We will learn about Truffle by building an alt-coin.
Chapter 9, Building a Consortium Blockchain, we will discuss consortium blockchain.

What you need for this book
You require Windows 7 SP1+, 8, 10 or Mac OS X 10.8+.

Who this book is for
This book is for JavaScript developers who now want to create tamper-proof data (and
transaction) applications using Blockchain and Ethereum. Those who are interested in
cryptocurrencies and the logic and database empowering it will find this book extremely useful.
Loading... Protection Status