Build a private block chain environment __ block chain

Source: Internet
Author: User
Tags install go

Recently in the research block chain. Plan to build a test environment to start running. The whole construction process is recorded here for up-and reference. Overall, it is divided into three steps to install the relevant software, initialize the system, set up the cluster, and the last step to dig the mine. We are using the ether, compared to other blocks of the chain, which is a mature environment. Although the recent hard branch of the event, for enterprise applications, the function is still relatively perfect. Install Deployment 1. Install Go Environment

If the machine can not be on the network, you have to configure the agent. Ubuntu Configuration Agent way a lot of online, not introduced here.

  Curl-o https://storage.googleapis.com/golang/go1.5.1.linux-amd64.tar.gz
  tar-c/usr/local-xzf go1.5.1.linux-amd64.tar.gz
  mkdir-p ~/go echo "Export gopath= $HOME/go" >> ~/.BASHRC
  echo "Export path=$ PATH: $HOME/go/bin:/usr/local/go/bin ">> ~/.bashrc
  Source ~/.BASHRC
2. Install Ethereum
  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

This problem was encountered while performing sudo add-apt-repository-y ppa:ethereum/ethereum:

  root@ubuntu-kvm:~# sudo add-apt-repository-y ppa:ethereum/ethereum
  cannot add PPA: ' Ppa:ethereum/ethereum '.
   Please check this PPA name or format is correct.

According to ask Ubuntu's comments, modified to:

  sudo apt-get install Software-properties-common
  sudo-e add-apt-repository-y ppa:ethereum/ethereum
  Add-apt-repository-y ppa:ethereum/ethereum-dev
  sudo apt-get update
  sudo apt-get install Ethereum
3. Install the SOLC compiler
  sudo add-apt-repository ppa:ethereum/ethereum-qt
  sudo add-apt-repository ppa:ethereum/ethereum
  sudo apt-get Update
  sudo apt-get install Cpp-ethereum

Similarly, if you encounter a warning for the PPA name error, do the following:

  Sudo-e add-apt-repository ppa:ethereum/ethereum-qt
  sudo-e add-apt-repository ppa:ethereum/ethereum
  sudo Apt-get Update
  sudo apt-get install Cpp-ethereum

The relevant software has been installed. build a private chain 1. Start Geth service

  Geth--datadir "/root/chain" console

Where DataDir is used to specify the data directory. This directory cannot be created beforehand, or the command will fail. The results of the implementation are as follows:

2. Create Account

After execution, enter the Geth interaction mode. Then create an account, and then exit. This account is used to perform the Genesis operation. Then exit exit

> Personal.newaccount ("Password");
 " 0xea5c99831c2e4a0e094facdbac1befcf6c92e543 "
> Exit
3. Creation of the Genesis block

Compile the scripts needed to create the Genesis block, and note that the key under Alloc needs to be consistent with the above account number.

  {"Alloc": {"0xea5c99831c2e4a0e094facdbac1befcf6c92e543": {"
      Balance": "1000"
    }
  },
 
  " Nonce ":" 0x0000000000000042 ","
  difficulty ":" 0x020000 ",
  " Mixhash ":" 0x0000000000000000000000000000000000000000000000000000000000000000 ","
  Coinbase ":" 0x0000000000000000000000000000000000000000 ","
  timestamp ":" 0x00 ",
  " Parenthash ":" 0x0000000000000000000000000000000000000000000000000000000000000000 ","
  extradata ":" CNNMoney Jack Ma interview : Wars start when trade stops, 20160902 ",
  gaslimit": "0xFFFFFFFF"
  }

The meaning of each parameter is as follows:

Mixhash: A hash generated by a portion of a block that is used in conjunction with a nonce to excavate a mine. Note that his and nonce settings need to meet the yellow paper of the etheric Square, 4.3.4. Block Header validity, (44) The conditions described in the section.

Nonce:nonce is a 64-bit random number used to dig mines, noting that his and mixhash settings need to meet the yellow paper of the etheric Square, 4.3.4. Block Header validity, (44) The conditions described in the section.

Difficulty: The difficulty of setting the current block, if the difficulty is too large, the CPU is difficult to dig ore, here to set a small difficulty

Alloc: The number of etheric coins used to preset accounts and account numbers, because private chain mining is easier, so we do not need to set up a currency account, when needed to create their own.

Coinbase: Miner's account number, just fill in

Timestamp: Set the time stamp 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, random fill, you can fill in your personality information

Gaslimit: This value sets the total consumption limit of gas to limit the sum of the transaction information that the block can contain, because we are the private chain, so fill in the maximum.

Create data store address and initialize Genesis block

Geth  --datadir "/root/chain" Init Genesis.json 

Implementation of the results are as follows: 4. Start the private chain

Execute the following script

Geth--identity "Phoenix"--rpc--rpccorsdomain "*"--datadir "/root/chain" "--port" 30303 "--rpcapi"  DB, ETH,NET,WEB3 "--networkid 98888 Console

The parameters are described as follows:

Identity: A block chain marked, casually filled out, used to indicate the name of the current network

Init: Specify the location of the creation block file and create the initial block

DataDir: Set the location of the current block chain network data storage

Port: Network listening ports, default is 8080

RPC: Initiate RPC traffic, which enables deployment and debugging of smart contracts. It is usually activated by default in Geth.

RPCAPI: Set up clients that allow RPC to be connected, typically DB,ETH,NET,WEB3

Networkid: Set the network ID of the current block chain, used to differentiate between different networks, is a number

Console: Start command line mode, you can execute commands in Geth

In addition, you can use the following parameters:

Nodiscover: Use this command to ensure that your node will not be discovered by someone who is not manually adding you. Otherwise, your node may be accidentally added by a stranger's chunk chain if he and you have the same initial file and network ID.

Maxpeers: If you don't want other people to connect to your test chain, you can use Maxpeers 0. Conversely, if you know exactly how many people you want to connect to your node, you can also adjust the number to achieve it.

RPCAPI: This command can determine what APIs are allowed to enter through RPC. By default, Geth can activate the Web3 interface in RPC. Note that the API is provided in the RPC/IPC interface so that everyone who can access the interface (for example, Dapp ' s) has permission to visit the API. Notice which API you are activating. Geth will activate all APIs on the IPC interface and the Db,eth,net and WEB3 APIs on the RPC interface by default.

Rpccorsdomain: This can indicate what URLs can be connected to your node to perform RPC customization-side tasks. Be careful, enter a specific URL instead of wildcard

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.