Block chain Learning (7): Geth Build private Network-actual combat __ ether Square

Source: Internet
Author: User

In this chapter we will combat how to use Geth, how to build the private network of the etheric square.

Previously said Geth is one of three tools to achieve the Ethernet square agreement, because Geth is officially respected and personal energy is limited, for the other two tools to build a private network, please refer to the online data.
The following geth, implemented on a MacBook, is similar to Windows. Step 1: Create a directory and Genesis.json a directory in the command-line mode, such as Tmpprivate

Create the file Genesis.json and fill in the following contents.

{"
  nonce": "0x0000000000000042", "
  timestamp": "0x0",
  "Parenthash": " 0x0000000000000000000000000000000000000000000000000000000000000000 ","
  extradata ":" 0x0 ",
  " GasLimit ":" 0x80000000 ","
  difficulty ":" 0x1 ",
  " Mixhash ":" 0x0000000000000000000000000000000000000000000000000000000000000000 ","
  Coinbase ":" 0x3333333333333333333333333333333333333333 ",
  " Alloc ": {     }
}
Proposed modification:
{
  "config": {"
        Chainid": "
        Homesteadblock": 0, "
        eip155block": 0,
        "Eip158block": 0
    },
    "Coinbase": "0x0000000000000000000000000000000000000000",
    "difficulty": "0x40000",
    " Extradata ":" ",
    " Gaslimit ":" 0xFFFFFFFF ",
    " nonce ":" 0x0000000000000042 ",
    " Mixhash ":" 0x0000000000000000000000000000000000000000000000000000000000000000 ","
    Parenthash ":" 0x0000000000000000000000000000000000000000000000000000000000000000 ",
    " timestamp ":" 0x00 ",
    " Alloc ": {}
}


Users can vim, can also use other editors such as sublime, personal recommended use Atom Atom official 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 files and code demos that will be executed primarily on atom.

After the creation is complete, in atom, there should be only one Genesis.json in this folder

Step 2: Execute the command, create the Genesis block switch back to the command line, execute the command, make the 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 add two folders Geth and KeyStore Geth are saved in the block chain of relevant data keystore The user information in the chain is saved

The directory structure seen from Atom now looks like this:

Step 3: Create your own private chain execute the simplest geth command to create your own private chain

Geth--datadir "./"--nodiscover console 2>>geth.log

Geth a lot of parameter items, interested can play geth–help to get details, we will also in the next chapter of the key parameter items are described. The command line at this point should be this:

Step 4: Create a user input command on your own private chain eth.accounts, we will find that the return value is []

This is because while the private chain of the etheric Square has been created, there are no accounts. Enter the command personal.newaccount ("XXX"), which will create a new user with a password of XXX. Of course, users can also change the XXX to 123, or 123456, or any password to 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: The log of the output block chain is the following code

Geth--datadir "./"--nodiscover console 2>>geth.log

The code console 2>> Geth.log represents the output of part of the console to the file Geth.log. Open another terminal, locate the Geth.log directory, execute the command tail-f Geth.log and continue to output the log of the etheric square

The entire process is shown in the following illustration:

Step 6: One of the most important steps is to start digging a mine. execute command on command line Miner.start (), start digging on our block chain

At this point the output of Geth.log should be like this

Until 100%. The private chain of the ether will be officially launched, and the etheric square is continuously generated. Note the point: 1. The ether coins dug into the mine will be insured by default in the first account, that is, eth.acccounts[0]. 2. Mining is the basis for implementing intelligent contracts. If you stop digging, not only will the etheric coins stop generating, but all smart contract calls will not work. 3. If you really want to stop digging, you can execute the order miner.stop () to stop digging 4. According to the above command, it should be possible to achieve the etheric square mining. If not, it could be a chain that existed before, and the previous data should be deleted. Delete the ~/.ethash folder and the inside file under Mac step 7: Finally, when the mining started the log is like this

Step 8: Check the number of etheric coins in the main account after the mine has been started

ACC0 = eth.accounts[0]
eth.getbalance (ACC0)

As long as the result is not 0, that means digging successfully.

The next chapter will explain some of the concepts in Geth, as well as some basic commands

Original link: http://www.ethchinese.com/?p=659





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.