Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Ethereum Cookbook

You're reading from   Ethereum Cookbook Over 100 recipes covering Ethereum-based tokens, games, wallets, smart contracts, protocols, and Dapps

Arrow left icon
Product type Paperback
Published in Aug 2018
Publisher Packt
ISBN-13 9781789133998
Length 404 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Manoj P R Manoj P R
Author Profile Icon Manoj P R
Manoj P R
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Getting Started FREE CHAPTER 2. Smart Contract Development 3. Interacting with the Contract 4. The Truffle Suite 5. Tokens and ICOs 6. Games and DAOs 7. Advanced Solidity 8. Smart Contract Security 9. Design Decisions 10. Other Protocols and Applications 11. Miscellaneous 12. Other Books You May Enjoy

Creating a blockchain network for development

You don't always have to create a fully functioning node to support your development. There are development networks that can simulate an Ethereum network. In this recipe, you will learn about ganache-cli (previously TestRPC), which is part of the Truffle suit of Ethereum development tools and is a command-line tool that you can use to create your personal blockchain network for Ethereum development.

Getting ready

Since the tool is written in JavaScript and distributed via npm, you will need Node.js (>= v6.11.5) installed on your machine to try this recipe.

How to do it...

Follow these steps to install and create a test Ethereum network using npm:

  1. Install ganache-cli using npm:
npm install -g ganache-cli
  1. Starting a basic blockchain network is as simple as running this command:
ganache-cli

You will know that your blockchain is ready when you see this screen:

Ganache creates a virtual Ethereum blockchain, and it generates some sample accounts for you to use during development. Each account is filled in 100 Ether so that you only have to focus on development. You can access the network from http://localhost:8545.

  1. You can use a few parameters to customize the blockchain. Here's one such example:
ganache-cli -a 5 -e 2000 -p 8080 -l 999999
  • -a: Number of accounts to generate while starting the network. The default is 10.
  • -e: Amount of Ether to allocate for each account. The default is 100 Ether.
  • -p: Port number for listening to RPC requests. The default is 8,545.
  • -l: Gas limit for each block. The default is 90,000.

You can find the complete list of parameters to configure here:

https://github.com/trufflesuite/ganache-cli.

By default, accounts are unlocked and you can do the transaction from any account without a password. You can change this by using the --secure or -n flag. This will lock all accounts by default and you need to unlock each one to send a transaction.

There's more...

There is a GUI for ganache that offers an easy-to-use interface for creating Ethereum networks. It even offers an intuitive User Interface (UI) for browsing blocks and transactions.

You can download and install the ganache GUI from http://truffleframework.com/ganache/.

You have been reading a chapter from
Ethereum Cookbook
Published in: Aug 2018
Publisher: Packt
ISBN-13: 9781789133998
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image