Installing the GBA Development Environment (Windows PC) - GovtBlockchainAssoc/DraftDocs GitHub Wiki
v0.6
This tutorial will walk you through the steps to set up the standard GBA development environment.
Approximate time to complete: 90 minutes
Tools you’ll be working with:
- Windows Subsystem for Linux
- Node.js
- Visual Studio Code
- TypeScript
- OpenZeppelin
- Azure Blockchain Development Kit for Ethereum extension on WSL
- Python
- Truffle Suite
- Ganache
Because of the extensive amount of existing software, when developing, you will likely have to add a relatively small amount of code to achieve substantial results and copies of GBA code will be available from the GBA’s GitHub site.
All development software recommended is free and we will be using cross-platform software wherever possible. We will also generally select the options with the largest developer market share.
Installation instructions will range from the single, simple command “install from ” for problem-free installations to detailed step-by-step instructions where installation is problematic.
For those not used to developing with open source and/or bleeding-edge technologies, please note that, in these days of constantly changing development packages and large numbers of project dependencies, there are difficulties with previously problem-free setup procedures more often than not.
Due to its ubiquity, we will be using a standard Windows PC for the development environment. You can easily use a Linux machine instead. Because we will be using the Windows Subsystem for Linux [WSL], the installation instructions will normally be the same for both and we will include them for both where they differ.
Installing the development environment on WSL is Microsoft’s own recommendation for Node.JS, most likely due to the numerous reported problems with node-gyp installations on native Windows (node-gyp is necessary to compile add-on modules for Node written in languages other than JavaScript that are required by other software that we will be using).
This also makes it easier and less problematic to transfer your software to the runtime environment after developing and testing it locally.
The core of our development stack is the open-source, cross-platform Node.JS with cross-platform development environment of Visual Studio Code. Node is a JavaScript runtime environment built on Chrome's V8 JavaScript engine that executes JavaScript code outside of a browser. It is used by the heaviest of heavy hitters including AliExpress, Amazon, eBay, LinkedIn, Netflix, PayPal, Reddit and Tumblr.
VS Code is a source-code editor developed by Microsoft for Windows, Linus, and macOS.
We recommend TypeScript, a type-checking variant of JavaScript, rather than plain vanilla JavaScript as its compiler detects far more runtime errors and tremendously speeds development.
OpenZeppelin provides tools to write, deploy, and operate decentralized applications, and is the easiest way to write upgradeable Ethereum/Solidity smart contracts.
Links to their SDK and Starter Kits (including a recommended tutorial) are located under the Products top menu item.
Ganache allows you to create a personal Ethereum blockchain you can use to run tests, execute commands, and inspect state while controlling how the chain operates.
The Azure Blockchain Development Kit simplifies how you create, connect to, build and deploy smart contracts on Ethereum ledgers.
Python programming language
Truffle is the most popular development framework for Ethereum.
Install the most recent version of Windows 10 from www.microsoft.com.
If you already have windows installed, navigate to Windows Update: Windows Start button > Settings > Update & Security > Windows Update.
Configure your Windows diagnostic and feedback settings, before you register with the Windows Insider Program.
GBA recommends WSL 2 for better performance. This option requires that you first register with the Windows Insider Program to receive Windows Insider preview builds. More information about the Windows Insider here.
Alternatively, you can use WSL 1 which does not require a Windows Insider preview build of Windows.
Navigate to your Windows Diagnostics & feedback settings: Windows Start button > Settings. Type Diagnostics & feedback settings into the search box.
Make sure the Full option is selected.
Restart your computer whenever prompted during the installation process.
To set up your Node.js development environment on WSL 2, you’ll first need to register with the Windows Insider Program so you can get Insider preview builds (required for WSL 2).
You’ll use your existing Microsoft account, or you can create a new one.
The registration and environment set up procedures are on the Microsoft website:
https://docs.microsoft.com/en-us/windows/nodejs/setup-on-wsl2
Use the information below to complete the procedures.
Install Windows 10 Insider Preview Build
- On the Insider settings screen, select Slow (ring) then select Confirm at the next prompts.
- WSL2 is broken on the current version of the Insider Build; the Slow option is a workaround.
(refer to the Microsoft website at the above URL for detailed instructions for the following):
Enable Windows Subsystem for Linux and Virtual Machine Platform
Install a Linux Distribution
Install WSL 2
Install nvm, node.js, and npm
Install your favorite code editor Although you can use other IDEs, GBA recommends Visual Studio Code (a.k.a. “Code”) because it has a number of extensions – including the Azure Blockchain Development Kit – that will make life tremendously easier.
Instructions to install Visual Studio Code and the Remote-WSL Extension are described here: https://code.visualstudio.com/remote-tutorials/wsl/getting-started
Note that the command for running VS Code from a Powershell WSL terminal is code.exe
, not just code
as stated in the instructions at link above.
On a Linux machine, use the following Code installation instructions written for and tested on Ubuntu 18.04 and Ubuntu 16.04:
-
Make sure you are logged in as a user with sudo privileges.
-
Update the packages index and install the dependencies.
sudo apt update
sudo apt install
software-properties-common apt-transport-https wget` -
Import the Microsoft GPG key.
wget -q https://packages.microsoft.com/keys/microsoft.asc -O- | sudo apt-key add -
-
Add the VS Code apt repository.
sudo add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main"
-
Install the latest version of Code.
sudo apt update
sudo apt install code
You can now launch VS Code either from the command line (type code
) or you can click on the VS Code icon (Activities -> Visual Studio Code).
If you are using Code on a Windows machine, it is always necessary to be aware whether you are currently in a WSL Code window or a Windows Code window.
The way to tell is to look in the lower left corner.
If it doesn’t say WSL: UBUntu-18.04 next to the “Open a remote window” icon then you are in a Windows window.
- To switch to a WSL window, click on the icon
and select Remote-WSL: New Window from the top of the dropdown that appears at the top of the screen.
- To switch back to a Windows Code window, click on WSL: UBUntu-18.04
and select Close Remote Connection from the bottom of the dropdown that appears at the top of the screen.
The Azure Blockchain Development Kit simplifies how you create, connect to, build and deploy smart contracts on Ethereum ledgers
-
Open Code from a Linux prompt and ensure that you are in a WSL window.
-
Click on the Extensions icon (the fifth icon in the left-hand toolbar)
-
Type “Azure Blockchain” in the Search Extensions in Marketplace search box and click on the green Install button to install the Azure Blockchain Development Kit for Ethereum extension. It will also install Azure Account and Solidity.
- Click on any of the Reload Required buttons to restart Code.
-
From within Code, open the command pallet:
Press Ctrl + Shift + P, or from the top menu, select View > Command Pallet.
-
Select Azure Blockchain: New Solidity Project.
-
Wait a few seconds and you will likely see that you are still missing the required apps: Python 2, Truffle Suite and Ganache CLI.
- Close Code
-
Open a Linux shell prompt and issue the following commands to install Python.
sudo apt install python-pip
sudo apt install python2.7
-
Reopen Code and repeat the Command Pallet sequence in Step 5 above to view the pre-requisites again. You will see that Python is now grayed out.
-
Click on the Install Truffle Suite button and wait until the Installing Truffle Suite message in the bottom status bar disappears.
-
Click on the Install Ganache CLI button and wait until the Installing Ganache CLI message disappears.
-
Close Code.
-
Test Ganache issuing the following command from a Linux Shell prompt:
ganache-cli –deterministic
-
MetaMask must be running on the development network (Localhost 8545) for Ganache to produce blocks. You can pause and un-pause Ganache’s block production by pressing Ctrl + S and Ctrl + Q respectively. Note that Ganache creates 10 wallets with 100 ETH when it starts.
-
Import one of the Private Keys into MetaMask. You’ll need the Ethereum for gas later.
-
Close Ganache.
Install the OpenZeppelin CLI globally by issuing the following commands at a Linux Shell prompt:
npm init –y
npm install @openzeppelin/contracts-ethereum-package
npm install @openzeppelin/upgrades@^2.5.0
This above command will most likely have errors. Ignore them.
sudo apt-get install build-essential
npm install -g @openzeppelin/cli
This above command will most likely have errors. Ignore them.
You’re all set!