Scroll Top

Setting Up Ethereum Development Environment on MacOS

Getting your Trinity Audio player ready...

Ethereum is the popular decentralized platform for blockchain. As part of this article, you will know how to setup Ethereum on macOS platform.

Prerequisites

Basic understanding of Blockchain & Ethereum, i.e. what & why of Ethereum?

Tool Set

Ethereum development ecosystem consists of the following list of tools.

  • HomeBrew : HomeBrew is package manager for macOS. It helps you to install stuff like packages that are not provided by Apple
  • XCode command line tools: Before installing HomeBrew you need to install XCode. We need XCode command line tools which include compilers, utilities needed for HomeBrew to perform its activities.
  • Go-ethereum : Geth or go-ethereum is a command line interface, which allows you to run and operate ethereum node. Geth is implemented in Go.  It allows you to do following functionalities :
    • To Mine blocks
    • To generate Ethers
    • To create and manage accounts
    • To deploy and interact with smart contracts
    • To transfer funds
    • To inspect block history
    • To connect to the public ethereum network (mainnet) or to create your own private network
  • Ganache: Ganache is an ethereum blockchain emulator that you can use for the development purpose. In order to replace testRPC you can use Ganache.
  • NodeJS and NPM: NodeJS is a server-side JavaScript platform to create apps that will help to communicate with your ethereum node.
  • Truffle: Truffle is build framework used to compile, test and deploy your smart contract. It helps in the faster development life cycle
  • Atom: To write your smart contracts install Atom (You can use your favorite text editor)

Steps to setup / install Ethereum on Mac OS

Step 1: Install HomeBrew

  • To install HomeBrew, open https://brew.sh/
  • Copy command as shown in below image

  • Open the terminal and paste command and press enter

/usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

  • After successful installation, you should be able to see below message in terminal:

  • To check the version of HomeBrew installed, type below command, in standard it will install the latest version only.

brew –version

Step 2: XCode installation

  • Open Mac app store and search for XCode
  • Click on XCode search item from the list and click on Install
  • If it’s already installed on your machine then update or skip this step
  • After installation accept the licensing terms

  • To install XCode command line tools, run following command:

xcode-select –install

Step 3: Install go-ethereum

  • Now to install ethereum let us use HomeBrew installed in the previous step
  • Connect HomeBrew to the repository which provides Geth i.e. update package catalog for Homebrew using following command:

brew update

  • Once Homebrew updated, add ethereum package to catalog using the following command:

brew tap ethereum/ethereum

  • Now we are ready to install ethereum using HomeBrew. Use below command to install:

brew install ethereum

  • If ethereum already installed on your machine then just upgrade it to the latest version using command:

brew upgrade ethereum

Step 4: Install Ganache

  • To download Ganache framework, open below link in the browser,

http://truffleframework.com/ganache/

  • Download Ganache for macOS
  • Install it like any other mac software
  • Launch it

Step 5: Install NodeJS & NPM

  • If you already have the latest versions installed then skip this step or if you have an older version then plan to update it to the latest version.
  • To install NodeJS use below command:

brew install node

  • To check which version installed type below command,
    • For NodeJS use below command:

node -v

    • For NPM use below command:

npm -v

Step 6: Install Truffle

  • If you have already installed Truffle and it’s not latest then I would suggest you remove it to avoid any issues, to remove Truffle from your machine use below command:

npm uninstall -g truffle

  • Now to install Truffle, use below command:

npm install -f truffle

Step 7: Install Atom

  • To install Atom text editor, open below url in the browser

https://github.com/atom/atom

  • Go to releases and download Mac installable file – atom-mac.zip
  • Extract the file and install it like any other Mac software
  • Open installed Atom and from the menu click on – “Install Shell Commands
  • Now open the terminal and type below command to install the extension in Atom for solidity support:

apm install language-ethereum

Congratulations! Your ethereum setup is done and its ready to use.

Now to verify if the setup works, let’s do some fund transfer and check balance,

  • Open the terminal and create a directory with any name

mkdir < name of directory >

e.g     mkdir blockchain

  • Now change directory

cd blockchain

  • Now to create truffle project use below command:

truffle init

  • After completing the above statement you should be able to see below file structure:
    • truffle.js – Truffle configuration file
    • test – Directory for test files for testing your application and contracts
    • migrations – Directory for scriptable deployment files
    • contracts – Directory for solidity contracts
  • To work with development accounts use below command:

truffle develop

  • After executing the above command you will see truffle will create 10 default accounts and with initial balance 100 ethers each

  • To check balance use web3 API as below

First account

web3.fromWei(web3.eth.getBalance(‘0x627306090abab3a6e1400e9345bc60c78a8bef57’), ‘ether’).toNumber()

Second account

web3.fromWei(web3.eth.getBalance(‘0xf17f52151ebef6c7334fad080c5704d77216b732’), ‘ether’).toNumber()

  • Now let’s transfer 1 ether from account one to account two using command:

eb3.eth.sendTransaction({from: ‘0x627306090abab3a6e1400e9345bc60c78a8bef57′, to:’0xf17f52151ebef6c7334fad080c5704d77216b732’, valu ‘ether’)})

Above image shows that fund of 1 ether is transferred successfully from one account to another.

Summary:

As part of this article, you have setup ethereum development environment using various tools like geth, ganache, truffle which helps you to make development lifecycle fast. Also, we saw how to transfer funds from one account to another and check account balances.

References:

https://brew.sh/
https://www.ethereum.org/cli
https://github.com/ethereum/go-ethereum/wiki/geth
http://truffleframework.com/ganache/
http://truffleframework.com/
https://ide.atom.io/

Related Posts

Comments (4)

what is the need to install xcode and homebrew? is it fine to work without xcode and homebrew?

Which OS are you using?

Homebrew is just a package management tool and it is not a mandatory that you use this tool.

When I try web3.fromWei(web3.eth.getBalance(‘0x627306090abab3a6e1400e9345bc60c78a8bef57’), ‘ether’).toNumber() I get an error: truffle(develop)> web3.fromWei(web3.eth.getBalance(‘0x627306090abab3a6e1400e9345bc60c78a8bef57’), ‘ether’).toNumber()
SyntaxError: Invalid or unexpected token
at REPLServer.Interface._onLine (readline.js:280:10)
at REPLServer.emit (events.js:211:7)
at emitOne (events.js:116:13)
at REPLServer.onLine (repl.js:468:10)
at REPLServer.runBound [as eval] (domain.js:314:12)
at bound (domain.js:301:14)
at ReplManager.interpret
Any idea about what can cause it?

Hi Walter,

Thanks for referring blog. Its a wordpress do formatting unexpected way. WordPress formate single quote into apostrophe while copying.

So can you please copy command and change apostrophe’s to single quotes or type entire command and this should work for you.

Let me know if you still face any issues.

Cheers…!

Comment to Alok Ranjan Cancel reply

Privacy Preferences
When you visit our website, it may store information through your browser from specific services, usually in form of cookies. Here you can change your privacy preferences. Please note that blocking some types of cookies may impact your experience on our website and the services we offer.