Crypto Press

Latest Crypto Discussions and Mining



Part two of my hands on tutorial series on Ethereum. In the first video we installed Geth – in this one we actually get our hands dirty and start using it.

We are just creating a private local ethereal network – with two nodes – I show how to initialise a new blockchain from a sample genesis block, how to start the javascript console and some basic commands to get you started.

I start a miner, show the block height increasing and that the blockchain is being communicated across both separate nodes.

This is intended to be a very hands on tutorial so please follow along.

______________________________________________________________

Here is the script from the session.

NOTE angle brackets i.e. the GREATER THAN SYMBOL are not allowed in the description so I’ve replaced with &gt – you need to replace with the GREATER THAN symbol when running the command

0. Set up the environment

cd ~
mkdir ethereum

echo ‘export ethereum_home=/Users/mattthomas/ethereum’ (double right arrow) ~/.bash_profile ~/.bash_profile

cd ethereum
vi $ethereum_home/genesis.json
(pasre this with cmd v in edit mode)

{
“nonce”: “0x0000000000000042”,
“timestamp”: “0x0”,
“parentHash”: “0x0000000000000000000000000000000000000000000000000000000000000000”,
“extraData”: “0x0”,
“gasLimit”: “0x8000000”,
“difficulty”: “0x400”,
“mixhash”: “0x0000000000000000000000000000000000000000000000000000000000000000”,
“coinbase”: “0x3333333333333333333333333333333333333333”,
“alloc”: {
}
}

Save with esc !wq

1. initialise the block
geth –datadir “$ethereum_home/youtube1” init “$ethereum_home/genesis.json”

2. start the console
geth –datadir “$ethereum_home/chain5” console 2 &gt console.log

3.create a 2nd node
geth –datadir “$ethereum_home/youtube1-a” init “$ethereum_home/genesis.json”

4. Start on a different port and specify networkid
geth –datadir “$ethereum_home/youtube1-a” –port 30304 –nodiscover –networkid 1234 console 2 &gt console.log

5. get the admin.nodeInfo enode from the second instance and copy it into admin.addPeer in the first node

6. Restart specifying IPC path
geth –datadir “$ethereum_home/youtube1-a” –port 30304 –nodiscover –ipcpath “$ethereum_home/youtube1-a/geth.ipc” –networkid 1234 console 2 &gt console.log

7 run get attach to attach another window to the node using the pic file
geth attach ipc:$ethereum_home/youtube1-a/geth.ipc

8 Key commands from the javascript console
Personal.newAccount()
(add password)
Miner.start(1) – start mining
eth.blockNumber – current block height
eth.getBlock(number).miner – miner of block at that number
eth.getBalance(account address) – current balance of that account

27 thoughts on “2 How to create a local private multi-node Ethereum network (geth console) – Ethereum from scratch:

  1. Hi . thank you for greeat tutorial. I have a problem associated with watch-only wallet. Can I make a peer and make it watch-only . The watch only wallet should generate addresses, read transaction and balances.and when I recieve some ETH it should be read-only.. Is there a way to do that ?

  2. Awesome Video!!!
    I am trying to replicate the same on Windows system. I see that the genesis.json mentioned here doesn't work. I modified mine and the following is working:

    {
    "nonce": "0x0000000000000042",
    "timestamp": "0x00",
    "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "extraData": "0x00",
    "gasLimit": "0x8000000",
    "difficulty": "0x400",
    "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "coinbase": "0x3333333333333333333333333333333333333333",
    "config": {
    "chainId": 15,
    "homesteadBlock": 0,
    "eip155Block": 0,
    "eip158Block": 0
    },
    "alloc": {
    }
    }

  3. TL;DR – update the provided genesis block snippet to have a difficulty of 20 and re-do all the steps.

    For everyone stuck on the miner.start(1) – It doesn't matter that yours returned null, probably just an API change since filming this video. And you aren't seeing the blockNumer increase because the difficulty seems to be set way to high. you need to modify the genesis block to have a difficulty of 20 and then redo all the steps.

  4. Matt, great work, appreciate.

    Anyone in this thread got the solution of miner.start(1) return null, and block number not increasing.

    Advance thanks for any sort of help and suggestion.

  5. getting error..
    geth –datadir "$ethereum_home/youtube1" init "$ethereum_home/genesis.json"
    INFO [05-24|14:52:42] Maximum peer count ETH=25 LES=0 total=25
    Fatal: Failed to create the protocol stack: mkdir /youtube1: permission denied

  6. panic: runtime error: invalid memory address or nil pointer dereference
    [signal 0xc0000005 code=0x0 addr=0x0 pc=0xa72182]

    I am getting this error while running another node.
    unable to run two nodes geth console at same time.
    solution:???

  7. Everything works but during the bonus section when I assign a path for the ipc (geth –datadir “$ethereum_home/mynode01” –networkid 1234 –ipcpath “$ethereum_home/mynode01/geth.ipc” console) geth creates a completely new directory structure within the ethereum folder and the name of the first folder is just a quote character. So the folder structure created within the ethereum folder goes like this [ " -> Users/name/ethreum/mynode02/ ]. It basically cloned the same directory I have been using into the ethereum folder plus it adds a top level folder name with just a quote character. Very bizarre.

  8. Issues with Init (using GETH version is 1.8.1-stable):

    1: Got following errors when executing: geth –datadir "$ethereum_home/youtube1" init "$ethereum_home/genesis.json"

    Fatal: invalid genesis file: json: cannot unmarshal hex string of odd length into Go struct field Genesis.extraData of type hexutil.Bytes

    FIX was to add extra 0 to timestamp and extradata fields

    2: Then got following error on init:
    Fatal: Failed to write genesis block: genesis has no chain configuration

    FIX: Add config {} element to JSON file.

    Summary: New JSON file for Genesis Block.

    {
    "config": {},
    "nonce": "0x0000000000000042",
    "timestamp": "0x00",
    "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "extraData": "0x00",
    "gasLimit": "0x8000000",
    "difficulty": "0x400",
    "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "coinbase": "0x3333333333333333333333333333333333333333",
    "alloc": { }
    }

  9. Matt, thank you for the great tutorial. When I do Miner.start(1), I get the following

    INFO [01-23|22:04:10] Updated mining threads threads=1
    INFO [01-23|22:04:10] Transaction pool price threshold updated price=18000000000
    INFO [01-23|22:04:10] Starting mining operation
    null
    > INFO [01-23|22:04:10] Commit new mining work number=35 txs=0 uncles=0 elapsed=145.101µs
    INFO [01-23|22:05:23] Successfully sealed new block number=35 hash=f6d3cc…ba6aa9
    INFO [01-23|22:05:23] ? mined potential block number=35 hash=f6d3cc…ba6aa9
    INFO [01-23|22:05:23] Commit new mining work number=36 txs=0 uncles=0 elapsed=117.5µs

    and this does not stop.

    Appreciate your help.

Leave comment

Your email address will not be published. Required fields are marked with *.

This site uses Akismet to reduce spam. Learn how your comment data is processed.