Ethereum – Go-Ethereum and Private Blockchain Setup

September 13, 2018

Author: Michael Gord

Tutorial - MLG Blockchain

Go-Ethereum and Private Blockchain Setup

For this tutorial to work you must have geth downloaded.

First you must create a genesis.json file with the parameters below. Each field can be changed however you want. It is recommended that you make a random nonce for your private ethereum network to avoid the chance of someone connecting to your blockchain. The allec object is to prefund accounts on your blockchain with tokens.

{
"config": {
"chainId": 15,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"difficulty": "200000000",
"gasLimit": "2100000",
"alloc": {
"7df9a875a174b3bc565e6424a0050ebc1b2d1d82": { "balance": "300000" }
, "f41c74c9ae680c1aa78f42e5647a62f353b7bdde": { "balance": "400000" }
}
}

Once you have setup your genesis.json file you need to run it from your terminal with this command to initiative your private blockchain network. Setting a data directory is optional, however it is recommended because otherwise your blockchain will be started in a default folder, or can get connected to the live ethereum blockchain if you are running a full ethereum node, which you probably don’t want.

geth --datadir /path/to/genesis.json init genesis.json

When executed in your terminal, you should see a success message. You should also see a folder called “chaindata” that was created in the data directory that you initiated your private ethereum blockchain.

Initialive Private Ethereum Blockchain

You can now connect to your private network using geth, which will run on your testnet the same way as it does on the live ethereum blockchain. Run the following command to connect geth with your private blockchain.

geth --datadir /path/to/genesis.json

In the message that is returned from the terminal, it is important to note the enode you are listening at and the IPC endpoint to connect other nodes to your blockchain.

Connect Geth to Private Ethereum Blockchain

If your terminal returns a message saying that the server has started, you have successfully connected geth to your private ethereum blockchain.

You should now have 3 more folders created in your private ethereum blockchain data directory including dapp, nodekey and nodes.

MLG Blockchain is a blockchain development and consulting firm based in Toronto that is focused on building next generation applications using blockchain and smart contract technology. View all our blockchain development tutorials at www.mlgblockchain.com/learn.html.

MLG Blockchain