How to setup miners in Ethereum

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

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:

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.

--

--

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

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