There are very simple ways to install dependencies for developing dApps on Ethereum blockchain using Solidity on MacOS and Linux, but for Windows users it becomes a herculean task and most of the time you will encounter errors that will never get debugged. So if you have developed interest in the Ethereum platform and its governing language Solidity, you can follow these steps to install the required dependencies on your Windows machine and everything will work fine.
“This helpful guide will walk you through step by step to install Ethereum dependencies on Windows 10 and write your first Smart Contract on Solidity.”
The Ethereum ecosystem allows anyone to code and deploy smart contracts written in Solidity (its distributed application) that can be deployed on the blockchain using Ether “gas.” Those smart contracts can be used for developing a simple “Hello Word” message for your friends or an engaging full-fledged web platform hosted on IPFS or ENS.
You may find many tutorials talking about how to install Solidity on Win 10 to write smart contracts in Solidity on Windows but most of the time you run into problems even if you follow the tutorials from Ethereum’s official docs. You can follow this tutorial without any knowledge of any of the programming languages. You can test smart contracts on Remix IDE in your explorer if you want to experience it and build your simple Smart Contract. But to set up a proper Solidity environment on your Windows 10 machine you can follow this tutorial.
Please feel free to leave your feedback on this Windows or Linux tutorial. Please follow these steps to set up your Windows 10 or Linux machine ready for writing Smart Contracts in Solidity for Web 3 dApps on your machine.
This tutorial about installing Solidity on Windows 10 is divided into parts to make to easy for everyone to follow up. Please follow each step as it’s mentioned below to develop the best web 3 dApps by writing error-less smart contracts in Solidity.
Part 1 Setting up Linux Subsystem on Win 10
#1 Install Linux Subsystem on Windows 10
This is purely a cheat sheet of sorts but only this way you can write smart contracts for dApps and it can work perfectly on your Windows machine. Let’s say we are installing Solidity straight on the machine, it will become entirely impossible to follow up the list and install all the dependencies for it. On top of that it may not work and something will always be malfunctioning. So installing a Linux Subsystem can truly save you pains.
Win 10 has its own built-in Linux Subsystem that you can trigger to work for you. With this tool, you can run Ubuntu (including a Bash shell) on your Windows machine, without any special setup for a dual-boot and with less strain on your computer’s resources than a full virtual machine setup would require.
Here is how to set up Linux Subsystem on your Windows 10 machine:
- Make sure you are using a 64-bit version of Windows
- Enable your Win 10 to support Developer Mode if it is not.
- Go to Settings (the gear icon on your Start menu) and select Update and Security
- Click through to the For Developers Section, and tweak the Developer Mode on
- Toggle on the Windows Feature “Windows Subsystem for Linux” just under the Windows Features > Turn Windows features on or off menu, accessible from the Start menu
6.You need to reboot the system if the “Windows Subsystem for Linux” feature has been selected.
7. Once the PC has restarted, type “bash” in the search box and access Bash through it
8. This may take some time. As soon as Bash Shell launches it will toggle Ubuntu for Win download or you should go to Microsoft App Store and Search Linux/Ubuntu as shown in the image below
9. It will show different Linux distros and we will choose Ubuntu app. This will start downloading and installing it on your system.
10. Once installed it will you will see Ubuntu icon on the startmenu. Click it and set up your one time username and password on Ubuntu.
11. Now you see a proper and functional Bash shell. Open it up. A prompt will pop up:
You need to know the basics of Unix commands to follow through. If you are struggling, see this Unix Commands guide which is basic and enough to get you through.
You can find the default shell directory in C drive. It will contain folders like Documents, Downloads to name a few. Run:
cd /mnt/c ls
You can also create a dedicated directory for that purpose which will put you at ease. Go to the C drive location where you want your project to be stored and create a directory like
mnt/c/Users/medit. cd /mnt/c/Users/medit mkdir first_solidity_project cd first_solidity_project
Now move to the next part and install the other dependencies
Part 2: Installing all other necessary dependencies for using Solidity on Windows system
You can use Solidity in your browser as well and there are other ways to install it as well on your Win 10 machine. We will use NodeJS for other dependencies.
You need to install cURL first of all from your new Ubuntu Bash shell, to catch on some of the upcoming installation steps
sudo apt-get install curl
After that we have mentioned other dependencies that need to be installed afterwards to use Solidity on your machine:
NVM or Node Version Mange is required to be installed to help with NodeJS to avoid errors and align versions.
Install with command:
curl -o-https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash
If you see the following error in your terminal.
bash: nvm: command not found
Then use this wgt url to install nvm.
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
Verify version with
Then install NodeJS by using NVM command:
nvm install node
set it up to use it in your shell set:
nvm use node
You can also switch between the different node versions using this command:
nvm use <version>
In order to install different Solidity-related packages, you can use version 6.3.0 or higher. Run the following command to check the node version you have installed:
npm is the NodeJS package manager and it will easily install Solidity packages and gets installed with npm. You should check its version by running command:
If everything is working fine including NodeJS and npm now is the time to install Solidity:
The solc package provides JS bindings for the current Solidity compiler. Use the following npm command to install it:
npm install -g solc
Check its version with
Ganache which was known as TestRPC is an emulator that gets you your own test blockchain with a bunch of wallets with testnet Ether on them. You can test your smart contracts without actually going on to the mainnent and deploying them on it. Ganache works as a virtual blockchain that helps developers test their projects and debug errors if there are any before deploying it on the Ethereum public blockchain.
Truffle sets up a directory structure inside the project folder to break it up into distinct, contract, migration and test folders. The more details will be shown below:
Install Truffle by using the npm command shown below:
npm install -g truffle
Then, install the Ganache command line interface with
npm install -g ganache-cli
Now open a second bash shell and check if Ganache is working:
You should see a list of “Available Accounts” and “Private Keys”, followed by a notification that says “Listening on localhost:8545…”
Geth is short for GO-Ethereum and a second optional step, geth is a command line tool that helps connect to the Ethereum blockchain and deploy smart contracts. You should install it first and when the system is ready, launch a node.
Since you are going to connect to the public Ethereum blockchain directly it can take a considerably long time and most of that depends on the hardware or machine you are using. You can see the Geth Documentation if you need any added advantage to understand the details.
So, if you have read through until here, we are done with the packages necessary for installing dependencies for developing anything you want like Web 3 or just smart contracts for your clients using Blockchain public blockchain.
Creating Your First Project/ Start Building Your First Web 3 Project Right away!
If you can scroll back up and see we created the first directory and called it
first_solidity_project open that directory where we are going to set up our very first smart contract.
Truffle offers many free templates called “Truffle Boxes” as you can jump start working on Solidity with these truffle boxes. They will automatically add the necessary items to these boxes or templates, as they are kind of Solidity templates to begin with. You can unbox these truffle boxes with the
truffle unbox <unbox-name>command. Go to look at the Truffle box called MetaCoin to set up your first mock token “MetaCoin.” Within your
first_solidity_projectdirectory, run command
truffle unbox MetaCoin
truffle unboxcomand is specifically for the template Truffle Boxes. If you want to create an empty structure so that you can write everything from scratch, run
truffle init instead.)
Please note that this truffle unboxing command is solely to unbox these Truffle templates or boxes.
Isto see how the foundation of your project actually looks.
You will notice the created folders in the directory such as
contracts, migrations, and a
testJSON file named ‘
truffle-box-json’ and two other JS files with the names ‘
truffle-config.js’ and ‘
truffle.js.’ Now we need to look into each one of these items:
it will be used to store all of your .sol( Solidity extension file). If you go further into it you will find ConvertLib.sol, MetaCoin.sol and Migration.sol.)
has the necessary JS files to stage your contract for deployment either on the test blockchain or the mainnet public Ethereum blockchain that we have installed earlier. You will see two JS files in the folder: 1_initial_migration.js and 2_deploy_contracts.js.
this one has JS or Solidity test files for smart contract testing purpose and its unhinged performance before deployment, in the MetaCoin example as they are TestMetacoin.sol and metacoin.js.
- Configuration files truffle-config.js , truffle-box.json and truffle.js.
You can read the complete Truffle documentation here to understand the usability of each one.
You can see more detail on each created item and their functionality in the Truffle documentation.
In order to test the very first Solidity contract, we need basically two things ready first: the contract, migration and test files as well, and ofcourse Ganache test blockchain. As we have already seen how to run the test project in part 2 on this guide. Similarly, it’s simple open a second shell and run a test
This command will start the test blockchain– Ganache which is your private blockchain designed to let developers test their projects. We need to keep it open and running for the testing purpose.
Once it’s opened we can test our MetaCoin that we unboxed, it will determine the created contract meets the minimum requirements that we have specified in our test files that are placed in the test files metacoin.js and TestMetacoin.Sol( It’s important to begin Solidity test files with capital i-e ‘Test’). The major difference between JS and Solidity tests has been explained here which are used in the MetaCoin Truffle box.
In order to see inside the test files, cd into that test folder and start it with the built-in vim editor for reading contents available in
TestMetaCoin.Solby using this command.
(To exit the vim editor when you’re done, type :q )
Another important thing is to use these two functions
testInitialBalanceWithNewMetaCoin()are the primary test case basis needed for that to be met. Now close this file (:
q) open the second file using vim in the
Now see those red boxes which highlight the output that we need to look at the passed test cases. Now, scroll down in vim to check the test file catches and show whether the contract has been successfully developed or failed.
Then next exit vim, cd into the folder and look at the contracts:
The contract allows us to send Metacoin to the different test accounts with a value of 10000 Metacoin for instance.
Now exit vim (with :q ) and we need to cd to the main project. We will now test our MetaCoin contract. Run command
If all goes well and error-free (and it should, if no changes are made), you will see 5 green check-marks to represent the passed tests and contract functions successfully. As everything has worked as expected we need to deploy this contract on Ganache which is our private test blockchain. Run command
It will add a new folder known as
build in the project directory items list. You will notice our new folder contains three JSON files communicating with the contract’s folder. Once we have generated JSON files, the
migratecommand then runs the migration files contained in that folder. It will look like this:
We will notice that the output we have received is that the command we used for migration in truffle ‘truffle migrate’ has launched two migration files as 1_initial_migration.js and 2_deploy_contracts, which reveal that 5 test blocks have been created: one is to deploy the Migrations.sol (count 1) to save migration on the network (count 2), one each to deploy ConvetLib.sol and MetaCoin.sol (count 4) and also the final one to just save that migration (count 5).
However, if we go to run the migration second time, we will notice no migration changes have been incurred like the screenshot below shows:
Now we need to move to other terminal window where we can see our test blockchain Ganache is running to check other information about blocks and migration:
We will find all the 5 blocks available there. Do check this blog that talks volumes about the truffle migrate command.
That’s all that we needed for testing and deploying our smart contracts built with Solidity on our test blockchain with the help of Linux Subsystem in Win 10 on our machine. This guide seems long but is a shrunk form of what you can read in detail on the documentation pages of Solidity and Truffle.