Blockchain Developer's Guide

Book description

Build real-world projects like a smart contract deployment platform, betting apps, wallet services, and much more using blockchain

Key Features

  • Apply blockchain principles and features for making your life and business better
  • Understand Ethereum for smart contracts and DApp deployment
  • Tackle current and future challenges and problems relating to blockchain

Book Description

Blockchain applications provide a single-shared ledger to eliminate trust issues involving multiple stakeholders. It is the main technical innovation of Bitcoin, where it serves as the public ledger for Bitcoin transactions.

Blockchain Developer's Guide takes you through the electrifying world of blockchain technology. It begins with the basic design of a blockchain and elaborates concepts, such as Initial Coin Offerings (ICOs), tokens, smart contracts, and other related terminologies. You will then explore the components of Ethereum, such as Ether tokens, transactions, and smart contracts that you need to build simple DApps.

Blockchain Developer's Guide also explains why you must specifically use Solidity for Ethereum-based projects and lets you explore different blockchains with easy-to-follow examples. You will learn a wide range of concepts - beginning with cryptography in cryptocurrencies and including ether security, mining, and smart contracts. You will learn how to use web sockets and various API services for Ethereum.

By the end of this Learning Path, you will be able to build efficient decentralized applications.

This Learning Path includes content from the following Packt products:

  • Blockchain Quick Reference by Brenn Hill, Samanyu Chopra, Paul Valencourt
  • Building Blockchain Projects by Narayan Prusty
    • What you will learn

      • Understand how various components of the blockchain architecture work
      • Get familiar with cryptography and the mechanics behind blockchain
      • Apply consensus protocol to determine the business sustainability
      • Understand what ICOs and crypto-mining are, and how they work

      Who this book is for

      Blockchain Developer's Guide is for you if you want to get to grips with the blockchain technology and develop your own distributed applications. It is also designed for those who want to polish their existing knowledge regarding the various pillars of the blockchain ecosystem. Prior exposure to an object-oriented programming language such as JavaScript is needed.

      Downloading the example code for this book You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Publisher resources

View/Submit Errata

Table of contents

  1. Title Page
  2. Copyright
    1. Blockchain Developer's Guide
  3. About Packt
    1. Why subscribe?
    2. Packt.com
  4. Contributors
    1. About the authors
    2. Packt is searching for authors like you
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Conventions used
    4. Get in touch
      1. Reviews
  6. Blockchain 101
    1. Processing a financial transaction
    2. Ledger
    3. Concept of a trustless system
    4. Introducing blockchain
      1. General elements of blockchain
        1. Peer-to-peer network
        2. Block
        3. Block header
        4. Addresses
        5. Wallets
        6. Transaction
        7. Nodes
      2. What does blockchain solve?
      3. Types of blockchains
        1. Public blockchain
        2. Semi-private blockchain
        3. Private blockchain
        4. Consortium blockchain
      4. Byzantine generals problem
      5. Consensus
      6. Blockchain in a nutshell
        1. Benefits
          1. Banking records
          2. Medical records
          3. Government records
          4. Creative and copyright records
          5. University degree records
        2. Challenges
          1. Complexity
          2. Network scalability
          3. Speed and cost
          4. Double spending 
    5. Summary
  7. Components and Structure of Blockchain
    1. Blocks
    2. The chain between blocks
    3. Hashing and signatures
    4. Digital signatures
      1. What are digital keys?
    5. Example block data
      1. Example Ethereum block
      2. Bitcoin block
      3. Global state
      4. Block time and block size
    6. Blockchain miners
    7. Blockchain validators
    8. Smart contracts
    9. Blockchain speed
      1. How to calculate blockchain throughput
      2. Comparisons with traditional networks
    10. Summary
  8. Decentralization Versus Distributed Systems
    1. Distributed systems
      1. Resiliency
        1. Fault tolerance and failure isolation
    2. Consensus and coordination
    3. Backups
      1. Consistency
      2. Peer-to-peer systems
      3. Decentralized systems
      4. Principles of decentralized systems
        1. Open access
        2. Non-hierarchical
        3. Ecosystem diversity
        4. Transparency
        5. Downsides
          1. Speed
          2. Censorship resistance
          3. Chaos and non-determinism
    4. Summary
  9. Cryptography and Mechanics Behind Blockchain
    1. Principles of security
    2. Historical perspective – classical cryptography
    3. Types of cryptography
      1. Symmetric cryptography
      2. Asymmetric (public-key) cryptography
      3. Signatures
      4. Hashing
        1. The avalanche effect
        2. Collisions
        3. Hashing a block
        4. Hashing outside PoW
    4. Summary
  10. Bitcoin
    1. The history of Bitcoin
    2. Why Bitcoin is volatile
    3. Keys and addresses
      1. Currency units
      2. Vanity addresses
      3. Base58 check encoding
    4. Transactions
      1. Types
        1. Pay-to-Public-Key Hash
        2. Pay-to-Script Hash
    5. Blocks
      1. Genesis block
    6. Bitcoin network
      1. Types of nodes
        1. Full node
        2. Lightweight nodes
        3. Other nodes
      2. Network discovery
        1. Finding peers
          1. DNS seeds
          2. Static IPs
    7. Wallets
      1. Types
        1. Deterministic wallet
          1.  Deterministic wallets
          2. HD wallets
        2. Non-deterministic wallet
    8. Summary
  11. Altcoins
    1. Introducing Altcoins
      1. Tokens
        1. Ethereum
        2. Omni Layer
        3. NEO
        4. Waves
        5. Counterparty
    2. Alternative currency
      1. Monetary alternatives
      2. Consensus alternatives
      3. Litecoin
      4. Ether
      5. Ripple
      6. Bitcoin Cash
    3. Acquiring cryptocurrency 
      1. Mining of cryptocurrency
        1. Bitcoin mining
          1. Mining difficulty
          2. Mining pools
        2. Altcoin mining
      2. Cryptocurrency exchanges
      3. Cryptocurrency wallets
    4. Summary
  12. Achieving Consensus
    1. Practical Byzantine fault tolerance algorithm 
      1. Byzantine faults
      2. How PBFT works
    2. Proof of Work
      1. How the PoW problem works in Bitcoin
    3. Proof of Stake
      1. The nothing-at-stake attack
      2. Variations
        1. Delegated Proof of Stake
      3. Tendermint consensus
    4. Proof of Authority
      1. Establishing authority
    5. Proof of Elapsed time
    6. Summary
    7. References
  13. Advanced Blockchain Concepts
    1. Blockchain and banks
      1. Unbanked – going pure crypto
        1. Fixing pegs
        2. Buying options
        3. Why regulated exchanges?
        4. Unbanked and unincorporated?
        5. The DAO
        6. Decentralizing an organization
        7. Putting a corporation on a blockchain
        8. Cutting out the middle man
        9. Providing capital
      2. Social purpose – blockchain as leveler
        1. Banking the unbanked
      3. Silk road LLC – privacy and ethics
      4. Tracking all the things
      5. Defeating some privacy issues with zero-knowledge proofs
      6. Unwrapping the concept of zero-knowledge proofs
    2. Summary
  14. Cryptocurrency Wallets
    1. Introduction to cryptocurrency wallets
      1. Transactions in cryptocurrency wallets
      2. Types of cryptocurrency wallets
        1. Currency support
        2. Tenancy 
          1. Software wallets
          2. Hardware wallets
          3. Paper wallets
          4. Brain wallet
        3. Usage frequency
        4. Key derivation
          1. Non-deterministic wallet
          2. Deterministic wallets
          3. Hierarchical deterministic wallets
          4. Mnemonic codes
          5. Key generation process in HD wallets
          6. Child key derivation 
          7. Private key generation
          8. Extended keys 
    2. Summary
  15. Alternate Blockchains
    1. Various uses of blockchain
      1. Government
      2. Healthcare
      3. Medical research
      4. Supply chain
      5. Copyright
      6. Fine art
      7. Shipping
      8. Energy
      9. Computation and data storage
      10. Identification and social security
      11. Enterprise
    2. Ripple
      1. Transactions
    3. Stellar 
    4. Tendermint
    5. Monax
    6. Summary
  16. Hyperledger and Enterprise Blockchains
    1. History of Hyperledger
    2. Hyperledger projects
      1. Hyperledger Burrow
      2. Hyperledger Sawtooth
        1. Sawtooth architecture
          1. Transaction families
          2. Transactions and batches
          3. The key pieces
      3. Hyperledger Fabric
        1. Architecture choices and features
          1. Organizational focus
          2. Private channels
          3. Assets
          4. Smart contracts
        2. Advantages of Fabric
      4. Hyperledger Iroha
      5. Hyperledger Indy
    3. Tools in Hyperledger
      1. Hyperledger Caliper
      2. Hyperledger Composer
      3. Hyperledger Cello
      4. Hyperledger Explorer
      5. Hyperledger Quilt
      6. Relationships between the tools
      7. Which Hyperledger project should you use?
      8. Using Hyperledger
    4. Summary
  17. Ethereum 101
    1. Introducing Ethereum
    2. Components of Ethereum
      1. Ethereum accounts
      2. Ethereum network
        1. Ethereum public MainNet
      3. Ethereum clients
        1. Geth
          1. Installing Geth
          2. Managing accounts
      4. Ethereum gas
      5. Ethereum virtual machine
        1. Execution environment
      6. Ethereum block
        1. Block header
        2. Ommers or uncles
      7. Messages
      8. Ethash
    3. Ether
      1. Procuring ether
        1. Trading
    4. Summary
  18. Solidity 101
    1. Basics of Solidity
      1. The basics of working on Solidity
        1. Using the compiler
    2. Programming in Solidity
      1. Laying out a Solidity file
        1. Importing files
        2. Commenting
          1. Tags
      2. Structure of a contract
        1. State variables
        2. Functions
        3. Function modifiers
        4. Events
      3. Types
        1. Value types
          1. Boolean
          2. Integers
          3. Address
          4. Array value type
          5. Literal
          6. Enums
          7. Function
          8. Function Modifiers
        2. Reference types
          1. Structs
          2. Data location
        3. Mapping
      4. Units and global variables
    3. Summary
  19. Smart Contracts
    1. Why smart contracts?
      1. Automating processes and resolutions between parties
        1. Real-world example
      2. Increased transparency
        1. Ending centralized data
      3. Increased fairness
    2. Smart contract approaches
      1. Example Ethereum smart contracts
        1. The promises
        2. Security considerations
        3. Dealing with threats in smart contracts
    3. Limitations of smart contracts
      1. Data quality and mistakes
      2. Legal validity
      3. Stability of meaning
    4. Summary
      1. References
  20. Ethereum Accounts and Ether Tokens
    1. Introducing Ethereum accounts
      1. Ethereum state transition function
      2. Genesis block
      3. Transaction receipts
        1. Elements
          1. Post-transaction state
          2. Gas used
          3. Set of logs
          4. The bloom filter
        2. Structure
      4. Transaction sub state
        1. Suicide set
        2. Log series
        3. Refund balance
      5. Messages
      6. Calls
    2. Ethereum block validation
      1. Uncles validation
      2. Block difficulty
      3. Block finalization
    3. Disadvantages of Ethereum-based tokens
    4. Summary
  21. Decentralized Applications
    1. What makes an application decentralized
      1. Defining a decentralized application
      2. Decentralized apps and blockchain
        1. Using blockchain does not make an application decentralized
    2. Major decentralized blockchain applications
      1. Aragon
      2. district0x
        1. What is a district?
      3. Ethereum name service
      4. Civic/uPort
      5. Gnosis
      6. Steemit
      7. CryptoKitties
    3. Summary
      1. References
  22. Mining
    1. Cryptocurrency mining
      1. The mining process
    2. Algorithms 
    3. Mining hardware
      1. CPU-based mining
      2. GPU-based mining
      3. FPGA-based mining
      4. ASIC-based mining
    4. Miner types
      1. Cloud mining
      2. Hardware mining
        1. Mining rigs
    5. Mining pools
      1. Pay-per-share – PPS
      2. Proportional – PROP
      3. Pay-per-last-N-shares – PPLNS
      4. The double geometric method – DGM
      5. Shared maximum pay per share – SMPPS
      6. Equalized shared maximum pay per share – ESMPPS
      7. Recent shared maximum pay per share – RSMPPS
      8. Capped pay per share with recent backpay – CPPSRB
      9. Bitcoin pooled mining – BPM
      10. Pay on target – POT
      11. SCORE
      12. Popular pools
    6. Mining software
    7. Summary
  23. ICO 101
    1. The current state of the ICO market
      1. Increasing volume of ICOs
    2. Typical aspects of an ICO campaign
      1. Whitepaper
      2. Private placement
      3. Pre-sale
        1. Good pre-sale practices
      4. Public sale
        1. Capped sale
        2. Uncapped sale
        3. Dutch auction
      5. Influencer marketing
      6. PR campaigns
      7. Content marketing
      8. ICO reviewers
      9. Smart contract and prototype development
        1. Code audits
      10. Bounty campaigns
      11. Airdrops
      12. Road shows
    3. Issues with ICOs and blockchain projects
      1. Proof of product-market fit and traction
        1. Low barrier to entry
      2. Does a project really need the blockchain?
      3. Misleading token practices
        1. Legality
          1. Utility versus Security
          2. Other considerations
      4. Sustainability
      5. Advantages of ICOs
        1. Liquidity
        2. Lack of gatekeepers
        3. Minimal investment sizes
      6. Notable scams 
        1. Onecoin
        2. Pincoin and iFan
        3. Bitconnect
      7. Other problems
        1. Major hacks
          1. The DAO
          2. Parity
      8. Securing an ICO
        1. SSH key locked servers
        2. DNS security
        3. Intrusion detection
        4. Purchase related domains
        5. Monitor social channels
        6. Multi-signature wallets
        7. Code audits
      9. Conclusion
      10. References
  24. Creating Your Own Currency
    1. Understanding types of cryptocurrency
      1. Tokens based on existing blockchains
      2. Creating a new blockchain from scratch
      3. A forked blockchain with one's own genesis block
        1. Litecoin's development
        2. The process
    2. Creating one's own cryptocurrency
      1. Setting up Litecoin
        1. Platform selection
          1. Preparation
          2. Dependency installation
          3. Build instructions
      2. Setting up our own coin
        1. Port selection
        2. The setting of block-related parameters
        3. Amount limit
        4. The coinbase maturity number
        5. Genesis block creation
        6. Wallet address
        7. Checkpoints
        8. Creatives and graphics
      3. Summing up 
    3. Summary
  25. Scalability and Other Challenges
    1. Scalability and decentralization
    2. Blockchains in business
    3. Usability
      1. Lack of protection
    4. 51% attacks
    5. Network forks
    6. Catastrophic bugs
    7. Lack of interoperability
    8. Low availability of blockchain skills
    9. Privacy
    10. Energy consumption
    11. Summary
    12. References
  26. Future of Blockchain
    1. Ongoing fragmentation and specialization
      1. Video games
      2. Real estate
      3. Logistics
      4. Licensing
      5. Industry consortiums
      6. A large number of total-loss projects
    2. Legal and regulatory evolution
      1. Security token offerings
      2. Aggregate and insurance products
    3. Technological stabilization
      1. Ethereum and Hyperledger 
      2. Service consolidation and product offerings
      3. Cross-chain communication
    4. Intersecting with AI and IoT
      1. Blockchain-intersecting AI
      2. Blockchain-intersecting IoT
    5. Summary
  27. Understanding Decentralized Applications
    1. Decentralized autonomous organization
    2. User identity in DApps
    3. User accounts in DApps
    4. Accessing the centralized apps
    5. Internal currency in DApps
      1. Disadvantages of internal currency in DApps
    6. What are permissioned DApps?
    7. Popular DApps
      1. Bitcoin
        1. What is a ledger?
        2. What is blockchain?
        3. Is Bitcoin legal?
        4. Why would someone use Bitcoin?
      2. Ethereum
      3. The Hyperledger project
      4. IPFS
        1. How does it work?
          1. Filecoin
      5. Namecoin
        1. .bit domains
      6. Dash
        1. Decentralized governance and budgeting
        2. Decentralized service
      7. BigChainDB
      8. OpenBazaar
      9. Ripple
    8. Summary
  28. Understanding How Ethereum Works
    1. Transactions
    2. Timestamp
    3. Nonce
    4. Block time
    5. Forking
    6. Genesis block
    7. Peer discovery
    8. Whisper and Swarm
    9. Ethereum Wallet
    10. Serenity
      1. Payment and state channels
      2. Proof-of-stake and casper
      3. Sharding
    11. Summary
  29. Writing Smart Contracts
    1. Solidity source files
    2. The structure of a smart contract
    3. Data location
    4. What are the different data types?
      1. Arrays
      2. Strings
      3. Structs
      4. Enums
      5. Mappings
      6. The delete operator
      7. Conversion between elementary types
      8. Using var
    5. Control structures
    6. Creating contracts using the new operator
    7. Exceptions
    8. External function calls
    9. Features of contracts
      1. Visibility
      2. Function modifiers
      3. The fallback function
      4. Inheritance
        1. The super keyword
        2. Abstract contracts
    10. Libraries
      1. Using for
    11. Returning multiple values
    12. Importing other Solidity source files
    13. Globally available variables
      1. Block and transaction properties
      2. Address type related
      3. Contract related
    14. Ether units
    15. Proof of existence, integrity, and ownership contract
    16. Compiling and deploying contracts
    17. Summary
  30. Getting Started with web3.js
    1. Introduction to web3.js
      1. Importing web3.js
      2. Connecting to nodes
      3. The API structure
      4. BigNumber.js
      5. Unit conversion
      6. Retrieving gas price, balance, and transaction details
      7. Sending ether
      8. Working with contracts
      9. Retrieving and listening to contract events
    2. Building a client for an ownership contract
      1. The project structure
      2. Building the backend
      3. Building the frontend
      4. Testing the client
    3. Summary
  31. Building a Wallet Service
    1. hooked-web3-provider and ethereumjs-tx libraries
    2. Introduction to LightWallet
      1. HD derivation path
    3. Building a wallet service
      1. Prerequisites
      2. Project structure
      3. Building the backend
      4. Building the frontend
      5. Testing
    4. Summary
  32. Building a Smart Contract Deployment Platform
    1. Calculating a transaction's nonce
    2. Introducing solcjs
      1. Installing solcjs
      2. solcjs APIs
        1. Using a different compiler version
        2. Linking libraries
        3. Updating the ABI
    3. Building a contract deployment platform
      1. The project structure
      2. Building the backend
      3. Building the frontend
      4. Testing
    4. Summary
  33. Building a Betting App
    1. Introduction to Oraclize
      1. How does it work?
      2. Data sources
      3. Proof of authenticity
      4. Pricing
      5. Getting started with the Oraclize API
        1. Setting the proof type and storage location
        2. Sending queries
        3. Scheduling queries
        4. Custom gas
        5. Callback functions
        6. Parsing helpers
        7. Getting the query price
      6. Encrypting queries
        1. Decrypting the data source
      7. Oraclize web IDE
    2. Working with strings
    3. Building the betting contract
    4. Building a client for the betting contract
      1. Projecting the structure
      2. Building the backend
      3. Building the frontend
      4. Testing the client
    5. Summary
  34. Building Enterprise Level Smart Contracts
    1. Exploring ethereumjs-testrpc
      1. Installation and usage
        1. The testrpc command-line application
        2. Using ethereumjs-testrpc as a web3 provider or as an HTTP server
      2. Available RPC methods
    2. What are event topics?
    3. Getting started with truffle-contract
      1. Installing and importing truffle-contract
      2. Setting up a testing environment
      3. The truffle-contract API
        1. The contract abstraction API
          1. Creating contract instances
        2. The contract instance API
    4. Introduction to truffle
      1. Installing truffle
      2. Initializing truffle
      3. Compiling contracts
      4. Configuration files
      5. Deploying contracts
        1. Migration files
        2. Writing migrations
      6. Unit testing contracts
        1. Writing tests in JavaScript
        2. Writing tests in Solidity
          1. How to send ether to a test contract
        3. Running tests
      7. Package management
        1. Package management via NPM
        2. Package management via EthPM
        3. Using contracts of packages within your contracts
        4. Using artifacts of packages within your JavaScript code
        5. Accessing a package's contracts deployed addresses in Solidity
      8. Using truffle's console
      9. Running external scripts in truffle's context
      10. Truffle's build pipeline
        1. Running an external command
        2. Running a custom function
        3. Truffle's default builder
          1. Building a client
      11. Truffle's server
    5. Summary
  35. Building a Consortium Blockchain
    1. What is a consortium blockchain?
    2. What is Proof-of-Authority consensus?
    3. Introduction to parity
      1. Understanding how Aura works
      2. Getting parity running
        1. Installing rust
          1. Linux
          2. OS X
          3. Windows
        2. Downloading, installing and running parity
      3. Creating a private network
        1. Creating accounts
        2. Creating a specification file
        3. Launching nodes
        4. Connecting nodes
      4. Permissioning and privacy
    4. Summary
  36. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Blockchain Developer's Guide
  • Author(s): Brenn Hill, Samanyu Chopra, Paul Valencourt, Narayan Prusty
  • Release date: December 2018
  • Publisher(s): Packt Publishing
  • ISBN: 9781789954722