Skip to content

ansmirnov/ethereum-run-private-network-with-geth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

Ethereum: run a private network with geth

Preparation

Install 3 nodes with docker.

Pull geth docker image

At each node.

docker pull ethereum/client-go

See help

docker run --rm ethereum/client-go --help

Create volume

At each node.

docker volume create geth-data

Generate addresses

At mining node.

docker run --rm --mount source=geth-data,target=/root/.ethereum -it ethereum/client-go account new

Enter password.

Save the address. For example, 0x0b00eE34d8C298C5dbf51814f0942e7A3ADcDB91.

Configure genesis block

We are using PoA (clique) consensus.

  1. Select random chainId.
  2. Replace addresses in extradata and alloc.

Copy this file at each node.

{
  "config": {
    "chainId": 65165461561,
    "homesteadBlock": 0,
    "eip150Block": 0,
    "eip155Block": 0,
    "eip158Block": 0,
    "byzantiumBlock": 0,
    "constantinopleBlock": 0,
    "petersburgBlock": 0,
    "clique": {
      "period": 5,
      "epoch": 30000
    }
  },
  "difficulty": "1",
  "gasLimit": "8000000",
  "extradata": "0x00000000000000000000000000000000000000000000000000000000000000000b00eE34d8C298C5dbf51814f0942e7A3ADcDB910000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  "alloc": {
    "0x0b00eE34d8C298C5dbf51814f0942e7A3ADcDB91": { "balance": "1000000000000000000000000000000000" }
  }
}

Initializing the Geth Database

At each node.

docker run --rm --mount source=geth-data,target=/root/.ethereum -v`pwd`/genesis.json:/etc/genesis.json -it ethereum/client-go init /etc/genesis.json

Run mining node

docker run --rm --name geth-private --detach --network host --mount source=geth-data,target=/root/.ethereum -v`pwd`/password:/etc/ethereum-password -it ethereum/client-go --networkid 65165461561 --unlock 0x0b00eE34d8C298C5dbf51814f0942e7A3ADcDB91 --password /etc/ethereum-password --mine

Get bootnode ENR

docker exec geth-private geth attach --exec admin.nodeInfo.enode

Run another node

BOOT_NODES=
docker run --rm --name geth-private --network host --mount source=geth-data,target=/root/.ethereum -it ethereum/client-go --networkid 65165461561 --http --http.addr 0.0.0.0 --bootnode $BOOT_NODES

Run geth console

docker exec -it geth-private geth attach

Show geth logs

docker logs geth-private

Kill the node

docker kill geth-private

References

  1. https://geth.ethereum.org/docs/interface/private-network

About

Launching a private Ethereum network based on Geth

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published