Ethereum Development On Windows

Andy Watt
edgefund
Published in
9 min readMay 2, 2018

Getting to grips with developing Dapps for Ethereum was a lot of fun, but it was also fairly challenging. There seems to be an endless number of tools out there, and stitching them together into a coherent development experience is not a straightforward task.

With a good amount of reading, and after following a few dead ends, I think I’ve finally managed to settle on a pretty good toolbox for developing smart contracts on a Windows environment. In this series I’m going to start by going through all of the steps required to configure a fresh Windows 10 install for Ethereum development. The first few posts will simply describe the tools that I’ve chosen to use, and how to install and test them. Once the toolbox is installed and configured, I’ll move onto describing how to use them.

My hope for this series, is that prospective Ethereum developers can start here and follow my footsteps to quickly have a decent development setup, and then get straight to the fun part - developing new and cool decentralised applications!

This post, and the rest of the series will assume very little prior knowledge or experience with the Ethereum specific tools that are being used. I will assume a certain amount of understanding on general blockchain concepts, and past experience in some form of programming. Knowledge of development practices like source control, testing, and debugging will also be assumed.

Environment

I come from a background in corporate applications development with C# and Visual Studio. So it was quite a jarring change moving from Visual Studio to the relative ‘Wild West’ that Ethereum development was a year or so ago. Things have moved on significantly in recent months, but the rich (hand-holding) experience we get from Microsoft’s tooling is still not quite there.

That said though, it is still entirely possible to set up a ‘professional’ development environment. That is what I’ll be describing in the rest of this post.

Requirements

The key features that I look for in a development environment are:

  • A decent code editor
  • Source control
  • Unit tests
  • Debugging

The code editor that I have settled on is Visual Studio Code. This decision was obviously influenced by my .NET background, and familiarity in Microsoft environments. But, I really do believe that VS Code is an excellent tool for this job.

VS Code integrates very well with Git for source control. Git is currently the undisputed king of source control, and so is the obvious choice for this task.

Unit testing any code is vitally important, but when that code controls access to valuable assets, the testing takes on even greater importance. Additionally, testing code that is written for execution on a blockchain is not quite as straightforward as it might first sound. I will elaborate more on blockchain-specific code testing in a later post. I have used the Truffle Framework to manage running the unit tests. This works well with VS Code, and comes with a number of cool features built in to make your testing-life much easier.

The last aspect of the environment that I want to configure, is a method for debugging the code. When I got started with Ethereum in 2017, there was really very few options for inline debugging. Remix was (and still really is) about the best of the lot for debugging. In recent releases the Truffle suite has added some debugging support. For the time being, I am happy to use the Truffle debugging features, although this is still an area of frustration for me. I’m hoping that the tools around this will mature quickly over the next few months.

Install the packages

The next few sections will go through installing and configuring the tools described above. This tutorial starts with a completely fresh Windows 10 install, and builds everything up from there.

The first step is to install Chocolatey. Start by opening a PowerShell window with administrator rights (right click, ‘run as administrator’). In PowerShell, type:

Set-ExecutionPolicy Bypass

When prompted, press ‘A’ to accept the elevated privileges. Chocolatey can now be installed by entering:

iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

You’ll need to close, and then reopen PowerShell, again, run as administrator. With that done, Chocolatey can be used to install the other tools that are required. Enter the following into PowerShell:

choco install visualstudiocode -y
choco install git -y
choco install nodejs -y

This installs the IDE (VS Code) and the source control framework (Git), setting up the very basics of the dev environment. Node.js is also installed at this stage, and npm (Node Package Manager) is used to install some additional packages.

You need close and re-open PowerShell again at this stage.

With Node.js installed, use npm to install the truffle framework. Run the following commands in Powershell:

npm install -g truffle

A quick status check

At this stage, the environment is more or less set up for some basic Ethereum dev. Easy when you know how!

Check that the installs have completed correctly by checking the version of the packages. Type into PowerShell:

node -v
npm -v
truffle --version

The output should look like the image below. Note that these products are upgraded frequently, and the version numbers are unlikely to match. I’d recommend trying the latest version, and if there are any issues, then revert to the versions shown below.

Configure Visual Studio Code for Ethereum Development

At this stage, all of the required packages are installed, and it is possible to use notepad and command line tools to do everything required… but that’s not really what I was aiming for. In this section. I’ll get Visual Studio Code configured and ready for Ethereum development.

We’ll use one of the Truffle Framework ‘boxes’ to show that we have everything configured correctly, without having to write any code ourselves — we’ll get to that later.

Choose which folder you want to be the root for this project, and navigate there with PowerShell. Then execute:

mkdir TruffleTest; cd TruffleTest; code .

The final command in the chain is “Code .”, which opens an instance of Visual Studio Code in the folder from which the command is executed.

Install the solidity extension for VSCode as shown (steps 1,2,3,4 shown):

Then install the Material Icon Theme, following the same process as for the Solidity extension.

From now on, we’ll use the VS Code integrated PowerShell terminal. Open the terminal by clicking Ctrl+` or Ctrl+’. (If PowerShell is not the default, see here for instructions on changing)

Getting Started with Truffle

The Truffle Framework provides ‘boxes’, which are basically pre-packaged examples to get started with. These are a great way to play with the Truffle functionality, and also provide a really quick way of testing that everything is set up correctly. In the VS Code terminal, type:

truffle unbox metacoin

The output from the console should look like this:

The files for the Truffle MetaCoin example have been downloaded. The end result should look like this.

Before we proceed, it’s worth having a dig around in this code.

The main application code is written in Solidity in the file ‘MetaCoin.sol’. This relies on a helper library called ‘ConvertLib.sol’. These files will be compiled and deployed to a simulated blockchain using Truffle.

Truffle provides a unit testing framework, and this sample comes with a couple of test classes, in the ‘tests’ folder. Examples written in Solidity and JavaScript are provided. These will be run through the Truffle testing framework shortly.

Compile the Contracts

We will compile the MetaCoin example. Simple type into the console

truffle compile

The console output should look like this:

You will notice that a ‘build’ folder has been added to the list of files, which contains the compiled json files.

What we have achieved here doesn’t seem very impressive. But, we have just compiled our first Dapp! Well done!

Deploying the Contracts

Now we need to migrate the contracts to a test network. In this case, that will be the truffle development environment, that is packaged with truffle.

The ‘develop’ command enters the Truffle development console environment. This will set up a kind of dummy blockchain, that operates similarly (but not identically) to the real Ethereum blockchain, and allows us to test deployment and execution of the code without needing to interface with an actual blockchain. This is ‘step one’ of testing your code .

Type into the console:

truffle develop

to get the following output:

This command has launched the truffle development environment, automatically configured with 10 accounts and keys. (More on why this matters later). For now, it suffices to say that this allows contracts to be deployed into this testing environment. Note that the addresses on your screen will differ from the above.

The code has been compiled, and Truffle console is now running. To deploy the compiled contract to the Truffle environment, simply type:

migrate

This will deploy the contracts to the test environment. The output should look like:

Again, it’s not totally obvious what has happened here — don’t worry, there will be further explanation in a coming post. The code that we compiled in an earlier step has been successfully deployed to a simulated blockchain. This allows us to run the unit tests, from the ‘test’ folder.

Testing the Contracts

The last thing to do at this stage is to make sure that the Truffle tests can be run. Simply type:

test

The unit tests will run, and hopefully pass.

To exit the truffle console, type ctrl+D

Again, that doesn’t look like much, but a lot is going on behind the scenes. The Solidity code that we compiled in the first step has new been deployed to a simulated blockchain, and a set of unit tests have been run.

What’s Next

This tutorial has taken us from a completely fresh install of Windows 10, to an operational environment for Ethereum development. We have downloaded, compiled, deployed, and tested a Dapp.

This is a good place to wrap up part one of these tutorials. In Part 2, I will complete the environment set up by covering debugging smart contracts, and integration with source control.

This stuff is not particularly complicated, but I found it tricky to piece it all together. I hope that this post, and the coming series is useful to some folks out there. Any comments or suggestions, please feel free to leave a comment.

Thanks for reading!

I am currently working on EdgeFund, an open-source platform which offers a decentralised shared bankroll on the Blockchain. To learn more about EdgeFund, please visit our website or join our telegram group to chat to the team and be sure to follow us on Twitter!

--

--

Andy Watt
edgefund

Technical Lead and co-founder at Avalone Consultants. Angular, .NET, and blockchain developer.