Setting up Ganache

If you remember, in the previous chapter,Peer-to-Peer Auctions in Ethereum, we introduced Ganache as a virtual blockchain for local testing. This tool is available under two formats:

  • Ganache CLI (previously known as TestRPC)
  • GUI version (we used it in the previous chapter)

In this chapter, we will use ganache-cli. Hence, install Ganache CLI globally using NPM, as follows:

npm install -g ganache-cli

Once installed, open a separate command line or tab and type in the following command:

ganache-cli -p 7545

As you may have guessed, the -p option specifies which port to listen on as Ganache CLI runs by default on 8545 (the same as Geth). If you are unsure about an option, refer to Ganache's GitHub page (https://github.com/trufflesuite/ganache-cli) where you can find ample information.

When Ganache starts up, it generates 10 accounts (unlocked) preloaded with a balance of 100 ether each, and displays their Ethereum addresses and the corresponding private keys, as shown in the following picture :

These accounts will be very helpful to build raw transactions or import the created accounts later.

After this step, you can deploy the contract by running the truffle migrate --network my_ganache migration command.

After the successful execution of the deployment script, Truffle will output the HelloWorld contract's address, as depicted here:

Truffle will automatically use the first account generated by Ganache to deploy your contract.

At the same time, in Ganache's output, you should see the deployment transaction details, as shown in the following screenshot:

You have now set up the necessary development and deployment environment to build a DApp, and learned how to compile and deploy a given contract into Truffle.

Next, we kick off the most exciting part: building the game. Let's start from the smart contract side.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset