The Geth’s saga: setting up Ethereum private network on windows

Pre requirements

Install geth: https://github.com/ethereum/go-ethereum/wiki/geth

Things to define before start

  • Custom Genesis File (it is the next topic)
  • Custom Data Directory (for me: “C:\ETH\”)
  • Custom NetworkID (for me: 13)
  • (Recommended) Disable Node Discovery

Creating The Genesis Block

Every blockchain starts with the genesis block.

{
"nonce" : "0x0000000000000055",
"mixHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"difficulty": "0x20000",
"gasLimit" : "0x800000",
"timestamp" : "0x0",
"extraData" : "",
"coinbase" : "0x0000000000000000000000000000000000000000",
"alloc" : {},
"config" : {
"chainId": 100,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
}
}

Parameters at genesis.json

Extract from: https://ethereum.stackexchange.com/questions/2376/what-does-each-genesis-json-parameter-mean

  • Chainid — identifies the current chain and is used for replay protection. This is a unique value for your private chain.
  • homesteadBlock — your chain won’t be undergoing the switch to Homestead, so leave this as 0.
  • eip155Block — your chain won’t be hard-forking for these changes, so leave as 0.
  • eip158Block — your chain won’t be hard-forking for these changes, so leave as 0.
// ChainConfig is the core config which determines the blockchain settings.
//
// ChainConfig is stored in the database on a per block basis.
// This means that any network, identified by its genesis block,
// can have its own set of configuration options.
type ChainConfig struct { ChainId *big.Int 'json:"chainId"' // Chain id identifies the current chain and is used for replay protection
HomesteadBlock *big.Int 'json:"homesteadBlock,omitempty"' // Homestead switch block (nil = no fork, 0 = already homestead)
DAOForkBlock *big.Int 'json:"daoForkBlock,omitempty"' // TheDAO hard-fork switch block (nil = no fork)
DAOForkSupport bool 'json:"daoForkSupport,omitempty"' // Whether the nodes supports or opposes the DAO hard-fork
// EIP150 implements the Gas price changes (https://github.com/ethereum/EIPs/issues/150) EIP150Block *big.Int 'json:"eip150Block,omitempty"' // EIP150 HF block (nil = no fork)
EIP150Hash common.Hash 'json:"eip150Hash,omitempty"' // EIP150 HF hash (fast sync aid)
EIP155Block *big.Int 'json:"eip155Block,omitempty"' // EIP155 HF block
EIP158Block *big.Int 'json:"eip158Block,omitempty"' // EIP158 HF block
// Various consensus engines
Ethash *EthashConfig 'json:"ethash,omitempty"'
Clique *CliqueConfig 'json:"clique,omitempty"'
}

Init GETH to create the genesis block

Remember my settings:

  • genesis.json is in “C:\ETH\configs\genesis.json”
  • datadir is “C:\ETH\data-private”
running Command Prompt with administrator privileges
geth --datadir "C:\ETH\data-private" init "C:\ETH\configs\genesis.json"
executing geth with the parameters — datadir and init
result of geth with the parameters — datadir and init

Resolving the warning: execute geth to create account

WARN [09–20|12:17:36] No etherbase set and no accounts found as default

Creating account at geth

Run geth with the following parameters:

geth --networkid 13 --port 60303 --rpc --lightkdf --cache 16 --datadir "C:\ETH\data-private" console

Parameters

Here are explanations about the parameters used.

Executing geth with console

Create new Account

At geth console:

>
>personal.newAccount()
Passphrase: *****
Repeat passphrase: *****
Creating an account

Check your account

At geth console:

>
>personal
Executing personal at geth console
0x842d06ee2f7c45b3c1080bdb75757f269335bc9c

Configure enode

Enode’s configuration will be used when other computers connect to the private network.

>admin.nodeInfo.enode
Running admin.nodeInfo.enode at geth console
"enode://ba4a9b4e8fb7a46776ad1f3ace7cb63fab5c50b185516b01515de12b2d7adacc525e69c133b01611e1a7009a18121c5e0b7f9950c3b70f9124a1a784469e96e6@0.0.0.0:60303"

IP and port for enode

Pay attention at port at enode’s end.

geth — networkid 13 — port 60303 — rpc — lightkdf — cache 16 — datadir “C:\ETH\data-private” console
Check computer’s IP
  • IP: change 0.0.0.0 to 192.168.1.114
  • Port: 60303
"enode://ba4a9b4e8fb7a46776ad1f3ace7cb63fab5c50b185516b01515de12b2d7adacc525e69c133b01611e1a7009a18121c5e0b7f9950c3b70f9124a1a784469e96e6@192.168.1.114:60303"
>exit
Exiting geth console

Execute node to mine

Now we are already to mine. I will execute geth again, but adding some parameters:

geth --identity nodeSOL --nodiscover --networkid 13 --port 60303 --maxpeers 10 --lightkdf --cache 16  --rpc --rpccorsdomain "*" --datadir "C:\ETH\data-private" --minerthreads 1  --mine
Execute geth to mine
geth --identity nodeSOL --nodiscover --networkid 13 --port 60303 --maxpeers 10 --lightkdf --cache 16  --rpc --rpccorsdomain "*" --datadir "C:\ETH\data-private" --etherbase "0x91e516b943c032d843356fa590bb2d56d52eb72e" --minerthreads 1  --mine
Starting mining operation
The first block is mined!

Attach to geth console in another window

I already have a geth node running, so I can attach another geth instance to interact with it.

geth --ipcpath geth.ipc --datadir "C:\ETH\data-private" attach
> personal
run personal at geth

Configure another node

Remember the first node’s configurations:

  • IP: 192.168.1.114
  • enode://ba4a9b4e8fb7a46776ad1f3ace7cb63fab5c50b185516b01515de12b2d7adacc525e69c133b01611e1a7009a18121c5e0b7f9950c3b70f9124a1a784469e96e6@192.168.1.114:60303
ping at command pronpt

Creating The Genesis Block

The genesis block is the same in all nodes at private network.

{
"nonce" : "0x0000000000000055",
"mixHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"difficulty": "0x20000",
"gasLimit" : "0x800000",
"timestamp" : "0x0",
"extraData" : "",
"coinbase" : "0x0000000000000000000000000000000000000000",
"alloc" : {}
"config" : {
"chainId": 100,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
}
}

Init GETH to create the genesis block at node 2

Remember my settings:

  • genesis.json is in “C:\ETH2\configs\genesis.json”
  • datadir is “C:\ETH2\data-private”
geth --datadir "C:\ETH2\data-private" init "C:\ETH2\configs\genesis.json"

Creating account at geth at node 2

Run geth with the following parameters:

geth --networkid 13 --port 60303 --rpc --lightkdf --cache 16 --datadir "C:\ETH2\data-private" console
>
>personal.newAccount()
Passphrase: *****
Repeat passphrase: *****
>
>personal
Executing personal at geth console — node 2
0x4c549625a09cff4831350e5400537674b7e1ac37

Clock error

Pay attention to this warning at geth console:

Waning: System clock seems off by …

Connect at another computer

It´s time to use enode info to execute geth connecting the private network.

geth --networkid 13 --port 60303 --rpc --rpcport 8545 --rpccorsdomain "*" --datadir "C:\ETH2\data-private" --minerthreads 1 --bootnodes "enode://ba4a9b4e8fb7a46776ad1f3ace7cb63fab5c50b185516b01515de12b2d7adacc525e69c133b01611e1a7009a18121c5e0b7f9950c3b70f9124a1a784469e96e6@192.168.1.114:60303"
Block synchronisation started

Attach to geth console in another window

At windows, run another instance of Command Prompt or PowerShell with administrator privileges and run:

geth — ipcpath geth.ipc — datadir "C:\ETH2\data-private" attach

Check your private network

At geth console:

net.peerCount
net.peerCount
admin.peers
admin.peers at first node
admin.peers at second node

Wrap up

Now you know how to set up a private network and connect a node in one computer to a second node im another computer, including mine ethers and synchronize nodes.

--

--

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