Setup Ethereum Private Network
Ethereum is popular framework for blockchain and cryptocurrency. For this article I assume you have basic information about BlockChain technology and Ethereum. In this article I will explain how to setup your private Ethereum network
- Operating System Ubuntu or OSX
- Minimum RAM 2 GB
Setup Ethereum Private Network
Step 1: Install Node Js 8.x
$curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
$apt-get install nodejs
Step 2: Install Ethereum geth client
$sudo apt-get install software-properties-common
$sudo add-apt-repository -y ppa:ethereum/ethereum
$sudo apt-get update
$sudo apt-get install ethereum
To verify proper installation, execute following command on terminal
Step 3: create genesis.json file and copy following json block
Following are important parameters of genesis.json
- nonce: A 64-bit hash, which proves, combined with the mix-hash, that a sufficient amount of computation has been carried out on this block: the Proof-of-Work (PoW).The nonce is the cryptographically secure mining proof-of-work that proves beyond reasonable doubt that a particular amount of computation has been expended in the determination of this token value. (Yellowpager, 11.5. Mining Proof-of-Work).
- mixhash: A 256-bit hash which proves, combined with the nonce, that a sufficient amount of computation has been carried out on this block: the Proof-of-Work (PoW). The combination of nonce and mixhash must satisfy a mathematical condition described in the Yellowpaper, 4.3.4.
- difficulty: A scalar value corresponding to the difficulty level applied during the nonce discovering of this block. It defines the mining Target, which can be calculated from the previous block’s difficulty level and the timestamp. The higher the difficulty, the statistically more calculations a Miner must perform to discover a valid block. This value is used to control the Block generation time of a Blockchain, keeping the Block generation frequency within a target range.
- alloc: Allows defining a list of pre-filled wallets. That’s an Ethereum specific functionality to handle the “Ether pre-sale” period. Since we can mine local Ether quickly, we don’t use this option.
- coinbase: The 160-bit address to which all rewards (in Ether) collected from the successful mining of this block have been transferred. They are a sum of the mining reward itself and the Contract transaction execution refunds. Often named “beneficiary” in the specifications, sometimes “etherbase” in the online documentation. This can be anything in the Genesis Block since the value is set by the setting of the Miner when a new Block is created.
- timestamp: A scalar value equal to the reasonable output of Unix
time()function at this block inception. This mechanism enforces a homeostasis in terms of the time between blocks. A smaller period between the last two blocks results in an increase in the difficulty level and thus additional computation required to find the next valid block. If the period is too large, the difficulty, and expected time to the next block, is reduced. The timestamp also allows verifying the order of block within the chain (Yellowpaper, 4.3.4. (43)).
- gasLimit: A scalar value equal to the current chain-wide limit of Gas expenditure per block. High in our case to avoid being limited by this threshold during tests. Note: this does not indicate that we should not pay attention to the Gas consumption of our Contracts.
- config: Configuration to describe the chain itself. Specifically the chain ID, the consensus engines to use, as well as the block numbers of any relevant hard forks. Chainid is identifies the current chain and is used for replay protection. This is a unique value for your private chain.
Step 4: Initialise geth client with genesis.json, Execute following command from directory which has genssis.json. you can access geth command from any directory.
$geth init genesis.json
Following are default directory for ethereum data storage
- Mac: ~/Library/Ethereum
- Linux: ~/.ethereum
- Windows: %APPDATA%\Ethereum
Step 5: Create password.sec file in any directory you want. open password.sec file in your favourite text editor and type password which you like.
Step 6: create coinbase account using following command. Execute following command from directory in which has password.sec
$geth account new —-password password.sec
Step 6: Create startGeth.sh file (for linux/mac users) and copy following command. make startGeth.sh file as executable using $chmod a+x startGeth.sh. Make sure you provide password.sec file path
geth --networkid 4224 --mine --nodiscover --rpc --rpcport "8545" --port "30303" --rpccorsdomain "*" --nat "any" --rpcapi eth,web3,personal,net --unlock 0 --password "/<your direcotry>/password.sec" --rpcaddr 0.0.0.0
Parameters for geth command
- networkid value Network identifier (integer, 1=Frontier, 2=Morden (disused), 3=Ropsten, 4=Rinkeby) (default: 1)
- mine Enable mining
- nodiscover Disables the peer discovery mechanism (manual peer addition)
- rpc Enable the HTTP-RPC server
- rpcport value HTTP-RPC server listening port (default: 8545)
- port value Network listening port (default: 30303)
- rpccorsdomain value Comma separated list of domains from which to accept cross origin requests (browser enforced)
- nat value NAT port mapping mechanism (any|none|upnp|pmp|extip:<IP>) (default: “any”)
- rpcapi value API’s offered over the HTTP-RPC interface
- unlock value Comma separated list of accounts to unlock. 0 means 1st account or coinbase account which we have created in step 6.
- password value Password file to use for non-interactive password input
- rpcaddr value HTTP-RPC server listening interface (default: “localhost”)
Step 7: execute startGeth.sh file
Congratulations.. Your private Ethereum network is up and running now.