To understand Ethereum Privatenetwork first to understand the two official Ethereum network, now Ethereum officially provides two kinds of network: Production Environment Network Test network Testnet
The following is a brief explanation of the two types of networks. Ethereum Production Network
Ethereum's production network is, as its name implies, a network of truly valuable etheric coins. At present, the production network has generated more than 3 million of the blocks, but also in continuous generation. Dug out each with NT $10 or more in the mine. The Ethereum state in the production environment is so (screenshot since 2017-02-17)
Production environment Network advantages globalization, deployment in the Internet environment, smart contract code, execution, block calls, can be clearly viewed. Smart contracts deployed on a production environment that can be called by any application worldwide
Cons: Any contract execution consumes real etheric currency, which is real cash. Not suitable for development, debugging, and testing, all nodes are globalized, slow, and for some commercial applications, only a subset of nodes, such as 10-20 servers for distributed deployments, are required. Without the need to network around the world.
ethereum Test Network testnet
Ethereum's testing network is also officially provided, as the name implies is for users to develop, debug and test. The above contract execution does not consume the real etheric currency. Which means no money.
So if you develop a simple smart contract, it is enough to use a test network, and users can focus more on the writing of smart contracts.
But because the network is officially provided, the understanding of the underlying implementations of Ethereum technology, the various parametric interfaces of Geth, and the true performance of the entire Ethereum technology is much weaker. So from the perspective of development, a better choice is the private Network, from the bottom of the technology to deeply understand Ethereum.
Test environment Network Advantages Contract execution does not consume real money globalization, deployed in the Internet environment, smart contract code, execution, block calls, can be clearly viewed. A smart contract deployed on a test environment that can be called by any application worldwide
Cons: All nodes are globalized, slower-speed test networks cannot be used as actual landing environments for commercial applications
ethereum private network Privatenetwork
Ethereum's private network, as its name implies, is a private network created by the user through Geth, a network that is ideally suited for development, commissioning, and testing.
Advantages for developers to understand the deep understanding of the technology of Ethereum because of the relatively small number of nodes, faster users can be created at any time, at any time to destroy, rebuild an ethereum network arbitrarily add nodes, or delete nodes, can be established on the server, but also on their own Windows or Mac machine, Even a single machine can build multiple nodes and implement a multi-node private network on a single machine.
Disadvantage because it is not globalized, only the nodes within the private network can see the execution, invocation, etc. of the smart contract. the next chapter explains: The actual combat to build a private network.
In this chapter we will combat how to use Geth, how to build ethereum private network.
Previously said Geth is one of three tools to implement the Ethereum protocol, as Geth is officially respected and personal Energy Limited, for the other two tools to build a private network, please refer to the online information.
The following Geth actual combat, implemented on the MacBook, for Windows, the comparison is similar.
Step 1: Create a directory and Genesis.json
Create a directory in command-line mode, such as Tmpprivate
Create the file Genesis.json and fill in the following content.
{
"nonce": "0x0000000000000042",
"timestamp": "0x0",
"Parenthash": " 0x0000000000000000000000000000000000000000000000000000000000000000 ",
" Extradata ":" 0x0 ",
" GasLimit ":" 0x80000000 ",
" difficulty ":" 0x1 ",
" Mixhash ":" 0x0000000000000000000000000000000000000000000000000000000000000000 ",
" Coinbase ":" 0x3333333333333333333333333333333333333333 ",
" Alloc ": { }
}
Users can vim, or can use other editors such as sublime, etc., personally recommend the use of atom
Atom website Address: https://atom.io/
Atom is a text editor supported by Google, a modern editor that you can customize to do anything, followed by file and code demonstrations that will be performed primarily on atom.
Once created, in atom, there should be only one Genesis.json under this folder
Step 2: Execute commands to create a Genesis block
Switch back to command line, execute command, create Genesis block
Geth--datadir "./" Init Genesis.json
The results of the implementation are as follows:
At this point, you can note that at this time, the current directory will be added two folders Geth and KeyStore Geth is saved in the blockchain related data keystore is stored in the chain of user information
The directory structure that you see from Atom is this:
Step 3: Create your own private chain
Execute one of the simplest Geth commands to create your own private chain
Geth--datadir "./"--nodiscover console 2>>geth.log
Geth a lot of parameters, interested can play geth–help to get detailed information, we will also in the following chapters on the key parameter items are explained. The command line should look like this at this point:
Step 4: Create a user on your own private chain
Enter the command eth.accounts and we will find that the return value is []
This is because while the ethereum private chain has been created, there are no accounts yet. Enter the command personal.newaccount ("xxx"), the command will create a new user, the user's password is xxx. Of course the user can also change the XXX to 123, or 123456, or any password re-enter the command eth.accounts, we will find a new user was created, which means that we have created an account, repeat Personal.newaccount () & Eth.accounts We can create a number of accounts.
The entire command screenshot is as follows:
Step 5: Log of the output chunk chain
In step 3, we execute the code
Geth--datadir "./"--nodiscover console 2>>geth.log
The code console 2>> Geth.log represents a portion of the console output, output to the file Geth.log up. Open another terminal, locate the directory where the Geth.log is located, execute the command tail-f Geth.log and continue to output the Ethereum log
The entire process is shown in the following figure:
Step 6: The most important step is to start mining.
Execute command Miner.start () on the command line and start digging on our blockchain
At this point the output of the Geth.log should be this
Wait until 100%. This ethereum private chain will be officially launched, and continue to generate the Ethereum. Note the point: 1. Ether coins dug into the mine will be covered by default in the first account, i.e. eth.acccounts[0]. 2. Mining is the basis for implementing smart contracts. If you stop digging, not only will the etheric currency stop generating, but the call of all smart contracts will not work. 3. If you really want to stop mining, you can execute command miner.stop () to stop mining 4. According to the above command, it should be possible to achieve ethereum mining. If not, it could be a chain that existed before, and the previous data should be deleted. You can delete the ~/.ethash folder and the files inside the Mac, then Step 7: Eventually, when the mining starts, the logs are like this.
Step 8: After mining starts, view the number of etheric coins in the master account
ACC0 = eth.accounts[0]
eth.getbalance (ACC0)
As long as the result is not 0, that means mining success.
in the next chapter, we will explain some of the concepts in Geth, as well as some basic commands