Windows environment setup with Solidity

A free video tutorial from Sebastien Arbogast
Entrepreneur, software developer, speaker and trainer
4.5 instructor rating •
1 course •
15,849 students
Learn more from the full course
Become a Blockchain Developer with Ethereum and SolidityDevelop your first decentralized application from scratch on the Ethereum blockchain
17:04:00 of on-demand video • Updated March 2020
- Understand the basic philosophy behind the blockchain and distributed/decentralized applications
- The basics of how a blockchain generally works, just enough to be able to use it as a development platform
- Develop a distributed application, from creating a blank project to deploying it in production all the way through writing smart contracts, unit testing them, and creating a user interface for them
- How to combine the right tools to put together a consistent and real world pragmatic development environment
- The fundamentals of the Solidity smart contract language
- How to use the Truffle build and testing framework (covers Truffle 4)
- How to deploy a decentralized app to various Ethereum instances (testrpc, private chain, test chain, main net)
- How to unit test smart contracts
English
In this lecture, we are going to set up our development environment for Windows
with all the tools that we need to develop smart contracts for Ethereum.
We're not going to describe all of them but focus on those that are widely used
by the community. By the way, this lecture is specifically for Windows. If you are
running on MacOS or Linux there are dedicated lessons for that. Our toolbox
will be composed of the following tools: Geth, Ganache, Truffle and Atom. The first
thing we need to install is Geth. Now Geth or Go-Ethereum is the command line
interface that allows you to run and operate a full Ethereum node. Geth is
implemented in Go and allows you to mine blocks, to generate ether, to deploy and
interact with smart contracts, to transfer funds, to inspect block history,
to create accounts, and so on and so forth. Geth can be used to connect to
the public Ethereum networks like the main net, or to create your own private
network for development purposes, which wel'll demonstrate later on in this course.
The benefit of using Geth in your development process is to let you fully
test your application before deploying it to the main net. So the installer for
Geth can be found on the Ethereum website. So we open our browser. By the
way, if you're only using Edge or Internet Explorer as a browser, you
should install either Chrome, which is the main one we use, or at least Firefox.
But Edge and Internet Explorer are not going to be suitable for blockchain
testing. So here I will go to "ethereum.github.io" By the way, all the
websites I mention in these videos, I will always put the links in
the resources of the corresponding lectures. So "go-ethereum/downloads". So here we can go to Geth 1.7.3 for Windows. Once it is downloaded you can
just open it, accept the security warning, and then it
will run the installation wizard. So here I agree, don't forget to check the
development tools checkbox here in this step, this is important. And once it's
done, you can click Next, you leave it in the default directory and it's
installing everything. When it's done, you can close it. Now throughout this course
we're gonna do a lot of things on the command line. And in Windows you have 2 command line interfaces by default: you have the CMD runtime, and you have the
PowerShell. Now we really strongly advise you to use the PowerShell, because it's
more powerful and its commands are way closer to what you may get on other UNIX
systems. So here we will start a PowerShell by going to the search and
looking for Windows PowerShell. And by the way, once it's running, it might help
to right-click it in the in the bar, and click "pin to taskbar". This way we can
easily go back to it when we need to. And this is the command line interface that
you should use. And here for example you can type"geth version" to check which
version of Geth is installed. And here we have1.7.3-stable, and that's
good. We can close PowerShell for now, and go back to the browser to install
Ganache. Now ganache is an Ethereum blockchain emulator that you can use for
development purposes. Ganache can be seen as a replacement for TestRPC, which we
used in previous versions of this course. The strength of Ganache is its UI
that allows you to inspect blocks and transactions in a more user-friendly
way. Compared to Geth, Ganache is an in-memory Ethereum node that runs faster and
provides all the visual components you need to test your contracts locally
before deploying them to a real Ethereum implementation. Now we can install
Ganache by downloading the installation package for windows on "truffleframework.com/ganache". Again I'll put this link in
the resources of this course. So here the website should detect
automatically which operating system I'm on, and propose me to download the
Windows version which I'm gonna do. So I click the download button on the home
page and once it's downloaded I just open the .APPX package, and after a while
I get the security warning. I still open it and I get to this screen so I just
click install leaving the "launch when ready" checkbox
checked. Once installation is complete,
you will see this screen that asks you to support Ganache by enabling Analytics.
You should leave it like that, and click "Continue". Now let's review the main
features of Ganache. When you start Ganache, it starts a new Ethereum node
in memory on network identifier 5777, which we can see in this part of the
screen. It also creates 10 accounts and puts 100 Ethers on each account.
Now contrary to what happened with TestRPC, Ganache always creates the same
accounts, it uses the same mnemonic, which will be very practical later on when we
import those accounts in MetaMask. So the first screen you see is the "Accounts"
view, and there you can find some information about the running node like
the current block, which is the number of the last block mined by the node, the gas
price, which is the minimum gas price this node requires on transactions in
order to mine them, the gas limit, which is the maximum gas this node is willing
to accept per block, the network identifier, the RPC server is the endpoint for the RPC parts that we'll connect to later, and the mining status
is important. By default, this fake node only mines a new block
when it receives a new transaction. That's what Auto-mining means. And this
is completely different from what real nodes would do, since a normal node would
mine a new block at regular intervals, whether there are pending transactions
or not. You can disable auto-mining, come back to a more normal behavior and even
set a mining block time in the settings. And last but not least, you can see the
mnemonic, which is the seed that Ganache uses to generate the first accounts. Then
you can see a list of the 10 accounts generated by Ganache, with the following
information: the address of the account, its balance, with only two
decimals, the number of transactions that were sent by this account, the index of
the account in the list of accounts, and finally a button that makes it possible
for you to see the private key for the account. Second you have the "Blocks" tab,
that shows you a list of blocks mined by the node, and here we only have one block,
which is the genesis block. We also have the "Transactions" tab where we will see a
list of all the transactions, and for now there aren't any. And last but not least,
the "Logs" tab, that shows you the logs of the running node. There's also search
field, where you can search for blocks or transactions by their hash or number. And
finally there's this cog icon that accesses settings. There you can change
the hostname, the port number, the network identifier - we'll use that quite a lot
later on - you can also disable auto- mining to set a regular mining block
time. we'll leave auto-mining on. In "Accounts and keys", you can define the
number of accounts that are generated when it starts, and also change the mnemonic
or generate a random one. Here, we'll leave the settings as they are. In "Chain",
you can customize the gas limit and the gas price, and finally in "Advanced", you
can enable or disable Google Analytics. Whenever you change something in the
settings, don't forget to save and restart to take those new settings into
account. Here we'll just go back. Now we can quit Ganache for
now. And the next thing we need to install is NodeJS and NPM. NodeJS
is a server-side JavaScript platform to create applications that will interact
with your Ethereum node. When we install NodeJS, we also install the Node Package
Manager, or NPM, that is required to set up most of the tools and libraries that are
needed to develop for Ethereum. To check if NodeJS and NPM are already installed on
your machine, you can use the following commands in a Windows PowerShell.
So let's open the PowerShell and "node -v" to show the version that is
installed for Node if any, and in this case we don't have any, and "npm -v"
will show us the version for NPM. And here is the same: none is installed. So if
you already have a version installed, make sure that NodeJS is at least in
version 8 and NPM is at least in version 5. Those are the versions that we tested
to produce this content and if you use older versions, it might not work. NodeJS can be installed in different ways, but the easiest way to install is
the MSI installation package, that you can find on the NodeJS website. So let's
quit PowerShell for now, go back to the browser and go to "nodejs.org". Again
the link will be in the description. And here, we'll use the "9.3.0 Current", and
not the LTS one. Once the package is downloaded, we can simply run the
installation wizard. I'll quit the Chrome browser for
now, just to see better. So I just click Next, I accept the terms of the
license agreement. Next I leave the default location for installation. Next I
leave all the defaults as they are, and then I click "Install". I will allow this
app to make changes to my device and then I click "Finish". Now I can go back to
a new PowerShell. If it was already running, you should quit it and come back,
start a new one to make sure that everything is in sync. And then you can
type "node -v" again and "npm -v". Again these are the versions with which we
tested all our content, so make sure that you have these versions at least.
The next thing we need to install is Truffle 4. Now to compile, test and
deploy your smart contracts, you will need a build framework that will
increase your development velocity compared to doing it manually. And we
will demonstrate that fact later on in this course. Here we will demonstrate the
use of Truffle 4, and we can find Truffle on the website where we also
found Ganache earlier: "truffleframework.com". Now if you have a previous version
of Truffle, please uninstall it. If you have Truffle 3, that we used in previous
versions of this course, you should remove it before installing the new
version, otherwise they will collide. And to install Truffle, we will install it as
a Node package. So we can go to the PowerShell. First of all let's uninstall
any potential older version that we might have: "npm uninstall -g
truffle" and then "npm install -g truffle", but we will add a version here "@4.0.4". This is because we don't want to install the latest version that
might introduce some breaking changes with the code of this course. So if you
are using a more recent version, especially a more recent major version,
don't be surprised if you've got issues. Here, 4.0.4 is really the latest version at the time of this recording. Once this is done,
you can run "truffle version" to check that the command exists and that it's in
the right version. And here you can see we have 4.0.4 for Truffle, and we have 0.4.18 for the Solidity compiler, implemented in JavaScript. The last step
of this lecture is to install a text editor, that will be used to edit our
smart contracts and other text files. At this point in time we don't really
have a real Ethereum IDE. You can find some plugins for IntelliJ, Webstorm or
Microsoft Visual Studio, but not a full IDE covering
all the development chain. But that's okay because we have some interesting
free text editors that are good enough for what we want to show here. In this
course, we chose to use Atom because it's freely available for Mac, Windows and
Linux. But of course, you are free to use the one that you are more familiar with.
To install Atom, we can first quit the PowerShell and go to "github.com/atom/atom". There we can go to "Releases" here. And we will not install the
1.24 beta. Instead we'll stick with the latest stable release, which in our case
is 1.23.2. It might be more recent for you, but at the time of this recording this
is what we have. And here we would use the atom-setup executable. And since we
are running on a 64-bit machine, we'll use "atom-setup-x64.exe". Once the package is
downloaded, you can simply open it. Here we'll quit the browser. So this
package installs Atom and it launches it when installation is done, and also
creates a shortcut on our desktop, which will be very practical to launch Atom
later on. So here is Atom. We'll accept the registration as a default handler for the
Atom protocol: "yes, always". And this should also have installed
all the atom and apm commands that we need in the PowerShell. So now if you
want, you can leave Atom, go back to the PowerShell, and run "atom -v"
to see the version that is installed. And "apm -v" to see the Atom Package
Manager version. So the Atom Package Manager is very useful to install
extensions and plugins for the Atom text editor. And in this case we'll use it to
install the language-ethereum extension, that adds support for the Solidity
language, that we'll use to write our smart contracts. So to install it we can
just run "apm install language-ethereum". We can also install this kind of
extension from Atom itself, but since we are in the command line, you might as well
do it here, and this is done now. I said this was the last tool. Actually there is
another one that we need to install on Windows because Windows unfortunately
doesn't come with a version of Git pre-installed with the operating system.
And Git is a version control system that is heavily used by NPM so when we will
install some NPM packages, sometimes it requires Git. So to anticipate on that we
can go to the browser. First let's close PowerShell, open the browser and go
to "git-scm.com/download/win". And this will automatically
download the installer. Installation package is under "Downloads" here, and you
can just open this package, close the browser for now, accept the security
warning, accept all the defaults, and then let it copy all the files. Now
again if you are not familiar with Git, it is a version control system similar
to Subversion or CVS, but it is used heavily in the NPM ecosystem. And then we
click "Finish" and it's proposing to open the release notes. OK.
we can close that and that's it. At this stage, we have all the tools required to
start the development of our smart contracts on Windows. One note for the
future: in the rest of this course, we are going to type a lot of commands in the
command line prompt, and on Windows you can either use the legacy command line
interface or the Windows PowerShell. Again we strongly advise you to use the
Windows PowerShell throughout this course, otherwise some commands might
fail. And even though most of the videos in this course were shot on a Mac with
a UNIX terminal, the very same commands were all tested to work in a Windows
PowerShell, unless explicitly stated otherwise. So again we tested everything.
If there are some differences, we will mention them explicitly. In the next
lecture, we'll show you how to set up and start a private Ethereum node.