Building Blockchain Projects
Narayan Prusty
- 266 pages
- English
- ePUB (mobile friendly)
- Available on iOS & Android
Building Blockchain Projects
Narayan Prusty
About This Book
Develop real-time practical DApps using Ethereum and JavaScriptAbout This Book⢠Create powerful, end-to-end applications for Blockchain using Ethereum⢠Write your first program using the Solidity programming language⢠Change the way you think and design your applications by using the all new database-BlockchainWho This Book Is ForThis 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.What You Will Learn⢠Walk through the basics of the Blockchain technology⢠Implement Blockchain's technology and its features, and see what can be achieved using them⢠Build DApps using Solidity and Web3.js⢠Understand the geth command and cryptography⢠Create Ethereum wallets⢠Explore consortium blockchainIn DetailBlockchain is a decentralized ledger that maintains a continuously growing list of data records that are 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, making it permission-less.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 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 about concepts such as cryptography in cryptocurrencies, ether security, mining, smart contracts, solidity, and more. You will also learn about web sockets, various API services for Ethereum, and much more.The blockchain is the main technical innovation of bitcoin, where it serves as the public ledger for bitcoin transactions.Style and approachThis is a project-based guide that not only gets you up and running with Blockchain, but also lets you create intuitive real-world applications that will make you an independent Blockchain developer.
Frequently asked questions
Information
Building Enterprise Level Smart Contracts
- What the ethereumjs-testrpc node is and how to use it?
- What are topics of events?
- Working with contracts using the truffle-contract package.
- Installing truffle and exploring the truffle command-line tool and configuration file
- Compiling, deploying, and testing Solidity code using truffle
- Package management via NPM and EthPM
- Using the truffle console and writing external scripts
- Building clients for the DApp using truffle
Exploring ethereumjs-testrpc
Installation and usage
The testrpc command-line application
npm install -g ethereumjs-testrpc
- -a or --accounts: This specifies the number of accounts to be generated at startup.
- -b or --blocktime: This specifies the blocktime in seconds for automatic mining. The default is 0, and there's no auto-mining.
- -d or --deterministic: Whenever the node is run, it will generate 10 deterministic addresses; that is, when you provide this flag, the same set of addresses are generated every time. This option can be used to generate deterministic addresses based on a predefined mnemonic as well.
- -n or --secure: Locks the available accounts by default. When this option is used without the --unlock option, the HD wallet will not be created.
- -m or --mnemonic: Uses a specific HD wallet mnemonic to generate initial addresses.
- -p or --port: The port number to listen on. Defaults to 8545.
- -h or --hostname: The hostname to listen on. Defaults to Node's server.listen() default.
- -s or --seed: The arbitrary data to generate the HD wallet mnemonic to be used.
- -g or --gasPrice: Uses a custom gas price (defaults to 1). If the gas price is not provided while sending the transaction to the node, then this gas price is used.
- -l or --gasLimit: Uses a custom limit (defaults to 0x47E7C4). If the gas limit is not provided while sending the transaction to node, then this gas limit is used.
- -f or --fork: This is the fork from another currently running Ethereum node at a given block. The input should be the HTTP location and port of the other client; for example, http://localhost:8545. Optionally, you can specify the block to fork from using an @ sign: http://localhost:8545@1599200.
- --debug: Outputs VM opcodes for debugging.
- --account: This option is used to import accounts. It specifies --account=... any number of times, passing arbitrary private keys and their associated balances to generate initial addresses. An testrpc --account="privatekey,balance" [--account="privatekey,balance"] an HD wallet will not be created for you when using --account.
- -u or --unlock: Specifies --unlock ... any number of times, passing either an address or an account index to unlock specific accounts. When used in conjunction with --secure, --unlock will override the locked state of the specified accounts: testrpc --secure --unlock "0x1234..." --unlock "0xabcd...". You can also specify a number, unlocking accounts by their index: testrpc --secure -u 0 -u 1. This feature can also be used to impersonate accounts and unlock addresses you wouldn't otherwise have access to. When used with the --fork feature, you can use the testrpc to make transactions as any address on the blockchain, which is very useful in testing and dynamic analysis.
- --networkId: Used to specify a network ID that this node is part of.
Using ethereumjs-testrpc as a web3 provider or as an HTTP server
var TestRPC = require("ethereumjs-testrpc");
web3.setProvider(TestRPC.provider());
var TestRPC = require("ethereumjs-testrpc");
var server = TestRPC.server();
server.listen(port, function(err, blockchain) {});
- accounts: Value is an array of objects. Each object should have a balance key with a hexadecimal value. The secretKey key can also be specified, which represents the account's private key. If there's no secretKey, the address is autogenerated with the given balance. If specified, the key is used to determine the account's address.
- debug: Outputs VM opcodes for debugging.
- logger: Value is an object that implements a log() function.
- mnemonic: Uses a specific HD wallet mnemonic to generate initial addresses.
- port: The port number to listen on when running as a server.
- seed: Arbitrary data to generate the HD wallet mnemonic to be used.
- total_accounts: The number of accounts to generate at start up.
- fork: The same as the preceding --fork option.
- network_id: The same as the --networkId option. Used to specify a network ID that this node is part of.
- time: The date that the first block should start. Use this feature along with the evm_increaseTime method to test time-dependent code.
- locked: Specifies whether or not accounts are locked by default.
- unlocked_accounts: An array of addresses or address indexes specifying which accounts should be unlocked.
Available RPC methods
- eth_accounts
- eth_blockNumber
- eth_call
- eth_coinbase
- eth_compileSolidity
- eth_estimateGas
- eth_gasPrice
- eth_getBalance
- eth_getBlockByNumber
- eth_getBlockByHash
- eth_getBlockTransactionCountByHash
- eth_getBlockTransactionCountByNumber
- eth_getCode (only supports block number "latest")
- eth_getCompilers
- eth_getFilterChanges
- eth_getFilterLogs
- eth_getLogs
- eth_getStorageAt
- eth_getTransactionByHash
- eth_getTransactionByBlockHashAndIndex
- eth_getTransactionByBlockNumberAndIndex
- eth_getTransactionCount
- eth_getTransactionReceipt
- eth_hashrate
- eth_mining
- eth_newBlockFilter
- eth_newFilter (includes log/event filters)
- eth_sendTransaction
- eth_sendRawTransaction
- eth_sign
- eth_syncing
- eth_uninstallFilter
- net_listening
- net_peerCount
- net_version
- miner_start
- miner_stop
- rpc_modules
- web3_clientVersion
- web3_sha3
- evm_snapshot: Snapshots the state of the blockchain at the current block. Takes no parameters. Returns the integer ID of the snapshot created.
- evm_revert: Reverts the state of the blockchain to a previous snapshot. Takes a single parameter, which is the snapshot ID to revert to. If no snapshot ID is passed, it will revert to the latest snapshot. Returns true.
- evm_increaseTime: Jumps forward in time. Takes one parameter, which is the amount of time to increase in seconds. Returns the total time adjustment in seconds.
- evm_mine: Forces a block to be mined. Takes no parameters. Mines a block independent of whether or not mining is started or stopped.