ConsenSys/local_ethereum_network

Name: local_ethereum_network

Owner: ConsenSys

Description: Creating a Local Ethereum Blockchain

Forked from: krisrandall/codecave_ethereum_blockchain

Created: 2018-01-05 05:11:23.0

Updated: 2018-01-10 19:29:54.0

Pushed: 2018-01-12 16:51:56.0

Homepage: null

Size: 7

Language: null

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Local Ethereum Network

See also : https://github.com/ethereum/go-ethereum/wiki/Private-network

Setting up your Ethereum Node(s)
1. Prereq : Install Geth

For windows : https://ethereum.github.io/go-ethereum/downloads/

For a mac :

ew update
ew upgrade
ew tap ethereum/ethereum
ew install ethereum

For linux (Ubuntu)

 apt-get install software-properties-common
 add-apt-repository -y ppa:ethereum/ethereum
 apt-get update
 apt-get install ethereum
2. Prereq : create /projects

Create a /projects symbolic link
(Note: This step is simply so “/projects” can be used in all other commands, instead you could use full paths, or set an env var)

dir <my projects folder>
do ln -s <my projects folder> /projects
3. Create local_ethereum_blockchain folder
dir /projects/local_ethereum_blockchain
4. Create the genesis block config

Create this file : /projects/local_ethereum_blockchain/genesis.json

With the following contents :


 "config": {
   "chainId": 1000,
   "homesteadBlock": 0,
   "eip155Block": 0,
   "eip158Block": 0
            },
 "nonce": "0x0000000000000061",
 "timestamp": "0x0",
 "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", 
 "gasLimit": "0x8000000",   
 "difficulty": "0x100",    
 "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
 "coinbase": "0x3333333333333333333333333333333333333333",
 "alloc": {}

(info about the genesis file)

5. Initialise an Ethereum node
th --datadir /projects/local_ethereum_blockchain/node1 init /projects/local_ethereum_blockchain/genesis.json
6. Start that Ethereum node
th --datadir /projects/local_ethereum_blockchain/node1 --networkid 1000 console
7. Initialise another Ethereum node
th --datadir /projects/local_ethereum_blockchain/node-2 init /projects/local_ethereum_blockchain/genesis.json
8. Start the 2nd Ethereum node
th --datadir /projects/local_ethereum_blockchain/node-2 --port 30304 --nodiscover --networkid 1000 console
9. Connect one node to the other

In one geth console :

min.nodeInfo.enode

In the other console :

min.addPeer( <the enode value from the first console> )
Useful geth commands
Node info
min.nodeInfo
Peers

Show peers

min.peers

How many peers ?

min.peers.length
Create an account

You need an account to do be able to do things like mining

rsonal.newAccount()

And make sure your remember/save the password!

Unlock account

Neccessary before some actions

rsonal.unlockAccount( eth.accounts[0] )
Start mining
ner.start(1)

The first block may take a while to mine, allow a few minutes

Stop mining
ner.stop() 
Current block number
h.blockNumber
Details of current block
h.getBlock( eth.blockNumber ) 
Which node minded the last block
h.getBlock(eth.blockNumber).miner
Account balance, in ether
b3.fromWei(eth.getBalance(eth.accounts[0]))
Transfer ether between accounts

First get the account numbers by doing

> eth.accounts

Then unlock the account you are sending from

> personal.unlockAccount( <from account> )

eg.

> personal.unlockAccount(eth.accounts[0])

Finally transfer 1 ether

h.sendTransaction({from: "<from account>", to: "<to account>", value: web3.toWei(1, "ether")})
Exit
it

(This will also stop the node from running if it was started using $ geth console (as opposed to $ geth attach))

Connect to other nodes on your network
  1. Get the IP of the node : $ ifconfig|grep netmask|awk '{print $2}'

  2. Get the enode of the node : > admin.nodeInfo.enode

  3. REPLACE [::] in the enode string with the [<ip address>]

  4. On your console > admin.addPeer(< the enode string with the ip address in it>)


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.