How to set up your Ethereum development environment for MacOS

0
88

I will introduce the proper tooling and show you how to prepare your PC for writing smart contracts and interfacing with the Ethereum blockchain.

Necessary Tools

  1. Homebrew
    HomeBrew is a package manager for macOS.
  2. Visual Studio Code
    Visual Studio Code is my code editor of choice when it comes to writing smart contracts. It’s super lightweight, full of extensions created by the community, and has powerful debugging tools. Obviously opinions may differ when it comes to which code editor or IDE to use. The final decision is yours.
  3. Geth (Go Ethreum)
    Geth is the the command line interface for running a full Ethereum node implemented in Go. It allows you the ability to do practically anything you would need to do on the blockchain (commands listed here).
  4. Ganache
    Ganache is a blockchain emulator that allows you to run tests, execute commands, and inspect state while controlling how the blockchain operates. Ganache was called Test RPC in the past, but the developers learned from Android that tasty dessert names are more appealing. The blockchain you create is personal, has user friendly UI, and runs quickly in memory.
  5. NPM
    NPM is a package manager for Node.js files. We’ll be using this to download dependencies like Truffle.
  6. Truffle
    Truffle is an awesome tool that makes the developers job much easier. It’s provides a testing framework, smart contract compilation, linking, deployment, and much more. It also handles a lot of boilerplate for you when you get into the realm of using boxes.

Lets Start

  1. Install Homebrew by pasting the following command into the terminal.
/usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

Go through the the installation and when you see Installation Successful you’re done!

Type brew update

2. Install Visual Studio Code .zip from https://code.visualstudio.com/docs?dv=osx. Go through the installation process.

After Downloading and opening you will need to download the solidity extension to allow you to write in that language.

Type ‘Solidity’ in the search bar and get the extension with the information listed below, It should be the first one suggested.

Name: solidity
Id: juanblanco.solidity
Description: Ethereum Solidity Language for Visual Studio Code
Version: 0.0.49
Publisher: Juan Blanco
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=juanblanco.solidity

3. Install Geth (Go-Ethereum)
We’re going to use homebrew to connect to the Geth repository. We will need to access https://github.com/ethereum/homebrew-ethereum to download the Ethereum client. In your terminal type in the following commands.

a)brew tap ethereum/ethereum
b)brew install ethereum
or brew update ethereum if geth is already installed on your machine.

4. Install Ganache
http://truffleframework.com/ganache/

5. Install NodeJS and the NPM package manager

a) brew install node
sanity check that all is well by checking their versions
b) node -v
c) npm -v

6. Install Truffle now that we have node installed. To avoid complications we’ll do a truffle uninstall first. Truffle can get finicky if the installation detects traces of it elsewhere on your computer.

npm uninstall -g truffle
npm install -g truffle

DONE!

The Final Test

  1. Get Balance From one of our generated accounts
  2. Convert that Balance From Wei to Ether

Our Sources:
https://web3js.readthedocs.io/en/1.0/web3-utils.html?highlight=fromwei#fromwei

https://web3js.readthedocs.io/en/1.0/web3-eth.html

In Terminal type in

a) truffle init
b) truffle migrate
c) truffle develop

After a list of the 10 generated accounts are shown, you can select any of the public addresses and use the web3 command to get its balance. All of the generated test addresses will have a balance of 100 Ether, but it will be shown in wei unless we convert it.

web3.eth.getBalance(“[Address]”)

this command prints out the Address’ balance in wei. To convert it we will take the result and specify it’s conversion type.

web3.utils.fromWei(`[wei value]`, 'ether')

Conclusion

You’re setup and ready to start writing contracts. I recommend filling in any loopholes in your knowledge at

  1. https://solidity.readthedocs.io/en/develop/introduction-to-smart-contracts.html
  2. https://www.bitdegree.org/learn/solidity-introduction/
  3. https://web3js.readthedocs.io/en/1.0/web3-eth.html

I have another that demonstrates how to publish smart contracts to the testnet or mainnet. Check it out Here.

Sources

https://brew.sh/
https://github.com/ethereum/go-ethereum/wiki/geth
https://web3js.readthedocs.io/en/1.0/web3-eth.html
https://solidity.readthedocs.io/en/develop/introduction-to-smart-contracts.html
https://www.ethereum.org/cli
https://github.com/ethereum/go-ethereum/wiki/geth
https://code.visualstudio.com/docs
http://truffleframework.com/

Source