How to setup miners in Ethereum

ABHISHEK KUMAR
5 min readJan 16, 2018

For windows installation:

1. Install geth (https://ethereum.github.io/go-ethereum/downloads/)

2. Install latest version of nodejs as well as npm.

3. Install web3 and solidity.

4. Install express-generator

5. Install truffle or embark or any other framework to make a miner as a server.

6. check whether it is installed or not by typing geth in cmd prompt.

For Linux Installation:

1.  wget https://gethstore.blob.core.windows.net/builds/geth-linux-arm7-1.5.7-da2a22c3.tar.gz2.  tar zxvf geth-linux-arm7-1.5.7-da2a22c3.tar.gz3.  cd geth-linux-arm7-1.5.7-da2a22c34.  sudo cp geth /usr/local/bin5.  geth version6.  geth

To run in full miner (run in command prompt):

1. mkdir –p /Ethereum/miner1

2. mkdir –p /Ethereum/miner2

3. make a genesis file i.e in the name of genesis.json

genesis.json file contains

  1. 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. Block Header Validity, (44). It allows to verify that the Block has really been cryptographically mined, thus, from this aspect, is valid.
  2. 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 combination of nonce and mixhash must satisfy a mathematical condition described in the Yellowpaper, 4.3.4. Block Header Validity, (44), and allows to verify that the Block has really been cryptographically mined and thus, from this aspect, is valid. 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).
  3. 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. On the test network, we keep this value low to avoid waiting during tests, since the discovery of a valid Block is required to execute a transaction on the Blockchain.
  4. 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.
  5. 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.
  6. 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.
  7. parentHash The Keccak 256-bit hash of the entire parent block header (including its nonce and mixhash). Pointer to the parent block, thus effectively building the chain of blocks. In the case of the Genesis block, and only in this case, it’s 0.
  8. extraData An optional free, but max. 32-byte long space to conserve smart things for ethernity.
  9. 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.

file should be like this “genesis.json” and contains should be

{"nonce": "0x0000000000000042","mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000","difficulty": "0x400","alloc": {},"coinbase": "0x0000000000000000000000000000000000000000","timestamp": "0x00","parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000","extraData": "0x436861696e536b696c6c732047656e6573697320426c6f636b","gasLimit": "0xffffffff","config": {"chainId": 42,"homesteadBlock": 0,"eip155Block": 0,"eip158Block": 0}}

Initialize the private blockchain

It’s time to initialize the private blockchain with the genesis block.

This operation will create the initial database stored under the data directory dedicated to each miner.

Initialize miner #1

1. cd ~/Ethereum

2. geth –datadir ~/Ethereum/miner1 init genesis.json

3. it contains the database of your private blockchain and keystore.

Initialize miner #2

1. cd ~/Ethereum

2. geth –datadir ~/Ethereum/miner2 init genesis.json

3. it contains the database of your private blockchain and keystore.

Create accounts geth --datadir ~/Ethereum/miner1 account newCreate accounts geth --datadir ~/Ethereum/miner2 account new

4. while creating u will be asked for password remember that password

5. check how many accounts are there by running cmd

6. geth –datadir ~/Ethereum/miner1 account list

7. geth –datadir ~/Ethereum/miner2 account list

8. Now make password.sec file in Ethereum folder and put your account password over there.

9. Now u r both miner is setup

10. Run the miner by following cmds

11. geth --identity "miner1" --networkid 42 --datadir "~/Ethereum/miner1" --nodiscover --mine --rpc --rpcport "8042" --port "30303" –rpcapi “db,eth,net,web3,miner” --unlock 0 --password ~/Ethereum/miner1/password.sec --ipcpath "~/Library/Ethereum/geth.ipc"

12. geth --identity "miner2" --networkid 42 --datadir "~/Ethereum/miner2" --nodiscover --mine --rpc --rpcport "8044" --port "30304" –rpcapi “db,eth,net,web3,miner” --unlock 0 --password ~/Ethereum/miner2/password.sec --ipcpath "~/Ethereum/geth.ipc"

13. now run in another terminal

14. geth attach if it not working

geth attach ipc://./pipe/Ethereum/geth.ipc

pass the path of ipc.

The meaning of the main parameters is the following:

  1. identity: name of our node
  2. networkid: this network identifier is an arbitrary value that will be used to pair all nodes of the same network. This value must be different from 0 to 3 (already used by the live chains)
  3. datadir: folder where our private blockchain stores its data
  4. rpc and rpcport: enabling HTTP-RPC server and giving its listening port number.
  5. port: network listening port number, on which nodes connect to one another to spread new transactions and blocks.
  6. nodiscover: disable the discovery mechanism (we will pair our nodes later).
  7. mine: mine ethers and transactions.
  8. unlock: id of the default account.
  9. password: path to the file containing the password of the default account.
  10. ipcpath: path where to store the filename for IPC socket/pipe

In geth attach type these cmds

1. admin.nodeInfo.enode (shows node information)

2. eth.coinbase

3. eth.accounts

4. eth.getBalance(eth.coinbase)

5. eth.getBalance(eth.accounts[1])

6. personal.unlockAccount(eth.accounts[3], ‘hello’)

7. web3.fromWei( eth.getBalance(eth.accounts[3]))

8. eth.sendTransaction({from: “0x account no of sender “, to: “0x account no of receiver”, value: web3.toWei(100, “ether”)})

9. eth.pendingTransaction

Now attach two nodes

1. look the node information (admin.nodeInfo.enode)

2. make static-nodes.json file in both the miners.

Put the both node information on that like ["enode://b8863bf7c8bb13c3afc459d5bf6e664ed4200f50b86aebf5c70d205d32dd77cf2a888b8adf4a8e55ab13e8ab5ad7ec93b7027e73ca70f87af5b425197712d272@192.168.1.39:30303","enode://41be9d79ebe23b59f21cbaf5b584bec5760d448ff6f57ca65ada89c36e7a05f20d9cfdd091b81464b9c2f0601555c29c3d2d88c9b8ab39b05c0e505dc297ebb7@192.168.1.39:30304"]

3. restart u r miner

4. and type admin.peers cmd and see the peers

now both nodes are attached and u can transfer balance from one node to another node.

In the next tutorial i will show you how to write smart contract.

--

--

ABHISHEK KUMAR

DevOps/Cloud | 2x AWS Certified | 1x Terraform Certified | 1x CKAD Certified | Gitlab