ETH — Cheat Sheet for MacOS Ethereum development

David Léonard
Oct 29, 2020 · 5 min read
A quick and dirty cheat sheet for Ethereum development on MacOS to win your deployments

The other day, I wanted to help a friend to start his Ethereum development Environment on MacOS and I didn’t remember how much little stuff you need to install to make it work.

So here is my small Cheat Sheet to start his Ethereum development Environment on MacOS

It’s missing few things for now, but I’ll add them soon.
Don’t hesitate to tell me what to improve!

Homebrew

$ /bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

NodeJS

brew install node

npm

Normally npm comes directly when you install NodeJS, but you can force it this way:

$ brew install npm

Truffle

$ mkdir test
$ cd test/
$ npm init -y
$ npm install truffle
$ npx truffle init

React

$ npx truffle unbox react

Ganache

It can be used across the entire development cycle; enabling you to develop, deploy, and test your dApps in a safe and deterministic environment.

Ganache UI

Ganache-cli

$ mkdir test
$ cd test/
$ npm init -y
$ npm install ganache-cli
$ npm run ganache

Hd-Wallet-Provider

$ npm -i — save-dev truffle-hdwallet-provider

Yarn

For more information, you can refer to https://engineering.fb.com/2016/10/11/web/yarn-a-new-package-manager-for-javascript

$ brew install yarn
$ yarn bootstrap
$ yarn start //in the front-end folder

Lite-server

Installation

$ npm install lite-server — save-dev
$ yarn add lite-server — dev

Usage

# Inside package.json…
“scripts”: {
“dev”: “lite-server”
},
$ npx lite-server //using on the fly
or
$ npm run dev
or
$ lite-server //if installed globaly

Ethereum Smart Contract Development Process on ganache

$ mkdir myProject //create a folder for the project
$ cd myProject/ //go inside the folder
$ truffle init //initialize a new truffle
$ truffle create test myProject //test cases creation
$ npm run ganache //launch ganache-cli local blockchain
$ truffle comple -all — network development //deploy code on ganache blockchain
$ truffle console //grab info after manual testing
$ truffle test //automated test cases

Web3.js

3 ways of adding web3.js

$ npm install web3//npm installation
$ yarn add web3 //yarn installation
- download and link the dist /web3.min.js //pure js

Setting the provider

The easiest way to interact with the blockchain is to set up MetaMask on your browser and use this code in your development.

window.onload = function() {
updateETHBlocks();
};
async function updateETHBlocks() {
let web3 = new Web3(Web3.givenProvider);
let latest = await web3.eth.getBlockNumber();
console.log(latest);
for (var i=0; i < 10; i++) {
let block = await web3.eth.getBlock(latest-i);
printBlock(block);
}
}

If you’d like to connect Web3 to Ganache, it’s pretty easy : just create a new network using the option “Custom RPC”.

To create a new network just choose Custom RPC
Note that if you’re using Ganache UI, the default port is 7545, if you’re using Ganache-cli it’ll be 8545

If you’d like to access directly from your app, you can create an account on infura.io and use this code:

async function updateBlocks() {
let web3 = new Web3(“https://<network>.infura.io/v3/YOUR-PROJECT-ID”);
let latest = await web3.eth.getBlockNumber();
console.log(latest);
for (var i = 0; i < 10; i++) {
let block = await web3.eth.getBlock(latest — i);
printBlock(block);
}
}

Please replace <network> by the network you choose to work with and off course “YOUR-PROJECT-ID” by the infura’s project ID you’ll work with.

Also, Read

Coinmonks

Coinmonks is a non-profit Crypto educational publication.

Coinmonks

Coinmonks is a non-profit Crypto educational publication. Follow us on Twitter @coinmonks Our other project - https://coincodecap.com

David Léonard

Written by

IT Guru • Defender against the Digital Dark Arts🛡 • Blockchain Advocate 🔑️. https://xn--l9hygo898lbsb.y.at

Coinmonks

Coinmonks is a non-profit Crypto educational publication. Follow us on Twitter @coinmonks Our other project - https://coincodecap.com