5.5 KiB
| title | sort_key |
|---|---|
| Creating a Private Network with Puppeth | B |
A private Ethereum network is useful for dapp testing, privacy, starting a local network for a hackathon, and many other purposes. An Ethereum network is private if the nodes are not connected to a main network.
Setting up a private network can be a complex task; you need to configure a genesis block, different node types, miners, monitoring, and more. To help get you started, puppeth is a CLI tool that leads you through the steps to create a private network, building it with Docker containers, and in creating a new Ethereum network down to the genesis, bootnodes, signers, ethstats, faucet, dashboard and more, without the hassle that it normally takes to configure all these services one by one. Puppeth uses ssh to connect into remote servers and builds its network components out of docker containers using docker-compose. The user is guided through the process via a command-line wizard that does the heavy lifting and topology configuration automatically behind the scenes.
Prerequisites
Any node you want to connect to the private network has some prerequisites:
- The ethereum toolchain
- Docker
- A running instance of Geth
You may have these already, but for ease of testing, we have a vagrant file you can use to create a two-node test cluster.
With your nodes and geth running, run the following command:
puppeth
Puppeth guides you through adding nodes to a private network, and this tutorial assumes you use the two-node cluster generated by the vagrant file above, if not, adjust your settings.
First, create a name for your network, for example, vagrantnet.
Puppeth then gives you four choices. Before any other steps, you need to add the instances. The IP addresses for the Vagrant nodes are "192.168.56.101" and "192.168.56.102". Select option 3 again, and then 2, and add the IP address for one instance in the format vagrant@192.168.56.101, the password is "vagrant". Select option 3 again for adding the second node.
You should now see a table listing the two nodes.
Next, create a new genesis by selecting option 2. Pick the default choices for the first three questions. For the fourth question that asks "Which accounts are allowed to seal?" and for the fifth question that asks "Which accounts should be pre-funded?", add one or more of the account addresses displayed in the Geth output from the Vagrant up process. When you have finished adding addresses for each question, enter a blank value to finish the step.
Question six asks if you want the pre-compiled contracts pre-funded, type yes. These are a set of contracts that are used for computationally intensive operations that would cost too much gas to implement.
Question seven asks if you want to specify a chain ID, take the default option, which is to create a random ID.
With the genesis created, select option 4 from the main menu to deploy network components in a variety of Docker containers.
Start by selecting option 1 to deploy Ethstats to either instance to monitor statistics across the cluster. You can accept the defaults for all of the following questions except the "API password", which you can set as you want. Once setup is finished, you can now see ethstats listed in the instance table, and opening _{IP_ADDRESS:PORT} in your browser should display the ethstats dashboard.
Next, you need to deploy a bootnode component by selecting option 4 from the main menu, then 3 to deploy a new component, and then 2. Pick the same instance you deployed ethstats to. Pick the default options for all the remaining questions, except the data location (set to /home/vagrant/bootdata), and the name of the node (bootnode). You should now see bootnode listed in the instances table, and the ethstats dashboard.
Next, deploy a sealer component, a node which serves as the miner of new blocks. From the main menu, select 4 to manage network components, then 4, and then 3. Choose the same instance as every other component so far. Again pick default options for all the remaining questions, except the data location (set to /home/vagrant/sealerdata), and the name of the node (sealernode). For the question that asks for the "signer's key JSON", you can find this file in the data directory specified for the node during geth initialization. If you're using the Vagrant file above, this file is in /home/vagrant/node1/keystore. Copy and paste the value of this field as the answer to the question, the "unlock password" is password. As mining operations typically need more than one node, also add the sealer component to the other node, using the same values as for the other node, except that you need to specify a different port (when running both nodes on the same machine), a different name, and paste the signers key from the second node. You should now see `sealernode's listed in the instances table, and in the ethstats dashboard.
Finally, add a dashboard component to view and manage the nodes and components. From the main menu, select 4 to manage network components, then 6, and then 7. Choose the same instance as every other component so far. Pick the default options for all the questions, and select the main node you installed each service on, or not to lost the service if you never installed it. You should now see the dashboard listed in the instances table, and at 192.168.56.101:{PORT}.
This tutorial was heavily influenced and helped by Bruno Skvorc's post.