After understanding and learning through various materials, I decided to start building a private chain environment based on Ethereum go-ethereum. Since my computer system is win7, in order to avoid too many inexplicable problems in the window environment, I specially built a virtual system of ubuntu16.04 version through vm. The following content is based on ubuntu16.04 system.
go-ethereum client
Download Address & Reference Manual
First of all, you can check the address of the go-ethereum project on git:
https://github.com/ethereum/Go-ethereum
You can click on the wiki tab on the project, or visit the wiki at:
https://github.com/ethereum/Go-ethereum/wiki/Building-Ethereum
Select the installation instructions for the ubuntu system on the wiki page, or you can directly visit the following link:
https://github.com/ethereum/go-ethereum/wiki/Installation-Instructions-for-Ubuntu
Installation command under ubuntu
Install ssh before installation so that you can connect to Ubuntu remotely using a client like putty or SecureCRT.
sudo apt-get install ssh
Open the command line window, or use the shortcut key CTL+ALT+T, and enter the following commands in sequence, and the installation is successful:
sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo add-apt-repository -y ppa:ethereum/ethereum-dev
sudo apt-get update
sudo apt-get install ethereum
PS: If you need to rely on other components during the installation process, install other components first. In addition, in the ubuntu16.04 version, the sudo apt-get install command can be shortened to sudo apt install.
installation test
After the installation is complete, enter at the command line:
geth --help
If the prompt information of various command line parameters is displayed, the installation is successful.
genesis block
After the above installation is successful, start it directly to connect to the public chain. Now create the private chain by configuring the genesis block. In the same network, the genesis block must be the same, otherwise it cannot be connected.
Create an eth root directory, and create a new creation block json file piccgenesis.json in the root directory. The content is as follows:
{
"config": {
"chainId": 15,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"coinbase" : "0x0000000000000000000000000000000000000000",
"difficulty" : "0x40000",
"extraData" : "",
"gasLimit" : "0xffffffff",
"nonce" : "0x0000000000000042",
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp" : "0x00",
"alloc": { }
}
Parameter explanation:
parameter name | Parameter Description |
---|---|
mixhash | Used in conjunction with nonce for mining, the hash generated by part of the previous block. Note that the setting of him and nonce needs to meet the conditions described in the Yellow paper of Ethereum, 4.3.4. Block Header Validity, (44). |
nonce | nonce is a 64-bit random number used for mining. Note that the settings of him and mixhash need to meet the conditions described in the Yellow paper, 4.3.4. Block Header Validity, (44) of Ethereum. |
difficulty | Set the difficulty of the current block. If the difficulty is too high, cpu mining will be difficult. Set a lower difficulty here. |
alloc | It is used to preset an account and the amount of ether in the account. Because private chain mining is easier, we do not need to preset an account with coins, and we can create it ourselves when we need it. |
coinbase | Miner's account, just fill in |
timestamp | Set the timestamp of the genesis block |
parentHash | The hash value of the previous block, because it is a genesis block, so this value is 0 |
extraData | Additional information, just fill in, you can fill in your personal information |
gasLimit | This value sets the limit on the total consumption of GAS, which is used to limit the sum of transaction information that the block can contain. Because we are a private chain, fill in the maximum value. |
Use the following command to connect to the public chain:
$nohup geth --datadir "/data" --cache 512 --rpc --rpcaddr 0.0.0.0&
// 后台执行
geth --datadir "/data" --cache 512 --rpc --rpcaddr 0.0.0.0
//可以看到执行日志和状态
Start a private chain node
Parameters required to start a private node
parameter name | Parameter Description |
---|---|
identity | The label of the blockchain, fill in casually, used to indicate the name of the current network |
init | Specify the location of the genesis block file, and create the initial block |
datadir | Set the location where the current blockchain network data is stored |
port | network listening port |
rpc | Start rpc communication, can deploy and debug smart contracts |
rpcapi | Set the rpc client that allows connections, generally db, eth, net, web3 |
networkid | Set the network ID of the current blockchain, used to distinguish different networks, is a number |
console | Start command line mode, you can execute commands in Geth |
Initialize & Start
The directory where I start eth is:
/home/cuijb/eth
Place the genesis block json file just configured in this directory: piccgenesis.json
initialization
There are two ways to initialize the genesis block:
Method 1: Execute the command to initialize first (note that it needs to be executed in the root directory where you are prepared to prevent eth)
$ geth --datadir "./" init piccgenesis.jso
The following figure appears:
Create your own private chain
Execute the simplest geth command to create your own private chain
geth --datadir "./" --nodiscover console 2>>geth.log
Parameter description: --nodiscover : Indicates the private chain I created, which does not allow others to join, my own separate network.
There are many parameter items for geth. If you are interested, you can hit geth –help to get detailed information. We will also explain the key parameter items in the following chapters. You can see the display as follows:
Then there are related command operations, which will be further explained in the next blog.
2017-11-30 Written in Shenzhen