Lesson 1 of 0
In Progress

4.02 – Downloading, Installing & Configuring All The Elements

Downloading, Installing, and Configuring All the Pieces

 

Now that you’re ready to build your Ethereum development environment, let’s dive right in. You’ll find out how to set up a PC running Microsoft Windows to be an Ethereum development platform. Windows isn’t the only operating system that supports Ethereum. You can just as easily set up a macOS or Linux computer to support Ethereum. If you’re running macOS or Linux, each tool in this chapter will work on your computer, too, although the installation steps might be a little different. Each tool’s website will provide detailed instructions for each operating system.

 

Installing the blockchain client

 

Start by installing an Ethereum client. We’re using Go Ethereum (Geth) as the Ethereum client for the examples in this course. Geth is written in the Go language and allows you to run a full Ethereum node. Running a full Ethereum node means you’ll have access to the complete Ethereum blockchain and also run a local EVM. Geth gives you the capability to mine ETH, create transactions and smart contracts, and examine any blocks that already exist on the blockchain. All remaining tools you’ll install in this chapter will depend on Geth to provide the local EVM and allow access to the blocks on the blockchain.

 

The Geth website provides prepackaged installers for Microsoft Windows, macos, and Linux operating systems. You can also download the Geth source code and build it for your own custom environment. If you’re interested in playing around with devices other than just computers, you can conduct an Internet search and easily find instructions on setting up Geth on smartphones or a Raspberry Pi. That’s the beauty of using open-source tools.

 

Start by downloading and installing Geth, as follows:

 

  1. Launch your browser and navigate to https://geth.ethereum.org; then click or tap the Downloads link at the top of the page.

 

Your web browser will look like Figure 4-1.

 

  1. Click or tap the Geth button for your operating system.

 

Because we’re setting up a Microsoft Windows computer in this tutorial, we selected Geth 1.10.9 for Windows. (When you set up your computer, a newer version of Geth might be available. You should download and install the latest version of each tool.)

 

  1. Launch the executable file you just downloaded.

 

  1. Click or tap I Agree to the GNU General Public License.

 

Always read any license agreement before agreeing to its contents.

 

  1. Select the Development Tools check box, and then click or tap the Next Button.

 

Make sure that you choose to install the development tools in this window before continuing. Figure 4-2 shows what the Installation Options window looks like.

 

  1. If you want to install Geth to a different folder than the one that’s displayed, change it to your desired destination folder.

 

  1. Click or tap the Install button to start the installation process.

 

  1. When the installation finishes, click or tap the Close button.

 

After you’ve installed Geth, you can launch it to start the EVM and synchronize with the public Ethereum blockchain.

 

— Go ETH (Geth) download page —

 

— Geth setup example —

 

You find out about some other Geth start-up options in Chapter 5 of this course, but the only option you need for now is syncmode, which tells Geth how much of the blockchain to download. The syncmode option has the following three values. Note that you’ll be using the light value for the syncmode option:

 

» full: Download and validate the entire blockchain. This option requires the most time and disk space but can provide the fastest response because a full node doesn’t ever have to request missing blocks from other nodes.

 

» fast: Download and validate the block headers and data for the most recent 1,000 transactions. This option is a good choice when you want to conserve some disk space but also want to store the most recent blocks locally.

 

» light: Download only the blockchain current state and request any missing blocks from other nodes as needed. This option allows you to operate Ethereum with minimal disk space requirements.

 

For the exercise in this course, you’ll use the light syncmode option for Geth. To start Geth in light mode, follow these steps:

 

  1. Launch a command prompt or PowerShell prompt.

 

To launch a command prompt, type cmd in the search bar at the lower-left corner of your desktop and then click or tap the Command Prompt option. To launch a PowerShell prompt, type PowerShell in the search bar and click or tap the PowerShell option.

 

  1. Change the current working directory to the Geth install directory.

 

If you installed Geth to the default location, type the following and then press Enter:

 

cd ‘C:\Program Files\Geth\’

 

  1. Type the following, and then press Enter:

 

.\geth — syncmode “light”

 

  1. This command launches Geth in light mode. Make sure that you type two dashes before syncmode.

 

Figure 4-3 shows the Geth command to start a light Ethereum node.

 

— Geth light node start-up command —

 

As Geth starts, it establishes a connection with the Ethereum network and begins synchronizing the current blockchain. Geth provides messages at each stage of its start-up process to let you see what is happening. Figure 4-4 shows what the Geth messages look like.

 

After Geth synchronizes the blockchain, you’re ready to use the Geth blockchain client to develop and deploy your own dApps.

 

— Geth runtime messages —

 

​​Installing the test blockchain

 

When you develop smart contracts and dApps, you don’t want to deploy your code or data to the live blockchain until you’re sure that everything works correctly. This means that you have to test your code in some non-live environment. To do this, you need a blockchain to use during the development and testing process. Ethereum clients, Geth included, connect to the main public Ethereum blockchain by default, but you can connect to other blockchains as well. You can change the connection settings easily for development and testing.

 

Several tools make it easy to create and manage test blockchains. Ganache is the test blockchain environment used here. According to the Ganache website (https://truffleframework.com/ganache), “Ganacheis a personal blockchain for Ethereum development that you can use to deploy contracts, develop your applications, and run tests.”

 

You aren’t limited to the prebuilt Ganache images. Because Ganache is an open source product, you can also download the Ganache source code and build it for your own custom environment.

 

To download and install Ganache, follow these steps:

 

  1. Launch your browser and navigate to https ://truffleframework.com/ ganache.

 

Your web browser should look like Figure 4-5.

 

  1. Click or tap the Download (Windows) button to download the Windows installer.

 

— The Ganache Download webpage —

 

  1. Launch the executable file you just downloaded. Then click or tap the Install button to start the installation process.

 

By default, Ganache launches when the installation finishes.

 

  1. Accept the default, as shown in Figure 4-6, or click or tap the Analytics Enabled toggle box to disable Analytics, and then click or tap the Continue button.

 

Because this is the first time you’re launching Ganache, you are asked to allow Google Analytics tracking. You don’t have to do this, but allowing analytics helps the Ganache development team understand how different people use Ganache.

 

  1. Click or tap the Quickstart button to launch Ganache.

 

Ganache provides the option to start with an empty test blockchain each time you launch Ganache, or to create a workspace that will save changes to a test blockchain when Ganache shuts down. Ganache workspaces are helpful when developers need to save changes to a test blockchain for later use. Choosing the Quickstart option tells Ganache to create a new, empty test blockchain.

 

When Ganache launches, you see the main Ganache Accounts window with basic server information and a list of accounts, as shown in Figure 4-7. Because the reason to install Ganache is to create your own blockchain, you need at least one account to access the blockchain. Ganache creates 10 accounts for you, each with a balance of 100.0 ETH. You can create more accounts and give them all the ETH they need to test your smart contracts and dApps.

 

— The Ganache Accounts window —

 

That’s all it takes to create your own Ethereum blockchain in Ganache. Of course, this blockchain is local to your own computer and isn’t distributed to any other nodes. Because no other nodes are on this network, there aren’t any miners. This blockchain is set to automining, which means that any new transactions are processed immediately. That setting makes it easy to test your smart contracts and dApps without having to pay miners to process your transactions.

 

When you’re ready to start developing software for Ethereum, you need to tell your client and other tools which blockchain to use. Let’s see where your new Ganache blockchain is located. In Ganache, click or tap the settings (gear) icon in the upper-right corner to launch the Ganache Settings window. Then click or tap the Server tab to open the Ganache Server Settings window. Figure 4-8 displays the Server tab of the Ganache Settings window.

 

— The Ganache Setting’s window’s server tab —

 

You can see where other tools can find your blockchain. The Hostname, Port Number, and Network ID values show you what you need any time you want another tool to use this blockchain. You don’t need these values quite yet, but now you know where to find them.

 

Also note the Automine setting, which is enabled by default. Before you deploy your software to a live blockchain, you can disable this setting and enter a number of seconds to delay between new blocks being added to the blockchain. Manually specifying a delay between block creations helps to simulate the effect of miners that you’ll encounter in a live blockchain. Testing will be more complex but also more realistic. In Chapter 8 of this course, you can find out more about carrying out comprehensive testing.

 

Before you leave the Settings window, look at the settings on the other tabs (Workspace, Accounts & Keys, Chain, Advanced, and About). The Ganache Quickstart guide has details on these settings at https://truffleframework.com/docs/ganache/quickstart.

 

Installing the testing environment

 

The software development process is made up of multiple steps. In Chapter 3 of this course, you can find out about the four main phases of the Ethereum software development life cycle. Although the life cycle has only four phases, many different tasks need to be accomplished. In addition to just writing source code, you have to compile your code, deploy it to a test environment, test the code, and measure how well the code performs against your specifications. Then you need to fix any flaws and repeat the testing process until you’re satisfied with the code’s operation.

 

After you complete testing, you need to transition your software from a test environment to a live environment. For this transition, you need to submit your smart contracts to a live blockchain and place any other code where your clients can access it. All tasks related to testing and deployment should be repeatable and as automated as possible. A comprehensive testing framework helps to standardize these tasks and make the entire development process more manageable.

 

Truffle is the testing environment we’re using for the examples in this course. You may have noticed that the test Ethereum network, Ganache, is part of the Truffle Suite. One of the reasons we chose both Truffle and Ganache is due to the easy integration of these tools. In the rest of this section, you find out how to install Truffle.

 

Getting ready to install Truffle

 

Before you can install Truffle, you have to ensure that your computer meets the prerequisites. Open your browser and navigate to https://truffleframework.com/docs/truffle/getting-started/installation to see the Truffle installation requirements, which are shown in Figure 4-9.

 

The main requirement for Truffle is to have NodeJS version 8.9.4 or later installed. NodeJS is an open-source project that provides a runtime environment for code written in JavaScript. JavaScript was originally designed to run in web browsers, but NodeJS makes it easy to run JavaScript code outside a browser.

 

It’s easy to find out whether NodeJS is installed. Open a command shell or PowerShell window, type the node command, and press Enter. You get either a simple “>” prompt or an error message telling you that NodeJS is not installed. Figure 4-10 shows the error message you see in Windows PowerShell if you don’t have NodeJS installed.

 

— Truffle installation requirements —

 

— Error message in PowerShell when NodeJS isn’t installed —

 

If you do have NodeJS installed, skip to the next section, “Downloading and installing Truffle.” If you don’t have NodeJS installed, follow these steps to download and install it:

 

  1. Launch your browser and navigate to https://nodejs.org/en/.

 

Your web browser should look like Figure 4-11. The NodeJS website detects your operating system and suggests the versions for that operating system. If you’re using Microsoft Windows, you see download links for Windows.

 

  1. Click or tap the button for the version you want to install to download the Windows installer.

 

You can download the latest version or the latest stable (long-term support, or LTS) version. We’re using the LTS version for the examples in this course. (When you set up your computer, a newer version of NodeJS might be available. You should download and install the latest version of each available tool.)

 

If you want to install NodeJS on a computer that isn’t running Microsoft Windows, or you want to build your own version of NodeJS, click or tap the Other Downloads link. This link takes you to a page with options to download source code or installer packages for multiple operating systems.

 

  1. Launch the executable file you just downloaded.

 

Click or tap the Next button to start the installation process.

 

  1. Read the End-User License Agreement, accept it, and then click or tap Next.

 

  1. Select NodeJS installation options in the next three windows.

 

Enter the install destination (or accept the default), and then click or tap Next. In the Custom Setup window that appears, click or tap Next to accept the defaults. In the next window, click or tap the Automatically Install the Necessary Tools option and then click or tap Next.

 

  1. To install NodeJS, click or tap Install.

 

  1. To complete the NodeJS part of the installation process, click or tap Finish.

 

  1. Install the NodeJS tools.

 

Press any key in the next two windows to run the scripts to install the supplemental NodeJS tools.

 

— The NodeJS Download webpage —

 

You can verify that NodeJS is installed with a simple command. Open a command shell or PowerShell window, type the following command, and press Enter:

 

node — version

 

This time, when you enter the node command, you should see a message showing you the installed NodeJS version. Figure 4-12 shows the version message in Windows PowerShell.

 

— NodeJS version message —

 

After you have NodeJS installed, you’re ready to install Truffle.

 

Downloading and installing Truffle

 

The NodeJS environment makes it easy to find and download new packages, including Truffle. The Truffle installation process requires you to enter just a single command.

 

To install Truffle, open a command shell or PowerShell window, type the following command, and press Enter:

 

npm install -g truffle

 

You may see some warnings during the installation, but don’t worry about them. Figure 4-13 shows what this command and the results look like. Truffle is installed and almost ready to be used.

 

Truffle organizes development activities into projects. That way, you can work on multiple projects with different configuration requirements. For example, you could set up a different testing blockchain for each of several projects. In Chapter 5 of this course, you can find out more about configuring projects. Here, let’s look at the basics of setting up a project in Truffle.

 

— Installing Truffle —

 

Each Truffle project needs its own folder. The first thing you need to do to set up a Truffle project is to create a project folder. To create a new empty project named myProject, for example, open a command shell or PowerShell window, type the following command, and press Enter:

 

mkdir myProject

 

Make the new project folder your current directory by typing the following command and pressing Enter:

 

cd myProject

 

Then, to initialize your new Truffle project, enter this command and press Enter:

 

truffle init

 

Figure 4-14 shows these commands initializing a new Truffle project.

 

— Initializing a new Truffle project —

 

That’s it! You now have a new Truffle project named myProject. That’s all you do at this point. You can use File Explorer or the dir command to look at the myProject folder to see the files and new folders that Truffle created. You can find out more about how Truffle uses these files and folders to define projects when you start writing your own smart contracts. But for now, you’re ready to install the last tool to complete your Ethereum development environment.

 

Installing the IDE

 

Now that all of the foundational pieces are in place, you’re just about ready to start writing code. The most visible part of software development is writing the source code. Many developers consider writing code to be the first “productive” step in the software development process, but that is far from the truth. Before you start writing any code, you should carefully and completely plan and design your application.

 

You save yourself far more time in the development process by taking the time up front to plan. Planning reduces the number of times you have to rework your code when what you write the first time doesn’t do everything that you need it to.

 

After you have a thorough plan and you know what code you need to write to meet all your application’s goals, you’re ready to start writing the source code that will become your final application. Although you can use any text editor to write code in Solidity, many tools are available to make your development activities easier.

 

An integrated development environment (IDE) is like a super editor. IDEs enable you to create and edit code as well as provide many supporting features, such as automatic code completion and syntax help, as you type. A good IDE can save you lots of time and help you write better code.

 

Use an editor or IDE that you find comfortable. Try out several options before you settle on the tool you’ll use.

 

For the exercise in this course, you use Microsoft Visual Studio Code IDE to write source code. To download and install Visual Studio Code, follow these steps:

 

  1. Launch your browser and navigate to https://code.visualstudio.com/.

 

Your web browser should look like Figure 4-15.

 

  1. Click or tap the Windows download button.

 

If you want to install Visual Studio Code on a computer that isn’t running Microsoft Windows, click or tap one of the other download buttons that corresponds to the operating system of your choice.

 

  1. Launch the executable file you just downloaded by clicking the Next button on the Setup – Visual Studio Code window.

 

  1. Read and accept the License Agreement, and then click or tap Next.

 

— The Microsoft Visual Studio Code download webpage example —

 

  1. Select Visual Studio Code installation options in the next three windows.

 

Enter the install destination (or accept the default), and then click or tap Next. In the Select Start Menu Folder window, click or tap Next to accept the defaults. In the next window, if you want to place a shortcut to Visual Studio Code on your desktop, click or tap the Create a Desktop Icon option. Then click or tap Next.

 

  1. To install Visual Studio code, review your install options (see Figure 4-16) and then click or tap Install.

 

Your settings should look similar to the ones in Figure 4-16, with the exception of the destination location.

 

  1. When Visual Studio Code finishes installing, click or tap Finish to complete the installation process and launch the Visual Studio Code IDE.

 

— The Visual Studio Code install options window —

 

The Visual Studio (VS) Code IDE is now installed. Figure 4-17 shows the default Visual Studio Code tabletop and Welcome window. The Welcome window contains lots of helpful information for getting started using the VS Code IDE.

 

If you close the Welcome window, you can always open it again from the Help menu. It’s the top option in the Help menu.

 

You have one more step to complete the installation of your Ethereum development environment. To get the benefit of VS Code’s syntax highlighting, code completion, and other features, you need to add an extension so that VS Code understands Solidity. The easiest way to add any extension to VS Code is right from the IDE.

 

— The Visual Studio Code IDE desktop —

 

Click or tap the Extensions (square image) icon on the left border of the VS Code tabletop. In the Search Extensions in Marketplace text box, type Solidity. A list of extensions that match your search term appears. Find the extension with the title “Ethereum Solidity Language for Visual Studio Code by Juan Blanco” and click or tap the green Install button for that extension. When you successfully install the Solidity extension, your VS Code window should look like Figure 4-18.

 

— The Visual Studio Code IDE with the Solidity extension —

 

Congratulations! You’ve successfully built an Ethereum Solidity application development environment.