Introduction to Blockchain (2): Building the Ethereum private chain (private network of Ethereum), as well as mining operations.

Source: Internet
Author: User

In doing some testing, it may be necessary to build a private ethereum network to facilitate control and to get to the real test work faster.

While the Ethereum nodes can link to each other need to meet 1) the same protocol version 2) the same networkid, so the most convenient way to build a private network is to use the--networkid option in the Geth command to set a different networkid from the main network ( The networkid of the main network is 1), which is also the official recommended method.

Start the private Ethereum network below:

mkdir Private-geth

CD Private-geth

Create a Genesis chunk file, which is a JSON-formatted file:

Vim Genesis.json

In the Genesis block JSON file, fill in the following, and save.

{

"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": {}

}

Initialize the Genesis node and set the data directory:

Geth--datadir./data/00 Init Genesis.json

Start the node, plus the console indicates that the command line is enabled after startup:

Geth--datadir./data/00--networkid Console

you can't do anything until you have an account ...., go ahead and enter the command at the command line to view the accounts in the current node:

> eth.accounts

[]

Output a "[]", indicating that Mao has a root, not to mention the account. Since there is no, then create a, continue to enter the command:

> Personal.newaccount ("123456")

Normally, the command line outputs:

INFO [05-15|23:59:29] New wallet appeared url=keystore:///home/zl/documents/p ... status=locked

"0x5b901c2495c077f515ae84fc53206f2eb3bf8296"

Before using the command to view the account, see:

> eth.accounts

["0x5b901c2495c077f515ae84fc53206f2eb3bf8296"]

There is output of "0x5b ... 96 "This string is the address of the account.

The account has, then do something more interesting, began to dig mine .... Continue output in command running script:

> Miner.start ()

INFO [05-16|00:07:25] Updated Mining Threads threads=0

INFO [05-16|00:07:25] starting mining operation

Null

INFO [05-16|00:07:25] Commit new mining work number=1 txs=0 uncles=0 elapsed=38.053ms

INFO [05-16|00:07:28] generating DAG in progress epoch=0 percentage=0 elapsed=1.715s

INFO [05-16|00:07:30] generating DAG in progress epoch=0 percentage=1 elapsed=3.448s

INFO [05-16|00:07:31] generating DAG in progress epoch=0 percentage=2 elapsed=5.059s

INFO [05-16|00:07:33] generating DAG in progress epoch=0 percentage=3 elapsed=6.799s

INFO [05-16|00:07:35] generating DAG in progress epoch=0 percentage=4 elapsed=8.373s

................................... This percenage=100, that is, after 100%, will continue to appear the following tips ....

INFO [05-16|00:24:54] successfully sealed new block number=36 HASH=95FDFD ... 1411ee

INFO [05-16|00:24:54]?? Block reached canonical chain Number=31 hash=438022...f6592e

................................. A lot of this tip, digging into a lot of mine .......... .........

INFO [05-16|00:24:54]?? Mined potential block number=36 HASH=95FDFD ... 1411ee

INFO [05-16|00:24:54] Commit new mining work number=37 txs=0 uncles=0 elapsed=122.202μs

Then stop mining:

>miner.stop ()

True

Then come and see how much of our account wallet is mine:

> eth.getbalance (eth.accounts[0])

355000000000000000000

Next, I'll talk about how to build a private network node group:

Setting up private network or local cluster

Reference Documentation:

Http://ethdocs.org/en/latest/network/test-networks.html?highlight=private%20chain

Https://github.com/ethereum/go-ethereum/wiki/Private-network

Https://github.com/ethereum/go-ethereum/wiki/Setting-up-private-network-or-local-cluster

http://chainskills.com/2017/03/10/part-3-setup-the-private-chain-miners/

Introduction to Blockchain (2): Building the Ethereum private chain (private network of Ethereum), as well as mining operations.

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.