Learning to build a chain block 1 Square Ethernet private chain in Ubuntu

In fact, never before understood the "block chain", "Bitcoin" just feel it is a very deep, very mysterious, a very complex thing.
However goose, I did not expect this semester course turned out to be a learning block chain.
Not in my plans, had to occupy my time and energy to finish the job, a little annoyed.
But since learned, it is good for it, there will always harvest.

The task is to build a first class private Ethernet Square chain in Ubuntu.
Next, enter the topic:


First, prepare the environment

1. Virtual Machine installed Ubuntu16.04:
Here Insert Picture Description
2. install Ubuntu:
Here Insert Picture Description
3. Tools to install the VM:
Here Insert Picture Description
4. Update Source:

sudo gedit /etc/apt/sources.list

Here Insert Picture Description
Then replace Tsinghua University, Ali cloud can specifically find online tutorials.

Update Source:

sudo apt-get update

Here Insert Picture Description
The need to modify the configuration file later with vim text editor, so also install vim:

sudo apt-get install vim-gtk
  • Need a reminder, vim There are several versions, I have failed before installation, and then saw a version of this tutorial is installed, and then succeeded.

Here Insert Picture Description

Second, the installation go locale

1. Download the installation package go language in a virtual machine:

wget https://studygolang.com/dl/golang/go1.10.3.linux-amd64.tar.gz

Here Insert Picture Description
2. In the directory of the downloaded archive, unzip it to / usr / local folder:

sudo tar -xzvf go1.10.3.linux-amd64.tar.gz -C /usr/local

Here Insert Picture Description
Here Insert Picture Description
3. Create a new file in the Home directory folder go:

mkdir go

Here Insert Picture Description
4. configuration environment variable
open environment variable configuration file:

sudo vim ~/.bashrc

Copy and paste the following code into the file Finally, save and exit:

export GOROOT=/usr/local/go
export GOBIN=$GOROOT/bin
export GOPATH=$HOME/go
export PATH=$PATH:$GOBIN

Here Insert Picture Description
The environment variables to take effect:

source ~/.bashrc

Here Insert Picture Description
5. Check whether the installation was successful:

go version

Here Insert Picture Description
At this point, go locale has been installed!

Third, install an Ethernet Square Ethereum client Geth

Geth is referred GoEthereum open source project, which is achieved using the Go language and client software Ethereum protocol, is currently the most users, the most widely used clients.

1. Enter the following commands in sequence:

sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install ethereum
  • I'm on a second command sudo add-apt-repository -y ppa : ethereum / ethereum when it came to being given! Then after a seven-hour-long detour revolving, hard work, and finally thought of a solution!
    Here Insert Picture Description
    If you get the error message shown below and I, like, you can try my method:

    Here Insert Picture Description

  • 1. First make sure that your virtual machines connect to the Internet, specifically the distribution network to find online tutorials

  • 2. Even if the network is still being given, you can try to update the Ubuntu package repository management:
    Here Insert Picture Description

  • 3. Add the geth source of PPA, PPA source in the search geth https://launchpad.net/ubuntu/+ppas, add it to the "other software", and shall use sudo gedit /etc/apt/sources.list written into the source file:
    Here Insert Picture Description
    Here Insert Picture Description
    again execute the above command after the update is complete, you can perform a normal second command.

  • However, geese, fourth command sudo apt-get install ethereum error in the figure below will appear in the course of implementation. Solution I found was: non-stop Repeat this command .
    Because although it failed every time, but it's download progress is cumulative, we can always repeat the download until the progress bar pull over. I spent the next did a good night, the next morning it was for the better:
    Here Insert Picture Description

2. Check whether the installation was successful:

geth version

Here Insert Picture Description
At this point, Geth installation is complete!

Fourth, build a chain of private Ethernet Square

1. Create a new folder e.g. Mychain, to store data private chain:

mkdir Mychain

Here Insert Picture Description
2. Create a file creation block genesis.json:

vim genesis.json

Writes the following:

  • I had written in accordance with the requirements specified by the teacher block file creation, but an error message appears:
    Failed to Genesis the Write Block: Unsupported fork
    Ordering: eip150Block not Enabled, Enabled But eip155Block 0 AT
    Internet search a bit, then changed to the following :
{
  "config": {
    "chainId": 666,
    "homesteadBlock": 0,
    "eip150Block": 0,
    "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "eip155Block": 0,
    "eip158Block": 0,
    "byzantiumBlock": 0,
    "constantinopleBlock": 0,
    "petersburgBlock": 0,
    "istanbulBlock": 0,
    "ethash": {}
  },
  "nonce": "0x0",
  "timestamp": "0x5ddf8f3e",
  "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "gasLimit": "0x47b760",
  "difficulty": "0x00002",
  "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase": "0x0000000000000000000000000000000000000000",
  "alloc": { },
  "number": "0x0",
  "gasUsed": "0x0",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}

3. Initialize the creation block, and specifies the data storage path:

geth --datadir Mychain init genesis.json

Here Insert Picture Description
4. After successful initialization, and generates geth keystore two folders in the data directory Mychain. Wherein geth / chaindata is stored in data blocks, keystore is stored in the account data:
Here Insert Picture Description
5. Start Private CCN:

geth --identity "TestNode" --rpc --rpcport "8545" --datadir mydata --port "30303" --networkid 6666 --nodiscover console
  • identity: Specifies the node ID
  • rpc: represents the open HTTP-RPC service;
  • rpcport: Specifies the HTTP-RPC service listening port number (default is 8545);
  • datadir: specifies the storage location of the data block chain;
  • port: Specifies the number of other nodes connected to the port used (default 30303);
  • networkid: Specifies chain private network number;
  • nodiscover: Close node discovery mechanism, added to prevent the same initial unfamiliar node configuration

There have been the following page it means to start a block chain node and the node into the console:
Here Insert Picture Description
At this point, the Ethernet private Chain Square in Ubuntu16.04 has built a good!


To summarize:
the environment constantly being given, I can not remember I tried too little time method, a snapshot of how many times restored.
Environmental take such a thing, others can really set the stage, the same way you will not be able to set the stage, there will always encounter some weird error ...... so although my installation steps have been various row wrong, but could you follow my steps to build still encounter problems.
Harvesting is that this should be the first time independently of the environment on the true meaning of my build. In this process, a larger harvest than to build successful, but encountered an error when troubleshooting thinking. After being given the problem because not all people have experienced, there are online solutions, but needs its own analysis, to determine the general direction of their own, then find the appropriate solution to flexibly apply their own problems.
Here Insert Picture Description

Published 66 original articles · won praise 26 · views 10000 +

Guess you like

Origin blog.csdn.net/u011785309/article/details/104778457