Tutorial: Operating a Private Network¶
Operating a private network¶
Maintaining your own private network is more involved as a lot of configurations taken for granted in the official networks need to be manually set up.
Defining the private genesis state¶
First, you’ll need to create the genesis state of your networks, which all nodes need to be aware of and agree upon. This consists of a small JSON file (e.g. call it genesis.json
):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
The above fields should be fine for most purposes, although we’d recommend changing the nonce
to some random value so you prevent unknown remote nodes from being able to connect to you. If you’d like to pre-fund some accounts for easier testing, create the accounts and populate the alloc
field with their addresses.
1 2 3 4 5 6 7 8 |
|
With the genesis state defined in the above JSON file, you’ll need to initialize every geth
node with it prior to starting it up to ensure all blockchain parameters are correctly set:
1 |
|
Creating the rendezvous point¶
With all nodes that you want to run initialized to the desired genesis state, you’ll need to start a bootstrap node that others can use to find each other in your network and/or over the internet. The clean way is to configure and run a dedicated bootnode:
1 2 |
|
With the bootnode online, it will display an enode
URL that other nodes can use to connect to it and exchange peer information. Make sure to replace the displayed IP address information (most probably [::]
) with your externally accessible IP to get the actual enode
URL.
Note
You could also use a full-fledged geth
node as a bootnode, but it’s the less recommended way.
Starting up your member nodes¶
With the bootnode operational and externally reachable (you can try telnet <ip> <port>
to ensure it’s indeed reachable), start every subsequent geth
node pointed to the bootnode for peer discovery via the --bootnodes
flag. It will probably also be desirable to keep the data directory of your private network separated, so do also specify a custom --datadir
flag.
1 |
|
Note
Since your network will be completely cut off from the main and test networks, you’ll also need to configure a miner to process transactions and create new blocks for you.
Running a private miner¶
Mining on the public Ethereum network is a complex task as it’s only feasible using GPUs, requiring an OpenCL or CUDA enabled ethminer
instance. For information on such a setup, please consult the EtherMining subreddit and the ethminer repository.
In a private network setting, however a single CPU miner instance is more than enough for practical purposes as it can produce a stable stream of blocks at the correct intervals without needing heavy resources (consider running on a single thread, no need for multiple ones either). To start a geth
instance for mining, run it with all your usual flags, extended by:
1 |
|
Which will start mining blocks and transactions on a single CPU thread, crediting all proceedings to the account specified by --etherbase
. You can further tune the mining by changing the default gas limit blocks converge to (--targetgaslimit
) and the price transactions are accepted at (--gasprice
).