How to install Truffle & TestRPC on Ubuntu or Windows 10 with “Windows subsystem for Linux”

I previously wrote how you can install Truffle & TestRPC on a windows machine, by using the Windows installers for Node & npm.
However I have found it is a much nicer experience to use the Windows Subsystem for Linux which provides a native Ubuntu shell with bash, which allows me to run all the Linux tools natively without issues. These install steps will work on an Ubuntu machine as well.

Prerequisite if running on Windows

  1. Enable Windows subsystem for Linux.

    Follow this short guide on how to enable it https://msdn.microsoft.com/en-us/commandline/wsl/install_guide

    image

  2. After following the steps in the guide above. Simply start the Ubuntu bash shell

    image

 

Install steps

(

# Takes a clean Ubuntu image, up to being Ethereum dev ready.
# installing npm from official repo
https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions as Ubuntu default apt-get has a very old version (NodeJS v4.1)
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash –
sudo apt-get update -y && sudo apt-get upgrade -y

# install system basics
sudo apt-get install -y build-essential nodejs

# upgrade node/npm/npx and then install dev tools
sudo npx dist-upgrade
sudo npm install -g ethereumjs-testrpc truffle

# fix up permission issues. npm5 creates these as root, so user can’t modify by default
sudo chown -R $(whoami) ~/.npm
sudo chown -R $USER:$(id -gn $USER) ~/.config

)

now you should be able to create a folder, go into it and run `truffle init` to create a new project template.

imageimage

 

Additional things to do

Now that your machine has it installed, I recommend you follow my other guide to get Visual Studio code configured for Truffle development.

Advertisements

Build 2017 keynote day 1

Highlights:

My main takeaways:

  • serverless computing and the CosmosDB are going to allow you to quickly create new ultra scalable applications.
  • AI, cognitive services and Cortana skills will allow you to build some real Sci-Fi things.
  • Microsoft graph is improving and adding more features that will allow you to build more personal apps.

Continue reading

Videos and notes of my Blockchain presentations at Microsoft Ignite Australia

As I previously mentioned, I was scheduled to deliver 2 talks at Ignite Australia. The talks both went well, and I’ve been getting a lot of great feedback about them. Now that the dust has settled and the content is all online I thought I should share the media to make it easier for other to watch and learn from them.

Saved image from Tweetium

Blockchain 101 & Azure Blockchain as a Service

Chris Zhong & I covered off an introduction to Blockchain 1.0 & 2.0. Covering off how Blockchain 1.0 technologies like Bitcoin are able to store state. But the rise of Blockchain 2.0 technologies like Ethereum, is what has gotten people’s attention as they are able to store state and embedded logic within “smart contracts”. I had heaps of fun with this session as I spent days putting together a scenario showing how multiple DApps (Decentralised Apps) could be linked together via on chain smart contracts, to build up an ecosystem of Blockchain apps that are able to leverage each other seamlessly.
A thanks to Chris Zhong for putting together and presenting the section on “Azure Blockchain as a Service”.

image

image

 

Blockchain Development on Azure Blockchain as a Service

Going into Blockchain development blind can leave you stumbling around on the net not knowing where to even begin to look. The purpose of this session was to take the knowledge I’ve picked up from doing Blockchain projects, and the months and months I’ve spent replacing and refining tools down to the easiest development experience, and distil it down for the audience. It was an awareness session “these are all the tools, here is why I use these ones, this is how you create a skeleton of a Blockchain app, interact with it, test it, etc.”. It wasn’t as clean as I would have liked, and subsequent repeat presentations have been smoother, but it is still a great starting point.

RegHack Downunder–Regulatory Blockchain hackfest in Melbourne Australia May 12-14

UPDATE: The event has finished, I have an event writeup available  https://davidburela.wordpress.com/2017/05/15/reghack-down-under-event-roundup/

RegHack details

I’m helping support a 3 day Blockchain regulatory hackfest here in Melbourne Australia on 12-14 of May https://reghack.org/
It is for companies working in the financial & energy sectors. There will be officials from government and regulators there able to answer questions on the day, allowing companies to quickly test out ideas during the event. We are inviting all companies that may have an interest in it (such as banks, financial institutions, energy distributors).

We encourage anyone interested to register and attend. You can either form a team with your workmates before you come along, or join up with people on the day to form a team.

Training events

Throughout the 3 weeks before the event, we’ll be running a series of 3 sessions in conjunction with the Ethereum Melbourne Meetup.

Week 1:

Thursday 27 April
What is a hackfest, how best to prepare for it https://www.meetup.com/Ethereum-Melbourne/events/239404213/

Week 2:

Tuesday 2nd May
Introduction to Ethereum workshop https://www.meetup.com/Ethereum-Melbourne/events/239097996/

Wednesday 3rd May
This is the session I will be running. Showing how to set up your dev environments with Truffle, TestRPC & an Azure BaaS Ethereum testnet https://www.meetup.com/Ethereum-Melbourne/events/239404235/
Week 3:

Wed 10 May
solidity master class https://www.meetup.com/Ethereum-Melbourne/events/239404253/

I’m delivering two talks at Microsoft Ignite Australia on Blockchain development

I’m excited to be delivering 2 talks at Microsoft Ignite Australia this year, both of them are on Blockchain development. I’ll be able to share my experience so far with developing solutions on the Blockchain with some of our customers.

Blockchain 101 & Azure Blockchain as a Service

https://msftignite.com.au/sessions/session-details/2485/blockchain-101-azure-blockchain-as-a-service-cld213
You keep hearing about the Blockchain, but do you really understand what it is, and the potential impact it will have on practically all industries? Join us as we cover: What the Blockchain is, Some scenarios showing potential use cases to put it into context, and then how Azure Blockchain as a Service can help you get started today.

Blockchain Development on Azure Blockchain as a Service

https://msftignite.com.au/sessions/session-details/2484/blockchain-development-on-azure-blockchain-as-a-service-cld424
This deep dive session will show the frameworks and tools you can start using today to develop Blockchain based applications and smart contracts. Then how to use the Azure Blockchain as a Service to configure a private consortium, or development Blockchain environment. This is a level 400 session, it is HIGHLY recommended that you attend the Blockchain 101 session before this. I’ll be utilising the Truffle framework http://truffleframework.com/

 

 

Meetup Madness & Kids coding open to all at Microsoft Ignite pre-day

Microsoft Ignite is just around the corner. But there are some events that are open to all if you happen to be on the Gold Coast.

MeetUp Madness

Microsoft is proud to bring together 7 technical communities from all over Australia to host MeetUp Madness.  Join likeminded professionals in an informal gathering talking all things tech. Topics will cover SQL, Cloud/Azure, .NET, Xamarin X-Platform development, Office 365, SharePoint, Data Science and Infrastructure. Take the opportunity to learn something new, meet those with similar interests and it wouldn’t be a MeetUp without pizza, beverages and swag. This event is open to everyone and all are welcome. All MeetUps will be held concurrently, so choose one that takes your fancy and RSVP at https://www.meetup.com/en-AU/Microsoft-events-in-Australia/

Magikcraft Kids Coding: Can Garry Pottr save the world from the Zombie Apocalypse? 

Microsoft is partnering with BizSpark Startup Magikcraft to host a kids coding event on Monday 13th February at the Gold Coast from 4-6pm.  Using Minecraft, kids will learn to craft JavaScript spells and join the hero of the Magikcraft universe, Garry Pottr, as he versus the Zombie Apocalypse to save the world.  Kids aged 8 -14 will learn how to cast lightning bolts, fly through the air, and finally face the Zombie Horde.  As well as a fun way to learn to code, this is an actual, legit, official Guinness Book of World Records event.  We will be setting the world record for the most Zombies killed by JavaScript lightning in a period of ten minutes.  Places are limited, so get in quick and register now. https://www.eventbrite.com/e/magikcraft-zombie-apocalypse-learn-to-code-set-a-world-record-tickets-31439588656

Also – Here’s details of the Zombie Apocalypse Leader board (using Azure functions) which will be displayed during the event: https://twitter.com/sitapati/status/826531378049060866

Ethereum DevOps with Truffle, TestRPC & Visual Studio Team Services

UPDATE 2017/09/07:
Consider this post deprecated. I have written a new much simpler guide https://davidburela.wordpress.com/2017/09/06/ethereum-devops-with-vsts-easier-now-with-new-truffle-installer-npx/

I have been working on automating the compilation and testing of Ethereum solidity contracts, via the use of Truffle. I’ve got the test results being published back into the portal, allowing me to see on each commit if my code still compiles and passes my tests.

image

I’m assuming you already have a Truffle project locally that you want to automate the continuous builds & testing on. Follow my tutorial on installing Truffle & TestRPC on Windows.

My final system will allow you to run “truffle test” locally to see standard test output, but will modify the test runner on the server to output it as JUnit format.

The Build system

The system uses the Visual Studio Team Services (VSTS) build engine to automate this. You can sign up for free, and get unlimited private Git repos.
You can have the code hosted on any Git provider. So either within VSTS itself, or GitHub, BitBucket, etc.

Prepare truffle.js

A pre-step is to define the  test section in the truffle.js file

mocha: {
reporter: “spec”,
reporterOptions: {
mochaFile: ‘junitresults.xml’
}
}

image

Create a build agent

VSTS does provide hosted build agents, which are generic and can build standard .Net projects, Xamarin, etc. But because we are going to use npm packages installed globally on the box to handle the Truffle builds

  • Create a new Windows VM (Can be your own hosted server, or Azure).
    e.g. Windows Server 2016 Datacentre edition on Azure
  • Install the VSTS build agent. Instructions at https://www.visualstudio.com/en-us/docs/build/admin/agents/v2-windows
    Note: DON’T select to run service as NT AUTHORITY\NETWORK, this will not work with TestRPC (needs to open ports).
    Run the service as another user, or NT AUTHORITY\SYSTEM
  • Install chocolatey
    https://chocolatey.org/install
  • Install these chocolatey packages
    • choco install git -y
    • choco install nodejs.install –
  • Install npm packages (make sure you open a new PowerShell window so that node is in your path)
    • npm install -g npm
    • npm install -g –production windows-build-tools
    • npm install -g ethereumjs-testrpc
    • npm install -g truffle
    • npm install -g mocha
    • npm install -g mocha-junit-reporter
  • Restart the build agent so that all new paths are working

Configure VSTS build

    • Create a new variable with the path to where the npm global path is, for the user you installed the npm packages on above
      variable name: npm.path
      variable value: path to npm packages e.g. C:\Users\<user>\AppData\Roaming\npm
      image
    • Add 7 PowerShell tasks, and configure them like this
      • Name: System version information
        Script:
        #Setting environment paths
        $ENV:Path = $ENV:Path + “;” + $env:npm_path
        npm config set prefix $env:npm_path    #only needs to be set once, will update for user
        #DEBUG
        #$env:path
        #npm list -g –depth=0
        #Display system information
        Write-Host “System version information”
        Write-Host -nonewline    “node version: ” ; node -v
        Write-Host -nonewline    “npm version: “; npm -v
        Write-Host -nonewline    “npm prefix: “;  npm prefix -g
        Write-Host -nonewline    “truffle: ” ;    truffle version
        image
    • Name: Config transform & test clean
      Script:
      # remove old test results
      rm .\junitresults.xml -ea SilentlyContinue
      # Modify the Truffle test runner to use the JUnit reporter
      Rename-Item .\truffle.js .\truffle_temp.js
      cat .\truffle_temp.js | % { $_ -replace ‘reporter: “spec”‘, ‘reporter: “mocha-junit-reporter”‘ } | Out-File -Encoding ASCII .\truffle.js
      rm .\truffle_temp.js
      image
    • Name: Truffle build
      Script:
      #Setting environment paths
      $ENV:Path = $ENV:Path + “;” + $env:npm_path
      #Truffle build
      truffle compile
      image
    • Name: Launch TestRPC
      Script:
      #Setting environment paths
      $ENV:Path = $ENV:Path + “;” + $env:npm_path
      # launch the process
      echo “launching TestRPC”
      $testrpcProcess = Start-Process testrpc -passthru
      # persist the PID to disk and display in logs
      $testrpcProcess.Id | Export-CliXml testrpcPID.xml
      cat testrpcPID.xmlimage
    • Name: Run Truffle tests
      Script:
      #Setting environment paths
      $ENV:Path = $ENV:Path + “;” + $env:npm_path
      # Run the tests
      truffle test
      image
    • Name: Shutdown TestRPC
      Other Settings: Enable “Always Run” (to make sure it is shutdown if there is an error)
      Script:
      #Setting environment paths
      $ENV:Path = $ENV:Path + “;” + $env:npm_path
      # retrieve the PID and kill the entire processs tree
      cat testrpcPID.xml
      $testrpcPID = Import-CliXml testrpcPID.xml
      taskkill /pid $testrpcPID /F /T
      image
  • Add a new Publish test result
    • Test Result Format: JUnit
      Test Result Files: junitresults.xml
      image

 

Future work

Things that I would like to add in the future:

  • Figure out how to automate this on a Linux build agent (VSTS supports both Windows & Linux based build agents)
  • Automate Release Management to run “truffle migrate” to push to a Bletchley test environment