Introduction to Ethereum development, part 1
This is part one of the “Introduction to Ethereum development” series. In this series you will install the essential tools, and compile, run and interact with a smart contract! Starting your blockchain development career with a 💥.
This post was first published on Github (you can find it here). It has been re-formatted for Medium, but the content is the same.
Let’s get started: Happy Coding!
Part 1 of this series, the one you are currently reading, takes you through installing the required tooling and creating your first blockchain project using Truffle.
Part 2 introduces all the elements of this project, gives an in-depth explanation on what is in a smart contract, and shows you how to compile and run the contract.
In part 3 of this series, we will interact with this contract, first from the console and then from a webpage.
Setting up development tools on your Mac
Ok, so not everyone is using a mac for development, but for this guide we assume you are 😄 If you are using a windows or linux machine, feel free to comment with the big differences, or better yet, a pull request to the Github page to add a section for these operating systems!
We are going to install the basics first, to get started as quick as possible. In following parts we will add new tooling when needed to improve the development workflow. 🔧
Installing Node
While it is possible to develop Ethereum smart contracts without using Node, or tooling based on Node, it does make everything much easier. Node (or Node.js) is a runtime framework for Javascript, running locally and pretty much on every common desktop OS.
Download NodeJS from the nodejs.org webpage: https://nodejs.org/en/download/. I recommend picking the current release, rather than the stable version.
Installing Git tooling
Next step is to install GIT. Chances are, you already have this installed if you are a developer or have developer tools installed, as it is used for pretty much everything. Installing this on a Mac is the easiest using the App Store and installing the Xcode developer tools. (Also nice for building macOS and iOS apps 😉)
The xcode tooling can be found here: https://developer.apple.com/xcode/.
Installing the truffle framework
Truffle is the de-facto standard for developing smart contracts. It is actively being maintained and updated by Consensys, one of the larger blockchain software companies, and the open source community.
Truffle can be installed by running sudo npm install -g truffle
in the console. NPM is the package manager installed with Node by default, so it should be available on your system now.
Installing Visual Studio Code (optional)
I like Visual Studio Code for my text editing, while it has the “Visual Studio” part in the name, it is a completely separate editor based on Electron, a framework written in Node. Visual Studio Code can be found here: https://code.visualstudio.com/.
A neat trick with Visual Studio Code is adding “code” to the path. This enables starting the editor from the terminal by typing “code .” in your current location! Instructions on how to set this up can be found here: https://code.visualstudio.com/docs/setup/mac.
This step is completely optional, but I do recommend an editor with at least syntax highlighting for Javascript and ideally also syntax highlighting (or a plug-in that enables this) for Solidity. Other options, aside from Visual Studio Code, are:
- Sublime (https://www.sublimetext.com/)
- Atom (https://atom.io/)
- Or even Emacs (https://www.gnu.org/software/emacs/)
I will be using Visual Studio Code throughout this walkthrough and will give some tips and tricks for this editor when we touch upon different topics.
Installing a good terminal emulator (optional)
Coming from a Linux and Windows background, the default Mac terminal emulator felt a bit lacking, so I installed a better one: iTerm2, which can be found here: https://www.iterm2.com/
This step is also completely optional, but listed here to reproduce my results and screenshots if needed. 😄
Creating your first Ethereum smart contract
So now you have all the tools required to start with your first smart contract! Smart contracts are the core part of any Ethereum-based blockchain solution, and are written (most often) in the Solidity language.
When you are using the Visual Studio Code editor, I can recommend installing the solidity extension, created by Juan Blanco, which is (for me) the highest result when searching with the keyword Solidity
in the extension tab.
Without further ado, let’s get started with Truffle and smart contracts! Actually, we are going to cheat a little bit and let Truffle create our smart contract. 😉
Creating a new Truffle project
Thankfully, the Truffle framework has evolved quite a bit since the first release and creating a new truffle project is actually dead simple. Execute the following commands in your console:
mkdir MetaCoin
cd MetaCoin
truffle unbox metacoin
Which should give you the following outcome:
Downloading...
Unpacking...
Setting up...
Unbox successful. Sweet!Commands:Compile contracts: truffle compile
Migrate contracts: truffle migrate
Test contracts: truffle test
MetaCoin is the example smart contract created by the Truffle framework, which we will compile, migrate, test — as described in the “commands” section of the feedback, and more in the following sections.
Congratulations on creating your first Ethereum blockchain project, this is a great step! You are now a true blockchain developer! Time to update the LinkedIn page 💰💰💰
Ok, maybe not yet. Let’s go see what’s in this project and what we can do with it in the next part of this series!
Extra: If you are into blockchain development, don’t forget to check out https://blockchain.company