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