HackerNoon.com
Published in

HackerNoon.com

Hands On: Creating Your Own Local Private Geth Node (Beginner Friendly)

Source: https://altcointoday.com/
Source: https://tenor.com/

What will we build?

  • Local: This blockchain will be running only on your computer (formally, node) locally.
  • Testnet: This will not mine real Ethers. Only fake ones. It is perfect for testing dApps, or for just playing around.

Prerequisites

  1. MacOS
  2. Homebrew (Download link: https://brew.sh/)
  3. XCode (Get from AppStore)

Setting Up Development Environment

Step 0: Download Geth using Homebrew

$ brew tap ethereum/ethereum
$ brew install ethereum

Before going any further, let me clear what Geth is

Let’s get crackin’ baby!

Genesis Block, The Special Block

Step 1: Create Genesis block

$ mkdir -p ethereum-tutorial && cd ethereum-tutorial
$ mkdir -p private && cd private
$ puppeth

Step 2: Initialise the genesis block

$ geth --datadir ~/ethereum-tutorial/private init niharikatestnet.json

Step 3: Creating accounts

$ geth --datadir . account new
$ geth --datadir . account list

Step 4: Write a Shell Script to Start Blockchain

geth --networkid 4224 --mine --minerthreads 1 --datadir "~/Desktop/Playground/ethereum-tutorial/private" --nodiscover --rpc --rpcport "8545" --port "30303" --rpccorsdomain "*" --nat "any" --rpcapi eth,web3,personal,net --unlock 0 --password ~/ethereum-tutorial/private/password.sec --ipcpath "~/Library/Ethereum/geth.ipc"
$ chmod +x startnode.sh
$ ./startnode.sh

Step 5: Connect to running geth

$ geth attach
Source: https://tenor.com/

Step 6: Query the blockchain

> eth.accounts
> eth.getBalance(eth.accounts[0])
> web3.fromWei(eth.getBalance(eth.accounts[0]), "ether")

Info: Stop Mining or Start Mining

$ miner.stop()
$ miner.start()

Step 7: Make transactions

> eth.sendTransaction({from: eth.coinbase, to: eth.accounts[1], value: web3.toWei(10, "ether")})
> web3.fromWei(eth.getBalance(eth.accounts[1]), "ether")

--

--

Elijah McClain, George Floyd, Eric Garner, Breonna Taylor, Ahmaud Arbery, Michael Brown, Oscar Grant, Atatiana Jefferson, Tamir Rice, Bettie Jones, Botham Jean

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store