Installing geth (go-ethereum) and Connecting to Private Network [MacOS Edition]

Tadashi Shigeoka ·  Sat, August 11, 2018

I’ll introduce how to install geth (go-ethereum) on macOS, set up an Ethereum node, and connect to a private network.

Ethereum | イーサリアム

Installing go-ethereum (geth)

Install ethereum by referring to the following articles:

First, update Homebrew:

brew update
brew upgrade

Next, install ethereum:

brew tap ethereum/ethereum
brew install ethereum
$ geth version  
Geth
Version: 1.8.13-stable
Architecture: amd64
Protocol Versions: [63 62]
Network Id: 1
Go Version: go1.10.3
Operating System: darwin
GOPATH=
GOROOT=/usr/local/Cellar/go/1.10.3/libexec

Connecting to Ethereum Private Network

From here, I worked following the article プライベート・ネットに接続する · Ethereum入門.

Creating Genesis File

Create and move to the eth_private_net directory:

ETH_PRIVATE_NET_DIR=~/works/eth_private_net
mkdir $ETH_PRIVATE_NET_DIR && cd $ETH_PRIVATE_NET_DIR

Create a myGenesis.json file with the following content under $ETH_PRIVATE_NET_DIR:

 {
  "config": {
    "chainId": 15
  },
  "nonce": "0x0000000000000042",
  "timestamp": "0x0",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "extraData": "",
  "gasLimit": "0x8000000",
  "difficulty": "0x4000",
  "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase": "0x3333333333333333333333333333333333333333",
  "alloc": {}
}

Starting Geth on Private Network

Initialize genesis block

geth --datadir $ETH_PRIVATE_NET_DIR init $ETH_PRIVATE_NET_DIR/myGenesis.json

Start geth

geth --networkid "15" --nodiscover --datadir $ETH_PRIVATE_NET_DIR console 2>> $ETH_PRIVATE_NET_DIR/geth_err.log

On the Geth prompt, execute:

> eth.getBlock(0)

Confirm that you can display block information for the specified block number.

That’s all from the Gemba where I set up an Ethereum node with geth on macOS.

Reference Information