Blockchain Development - Setting Up Development Environment For Smart Contracts - Part One

Introduction

In my last article on Blockchain, we learned about setting up Ethereum Blockchain on Microsoft Azure using Consortium leader. It is time for some development now. Before we move on to Smart Contracts and their development, it’s important for us to set up a development environment as a prerequisite. This article will solely focus on setting up the development environment for Smart Contract development. In the next article, we’ll see what smart contracts are and how we can develop those.

Blockchain
Image credit: https://pixabay.com

 

Tools and Development Environment

We’ll use a list of tools to set up our development environment before we proceed with actual development. I’ll use a fresh Windows installation on Microsoft Azure. You can follow the steps to set up a VM on Azure or can refer to my article on Setting up VM on Azure before we actually start. We’ll install Chrome browser on the fresh machine followed by MetaMask that is a Chrome plugin which will help us in authentication. Microsoft provides Visual Studio code, that is absolutely free and we can use that as a development IDE for our smart contracts development.  We’ll install NuGet Package Manager (NPM) and Chocolatey; i.e., also a package manager to get other tools and packages needed for development. We’ll use Git along with NPM and Windows build tools for the purpose of building/compiling the code. We’ll use an in-memory test server known as Test RPC to test the application and lastly, Truffle. We’ll explore more about Truffle when we start development.

Creating VM on Microsoft Azure

Blockchain

 

Azure

Azure is a cloud platform from Microsoft and provides numerous resources in the context of cloud computing. One of the resources is virtual machine; i.e., a fully functional machine of your choice with the choice of your configurations and operating system could be created within seconds with just a few clicks and you can access the machine remotely from anywhere with your secure credentials and do whatever you want for e.g. hosting your website, developing applications, creating production or test environment for your software etc. Let’s see step by step how we can achieve that.

Azure Account Setup

If one does not have a paid Azure account, one could leverage Azure’s new account’s benefits of giving $200 credits. That means if you are new to Azure and want to play around with its free trial, you’ll get $200 credits that you can use to explore Azure. If you are new to Azure and do not have an account, follow the following process; else, directly log in to your portal.

  1. Open the Azure web site i.e. azure.microsoft.com

    Blockchain

  2. Click on Start free to create your free Azure account and get $200 as credits.

    Blockchain

Creating an account and claiming $200 would need your credit/debit card for verification purposes only and will not deduct any amount from your card. You can play around with this credit and account for 30 days. You’ll see the signup page, where you fill all your information and signup step by step. Once signed-up successfully, you’ll see the link to the portal as shown below.

Blockchain

 

Click on the portal and you will land up on the dashboard and are ready to use/play around with Azure.

Blockchain

Virtual Machine Setup on Azure 
  1. Once on the dashboard, click on the “Virtual machines” link on the dashboard and a right panel would open where you see all your VMs. Since we are creating new and we do not have existing ones, so it would be blank. Click on “Create virtual machine”.

    Blockchain

  2. Once you click on “Create virtual machine”, you’ll get to see all the operating systems and solution templates that Azure provides to create a machine. You can choose to have Windows or Linux operating system based on requirements, but be careful about costs involved.

    Blockchain
  1. Since this article is for learning how to create a virtual machine, I’ll choose the Windows client machine with minimal machine configurations, one can choose based on requirements and need. So, choose “Windows Client” as shown in the following image.

    Blockchain

  2. You’ll get the window of the license agreement and legal Read that carefully and press “Create button”.

    Blockchain

  3. After clicking Create, you’ll be asked to fill outsome basic requirements as shown below. Give the name as per your choice, for e.g. I gave it “AKHILPC”, leave VM disk type as SSD, or choose as per your need. Provide username and password you would be needing when you connect remotely with the machine. Keep the username and password safe and secure. Choose the subscription, if you have a paid one, choose that else choose the trial subscription that you got. You must provide a resource group. You can create a new or use an existing one. Resource Group gives you a logical separation of all your Azure resources. Since I have an existing resource group created, I am using that. Choose Location, click on confirmation checkbox and click OK.

    Blockchain

  4. Once you click OK, you get to see the second section to choose the size of the machine where you see the list of RAMs, Hard disk size, SKU, and zones. Each configuration has a cost associated with it so choose as per your need and budget. For training/tutorial purposes I am choosing the first one that has the minimum cost as shown below.

    Blockchain

  5. In the third step, you are needed to choose certain settings related to availability, storage, and network. Choose/Provide the settings as per your discretion.

    Blockchain

  6. Once you click OK, you’ll be shown a summary page for all the configurations you choose, cost per hour and OS. Give confirmation if everything looks good by clicking on confirmation checkbox as shown in the below image and click on Create button.

    Blockchain

  7. Once you click Create, it may take a while to create your VM. It will say “Submitting deployment for…”. Wait till the deployment is complete. For me, it took 5~9 minutes.

    Blockchain

  8. Once deployment is done, you’ll see the section for your deployed VM, where you can choose to Start, Stop, Restart, Move or Delete your created VM. Clicking on Connect will show you two options in the right panel i.e. RDP and SSH. We’ll choose to connect via RDP, so download the RDP file shown at the right panel. Click the blue “Download RDP file” to get the file. Alternatively, you can directly open RDP connect via an mstsc command on your local machine. You get the IP address as shown below in RDP section.

    Blockchain

  9. The downloaded RDP file will be located at your local download location. Click on that to configure RDP connection.

    Blockchain

  10. The IP would automatically be filled, just fill the username and password to connect.

    Blockchain

  11. Once connection is successful, you’ll see the Welcome message while the window loads and configures for first-time use. Please wait for a while.

    Blockchain

  12. Once Windows has loaded, you’ll see the desktop as shown below. Now you can choose to do whatever you want with this machine.

    Blockchain

Note that for the time you use a machine, you’ll be charged hourly. In case you do not want to use the machine for some time or stop the machine daily at the defined time, you can do that manually by clicking on Virtual Machines option at your Azure dashboard. You’ll see your VM. Select your VM and click Stop. You can Start whenever you want. Thus, you can save a lot of costs.

Blockchain

 Moreover, by clicking on your select VM, you can monitor its hourly/daily usage statistics as shown below.

Blockchain

See how easy it was to set up a VM on Azure with just a few simple clicks? Now, you do not have to depend on any physical machine to do your job.

Step by Step Installation of Tools and Packages

As described by me in the earlier section, let’s start with step by step installation of other tools and packages.

  1. Install Chrome browser - The very first step is to install the Chrome browser. Download the Chrome browser.
    Blockchain

    Read Google terms and services and install it on the fresh machine that is just created.

    Blockchain
  1. Now we have to install MetaMask i.e. a chrome plugin that will help us in authentication and testing. Download MetaMask from GitHub from the following URL: https://github.com/MetaMask. As shown in the image below, choose metamask-extension link shown in pinned repositories and click it.

    Blockchain
  1. I have chosen the version 4.7.4, you may see a newer stable version when you try to download that. Download the chrome plugin by clicking on the link metamask-chrome-4.7.4.zip as shown in the following

    Blockchain

Unzip the downloaded zip file to any location on windows.

Blockchain

 

Now, open Chrome extension settings by typing following URL in chrome: chrome://extensions. Switch on the developer mode as shown in the following image and click on LOAD UNPACKED i.e. to load the unzipped downloaded extensions.

Blockchain

 

Now navigate to the folder where the MetaMask chrome extension was unzipped and choose that root folder as shown in the following image.

Blockchain

 

As soon as you click OK the extension will be loaded Chrome and you’ll see the MetaMask home page that confirms the extension is now part of chrome browser. You’ll see a fox icon at the top right of chrome as an extension. Now you can go back to chrome extensions page that we opened earlier and disable the developer mode that we enabled while loading the unpacked extension.

Blockchain

 

  1. Time to download Visual Studio code i.e. the IDE that helps us in development. VS Code is widely accepted and a lightweight free IDE provided by Microsoft for development. Navigate to the URL: https://code.visualstudio.com/. Download the latest stable build as shown in the following,

    Blockchain

    Once the executable is downloaded click on the same to install that. Read the license agreement and accept it and follow the instructions of installation setup to get visual studio code install on your machine.

    Blockchain
  1. Now its turn to download NPM i.e. Nuget Package Manager. Navigate to the URL: https://nodejs.org/en and download the latest released stable version that you see on the window. I am downloading 8.11.2 version of NPM as shown in the following image

    Blockchain

Click on the setup once it gets downloaded and follow the steps.

Blockchain

Keep all the settings as default and click on Next buttons until the setup is installed successfully.

Blockchain

Click on Finish once the setup is installed.

Blockchain

 

  1. Now, as discussed earlier in this article that we need one more package manager. Let’s install that as well i.e.” Chocolatey”. Chocolatey could be installed using PowerShell commands and we get the commands/scripts on the URL: https://chocolatey.org/. Go to the website and click on “Install Chocolatey Now” button as shown in the following image

    Blockchain

On the page where you land, scroll down to the section where you see subheading as “Install with PowerShell.exe”. Copy the script as shown in the red box in the following image. The script would be: Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) 

 Blockchain

Now open the PowerShell window from your windows start menu as shown below and run as administrator to launch the PowerShell command prompt.

Blockchain

The command prompt would look like as shown below.

Blockchain

Now paste the copied script to the command prompt and press enter.

Blockchain

Once Chocolatey commands and NuGet packages are in place, we’ll install GitHub client using install command of Chocolatey, this installs other useful tools that would be used while development.

So, type command: choco install git -params “/GitAndUnixToolsOnPath” in the command prompt as shown below and press enter.

Blockchain

The installer on command prompt will ask to run the script for allowing Global Configuration. You can type “Y” for yes and press enter to allow it.

Blockchain

Now close and re-open the power shell window to ensure everything is installed properly.

Blockchain

Let’s now execute some commands as follows,

    • Turn of all calls secure feature in Git: git config –system http.sslverify false

      Blockchain

    • Install node add on build tool via NPM: npm install -g node-gyp

      Blockchain

    • Install windows build tools: npm install –global –production windows-build-tools

      Blockchain

Installing windows build tools will take some time so be patient and in the meanwhile have something to eat if you like.

Blockchain

 

  1. Install Test RPC that is the local Ethereum server for testing our solution: npm install -g ethereumjs-testrpc

    Blockchain
  1. Lastly, we install the Truffle toolset: npm install -g truffle

    Blockchain

Now we are good to start our development as our tools and software are well in place and our development machine on Azure is up and running. Yes, it was a lot of work to setup the environment and tools, but don’t worry, it will be fun to develop and learn these new tools and technologies.   

References

Conclusion

In this article, we learned how to setup the development environment to start development. We came across various packages like NPM and Chocolatey that helped us to install more tools. We installed VS Code, MetaMask which will help us to provide coding environment. I have specially provided all the scripts in this article in text form and not an only image so that it is easy for you as a reader/developer to copy and execute. In my next article, we’ll focus on Smart Contracts and development. Cheers!