[Windows Installation] Git VsCode NVM Nodes Ganache Truffle

:warning: Work in progress , this post is full of typo and not done yet :warning:

The purpose of this post is to help you to setup your developer environment on Windows.

Do not get afraid by the size of this thread there is a lot of pictures.
The goal here is to make you gain a lot of time, if you start from 0 you will probably spend
30 minutes / 1 H setting up all this tools. But it will make you save a lot of painful hours of debugging

I start this tutorial with a machine with 0 tools installed, so if you follow it step by step you will have a clean environment, you will learn many things and you will have 0 Bug.

  1. Set the correct authorization on you windows system
  2. Download and install Choco (package manager)
  3. Install easily All the packages you need
  4. Install your tools related to blockchain development
  5. Test applications :warning: WIP
  6. Troubleshooting :warning: WIP

Set the correct authorization on you windows system

1.First step launch powerShell with the administrator right

A prompt will show up

Verify that you have the correct permission, windows check if the script has a valid signature.
Type the following command to check the permission

Get-ExecutionPolicy

In my case it Unrestricted, you can change it to Allsigned with the following command

Set-ExecutionPolicy AllSigned

Press Y for yes

If you have an error look at this othewise go to step 2

If you have this error it’s because a rules has been set at a higher level

Type the following command

Get-ExecutionPolicy -list

As you can see the MachinePolicy have more importance than the LocalMachine so you need to change it.

To do it type the following command

Set-ItemProperty -Path HKLM:\Software\Policies\Microsoft\Windows\PowerShell -Name ExecutionPolicy -Value ByPass

PWD my sys Admin :nerd_face: :fu:


Download and install Choco (package manager)
  1. Download choco

Choco is a package manager it will allow you to install package with the command line, it’s like apt, yum for linux distribution.

The installation script for choco is located in an https url, so you will have to set windows to use the last version of TLS. By default it’s using TLS 1.0 so we ll force windows to use the last version with this command.

[Net.ServicePointManager]::SecurityProtocol = "Tls12, Tls11, Tls"

You need to install choco in your user directory, by default you are located in the system32 folder which is a really bad place to install program

type the following command

pwd #this will show you where you are located

then

cd $env:userprofile\Desktop # to move to your user user Desktop

Now we are ready to download the installation script

type this command

Invoke-Webrequest -Uri https://chocolatey.org/install.ps1 -OutFile chocolatey-install.ps1

Then to make sure this is correctly downloaded type

cat chocolatey-install.ps1 | more

If you can see the readme as in my screenshot just type the letter

q

  1. Install Choco

Choco will recommend you to install the binary with the execution policy to Bypass.
But because i m a paranoid i ll run it with AllSigned.

Set-ExecutionPolicy  AllSigned -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

And Also because i m paranoid i ll type one hundred times R because i want to check when those scripts are used, but you can type A instead

After the installation you will have few warning don’t worry about it.

To make sure it’s installed successfully type the following command

choco list

You will have to upgrade all choco packages to make sure you are ready to go

choco upgrade all

Now restart your computer !


Install easily All the packages you need

Ok now as a developer you will need one package really useful GIT

If you think usb key or DropBox is the only way to share files this will change your life
Btw this is the best tutorial in the WORLD if you want to master git
https://learngitbranching.js.org/

Ok so let’s install git

choco install git 

Press A during the installation

When the installation is complete type

git --version

If you have this kind of message, restart your terminal

Three binaries are installed git git-gui.exe and git-lfs.exe
If you are not really familiar with git start with git-gui.exe , or do the tutorial linked above

image

Now we are going to install Node (we are close guys) here 2 options you can install node directly with choco or install it with nvm. I ll encourage you to use Nvm as you can change of node version when you want instead of installing multiples version of node in your machine.

  • Installation with Nvm

Now we will install nvm (Node Version Manager) nvm is really useful because you will not have to install multiples version of node on you machine, you will be able to change whenever you want.

choco install nvm 

Now check if nvm has been installed

If you have this kind of message, restart your terminal

Now you can choose the node version you need.
type

nvm list available

We will start with node 12.16.3 always choose an LTS version (Long Term Support)
Type

nvm install 12.16.3
nvm use 12.16.3

Make sure node is installed

node --version
npm --version


Install your tools related to blockchain development

Now we will install the required development tools for windows
type

choco install VisualStudioCode 

Now we will install the windows build tools

npm install -g -production windows-build-tools

Don’t worry the installation can take up to 5 minutes and your screen will look like this. It’s long but i promess you it ll be done before the end of this video

https://www.youtube.com/watch?v=ZO-ifNk9TIw&t=83s

  • Ganache

Ok now we will install ganache-cli , ganache allow you to run a local version of the ethereum blockchain . You will need it during the course , you can still install the GUI version here

https://github.com/trufflesuite/ganache/releases/download/v2.4.0/Ganache-2.4.0-win-x64.appx

But i like using my terminal.

Type

npm install -g ganache-cli

then verify

ganache-cli.cmd

  • Truffle

Well i wasn’t able to compile with an other truffle version than 4.1.17 so i ll recommend you to use this one , if you have found an other way let me know in this topic.

type

npm install -g [email protected] 

To verify create a directory first then initialize your truffle project

mkdir truffle_project
cd .\truffle_Project\
truffle init

If you have this issue try again

Solve after retrying let me know if you know why


Test applications
  • Test if “truffle compile” working

Ok now let’s try everything in one project.

cd $env:userprofile\Desktop #Go to your desktop
mkdir test_pet_shop #create a new folder
truffle unbox-pet-shop #pull a project already availble on truffle website

truffle compile

  • Test a basic test locally
git clone https://github.com/filipmartinsson/solidity-201.git
cd .\solidity-201\Testing Part 2\
rm .\build

If you have follow the tutorial vsCode is installed so you can type

code .

And you will see this windows

Otherwise open your favorite text editor and modify the following lines.

in truffle-config.js
line 45

     development: {
      host: "127.0.0.1",     // Localhost (default: none)
      port: 8545,            // Standard Ethereum port (default: none)
      network_id: "*",       // Any network (default: none)
     },

in Helloworld.sol change the first line

pragma solidity >=0.4.21 <0.6.0;

In an other terminal you will have to start ganache-cli
just type

ganache-cli

In your first terminal you can now test if the test is working

  • Testnet Ropsten

As truffle-hdwallet-provider is deprecated we will install the new version
Go into your project directory and install this version
type

npm install @truffle/hdwallet-provider
npm install fs
npm install path

Now you need to modify your truffle-config.js with the following code

const path = require("path");
const HDWalletProvider = require("@truffle/hdwallet-provider");

const fs = require('fs');
const mnemonic = fs.readFileSync(".secret.txt").toString().trim();

module.exports = {

  contracts_build_directory: path.join(__dirname, "client/src/contracts"),
  networks: {
    ropsten: {
       provider: () => new HDWalletProvider(mnemonic, `https://ropsten.infura.io/v3/PROJECT_ID`),
       network_id: 3,       // Ropsten's id
       gas: 5500000,        // Ropsten has a lower block limit than mainnet
       confirmations: 2,    // # of confs to wait between deployments. (default: 0)
       timeoutBlocks: 1000,  // # of blocks before a deployment times out  (minimum/default: 50)
       skipDryRun: true     // Skip dry run before migrations? (default: false for public nets )
    },
  },
  compilers: {
    solc: {
      version: "0.5.12",    // Fetch exact version from solc-bin (default: truffle's version)
    }
  }
};

We will use infura so you need to create an account here
https://infura.io/
Create a new project, in setting you will find your project id, replace the PROJECT_ID in the above config with your project id.

Create a file name .secret.txt and copy your metamask seed phrase

truffle migrate --network ropsten  --reset

Result


7 Likes

Nice! This will be very helpful. The command line can be rather intimidating for people starting to learn how to code, but once you get things set up it does make life much easier. It looks like Powershell has become a lot more useful these days. A few years ago I started using GitBash on my home system as this allows you to use the traditional linux commands in Windows.

  • Note if you install Node with the graphical installer from their website it will prompt you to install Chocolately (choco) so if you’ve done this recently you probably have it already

Infura looks like a really cool service as well. In their FAQ is a link to the Consensys Ethereum Developer Portal & Training, which also looks very useful.

Thanks Gabba!

2 Likes

Great link @mayjer ! I haven’t been on the consenSys site for a while, it’s crazy how many applications they are listing now …

When this topic will be done i will post all the command in one place.

Actually i didn’t know Chocolately has a graphical installer… lol it could be simpler. Can you choose your node version ? Many people have issue with their node version that’s why i wanted to use nvm.

Yeah i used GitBash too, but i switch to linux 6 years ago and i ll never go back to windows lol

1 Like

The Node installer does not come with NVM, though that would be useful. I installed NVM separately. The Chocolately install was done via a script initiated from the Node installer.

Funny story, I just installed Ubuntu yesterday because I needed to run Docker for the EOS101 course EOS Studio. Used my DVD burner for like the 2nd time in it’s life to create the boot disk :smile:

:sweat_smile:
I only use usb bootable keys, it’s more convenient.

1 Like

@gabba
I am still getting error

 PS C:\WINDOWS\system32> Get-ExecutionPolicy -list

        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser    Unrestricted
 LocalMachine       AllSigned


Set-ExecutionPolicy -Scope MachinePolicy -ExecutionPolicy Allsigned
Set-ExecutionPolicy : Cannot set execution policy. Execution policies at the MachinePolicy or UserPolicy scopes must
be set through Group Policy.
At line:1 char:1
+ Set-ExecutionPolicy -Scope MachinePolicy -ExecutionPolicy Allsigned
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Set-ExecutionPolicy], InvalidOperationException
    + FullyQualifiedErrorId : CantSetGroupPolicy,Microsoft.PowerShell.Commands.SetExecutionPolicyCommand

PS C:\WINDOWS\system32> Set-ItemProperty -Path HKLM:\Software\Policies\Microsoft\Windows\PowerShell -Name ExecutionPolicy -Value ByPass
Set-ItemProperty : Cannot find path 'HKLM:\Software\Policies\Microsoft\Windows\PowerShell' because it does not exist.
At line:1 char:1
+ Set-ItemProperty -Path HKLM:\Software\Policies\Microsoft\Windows\Powe ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (HKLM:\Software\...dows\PowerShell:String) [Set-ItemProperty], ItemNotFo
   undException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetItemPropertyCommand

PS C:\WINDOWS\system32> PWD my sys Admin
Get-Location : A positional parameter cannot be found that accepts argument 'my'.
At line:1 char:1
+ PWD my sys Admin
+ ~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-Location], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetLocationCommand

PS C:\WINDOWS\system32> Get-ExecutionPolicy -list

        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser    Unrestricted
 LocalMachine       AllSigned


PS C:\WINDOWS\system32>

You need to change the CurrentUser not the MachinePolicy every system is different i did that in my machine because the machinePolicy was set

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Allsigned
1 Like

Hello Gabba,
i still getting error

Hi @frivolous
You also need to set the local machine permission

Set-ExecutionPolicy -Scope LocalMachine -ExecutionPolicy Allsigned

Hi @gabba,
I sett local machine permission but still getting same error ?

@frivolous where did you download truffle ?

You can try to use the bypass execution policy instead if you are sure you did download it from a reliable place

Set-ExecutionPolicy -Scope LocalMachine -ExecutionPolicy Bypass

You can have a look a this post

Thank you @gabba !!!
You make my day :slight_smile:
Everything is fine and working !!!

1 Like

@gabba:

I followed all your instructions. But after all, It requires me to change to “pragma solidity 0.4.26” to be able to Migrate(?) Did I do something wrong?

In Remix, I added functions: “update” and “__callback” as instructed in filip’s video; After deploying to ropsten, I tried to run code in Remix, but it seems “latestNumber” can never wait for the value from __callback, it is zero all the times ?

Hi @tungtien

Sorry but i don’t understand what lastNumber you are talking about. Are you talking about the __callback called in the project using the provable api ?

You can change the pragma version at the top of your solidity files or in the truffle-config.js

1 Like

Sorry but i don’t understand what lastNumber you are talking about. Are you talking about the __callback called in the project using the provable api ?

Yes. @gabba, I will reply to you on this in the course forum…

You can change the pragma version at the top of your solidity files or in the truffle-config.js

But on @filip’s lecture all samples are in Solidity 0.5.12; Can’t we do the same as @filip to compile with 0.5.12 or higher?

@tungtien
Yes of course you can change the value in your .sol files and in the truffle-config.js for 0.5.12

2 Likes

When I change to pragma 0.5.12 , the error is like this:

You should use the version 0.5.X of provable api not the version 0.4.X

For example

2 Likes

Hi gabba,
THanks for providing above link. I have changed to that file, but it doesn’t solve the problem.
By the way, please check again the link provided by @filip below the video, the provableAPI.sol file is just an empty file!

@tungtien

The link is working for me

Can you share the error ? And push on git i ll check in the same

1 Like