XDC Private Testnet (Geth Fork)

Setting up a Private Test Network

Ethereum enables users to set up a private test network separate from the main Ethereum chain. The testnet helps test distributed apps built on Ethereum, without exposing them to the real Ethereum network. The following is a step-by-step walk-through on how to set up and run your Ethereum testnet using Geth and Homebrew.

Step-by-step Walk-through

Step 1: Install Geth and Homebrew.

Step 2: Create Genesis file.

Step 3: Start your node.

Step 4: Mine Ether.

Step 1: Install Geth and Homebrew

  • Open the terminal and install homebrew.

ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • Install Geth.

 brew tap ethereum/ethereum
 brew install ethereum

Step 2: Create Genesis File

The Genesis block is the first block in the chain. The Genesis file is the JSON file that defines the characteristics of the initial block and thus the rest of the blockchain.

  • Create a directory to hold your network files.

mkdir my-eth-chain
cd my-eth-chain
  • Create your Genesis file.

 touch myGenesis.json
  • Open your Genesis file and paste the following:

{ "config": { 
"chainId": 1994, 
"homesteadBlock": 0, 
"eip155Block": 0, 
"eip158Block": 0, 
"byzantiumBlock": 0 }, 
"difficulty": "400", 
"gasLimit": "2000000", 
"alloc": { 
"7b684d27167d208c66584ece7f09d8bc8f86ffff": { 
"balance": "100000000000000000000000" }, 
"ae13d41d66af28380c7af6d825ab557eb271ffff": { 
"balance": "120000000000000000000000" } } }

Configuration

  • chainId: A unique identifier of new private blockchain.

  • homesteadBlock: Homestead is the first production release of Ethereum. Given that developers are already using this version, the value of this parameter is set to zero.

  • eip155Block/eip158Block: Ethereum Improvement Proposals (EIP) were implemented to release Homestead. Given that hard forks are not required in private blockchain development, its value is set to zero.

  • Gas limit: The gas limit is the maximum amount of gas spent on a particular transaction. Consider setting a fairly high value on the gas to avoid hitting the limit and slowing down your network.

  • alloc: Allows allocation of Ether to a specific address.

Step 3: Start Your Node

  • Instantiate your data directory

geth --datadir ./myDataDir init ./myGenesis.json
  • Start your Ethereum peer node

geth --datadir ./myDataDir --networkid 1114 console 2>> myEth.log

The output will look like this:

Welcome to the Geth JavaScript console!

instance: Geth/v1.7.3-stable-4bb3c89d/darwin-amd64/go1.8.3
coinbase: 0xae13d41d66af28380c7af6d825ab557eb271ffff
at block: 5 (Thu, 07 Dec 2017 17:08:48 PST)
datadir: /Users/test/my-eth-chain/myDataDir
modules: admin:1.0 clique:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0

>
  • Display your Ethereum logs

Open terminal window, cd to my-eth-chainand typetail -f myEth.log

  • Create or import an account

In Geth Javascript console, create an account:

 >personal.newAccount("")
  • Set default account

>miner.setEtherbase(web3.eth.accounts[0])

Step 4: Mine Ether

Check your balance

> eth.getBalance(eth.coinbase)

Run the following to mine ether:

> miner.start()

Look at your terminal window, some mining actions will be visible in the logs. To stop mining:

> miner.stop()

Optional: Add other peers

On your same machine instantiate a new datadir:

geth --datadir ./peer2DataDir init ./myGenesis.json

Launch the second peer on a different port:

geth --datadir ./peer2DataDir --networkid 1114 --port 30304 console 2>> myEth2.log
  • Display your Ethereum logs

Open another terminal window

cd to my-eth-chain

Type tail -f myEth2.log

  • Join the first peer

In the geth JavaScript console of your 1st peer, type:

admin.nodeInfo.enode

The output will look like this:

“enode://dcff6d9dcb14eeb1d1b7575b0653fa1025ad1b7722c6d652d0449f0966e97931bdf037e5542086e7b9e0bec056566522c6c0cc4d73d8e4186a35da8aa5988e15@[::]:30303”

In the geth JavaScript console of your new second peer, type:

admin.addPeer( “enode:// ” )

Helpful geth console commands

admin.nodeInfo.enode net.listening net.peerCount admin.peers eth.coinbase eth.getBalance(eth.coinbase) personal eth.accounts miner.setEtherbase(web3.eth.accounts[0]) miner.setEtherbase(“0xae13d41d66af28380c7af6d825ab557eb271ffff”) miner.start() miner.stop() miner.hashrate eth.getBlock(0) eth.getBlock(“latest”) eth.blockNumber web3.eth.getBlock(BLOCK_NUMBER).hash eth.syncing debug.verbosity(6) //highest logging level, 3 is default

Last updated