Building a private chain environment based on digital currency

Source: Internet
Author: User
Tags hash json

Blockchain Enthusiast (qq:53016353)

Through the methods described in this article and the script, we can quickly set up their own private chain for blockchain development testing, this article is based on the Ethereum technology to build, divided into two parts, one is the Ubuntu under the construction method, the other is the Windwos under the building method, about the basic knowledge of ethereum related, can look at my original published some articles, the address is as follows: Http://blog.csdn.net/sportshark

I. Install Geth client under Ubuntu


The reason for using Ubuntu is that the official Ethereum support for Ubuntu is very good, and it is easiest to install on each Linux system.


Geth Official Installation Guide:


Go to the Ubuntu command line and execute the following command


sudo apt-get update
sudo apt-get Installsoftware-properties-common
sudo add-apt-repository-yppa:ethereum/ethereum
sudo add-apt-repository-yppa:ethereum/ethereum-dev
sudo apt-get update
sudo apt-get install Ethereum


The installation of the Ethereum client, including Geth,bootnode, EVM, Disasm, Rlpdump,ethtest, was completed after the system network was implemented.


At this point, if you enter the Geth command, you will be prompted to start the Ethereum start screen




Second, install the Windows Geth Client
Windows must be 64-bit system, download the compiled Win64 client from the official website, unzip to run,
After downloading, there is only one Geth.exe file.


Install the image client mist, still download the compiled client from the official address,
After the download is uncompressed, the Ethereum-wallet is the Ethereum graphical interface.




Iii. preparing for the creation of a block document


Configure their own creation block is to distinguish the public chain, the same network, the creation of the block must be the same, or can not be connected, this method in Windows and Ubuntu under General.


New file Piccgenesis.json, enter the following and save


{


"Nonce": "0x0000000000000042",


"Mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",


"Difficulty": "0x4000",


"Alloc": {},


"Coinbase": "0x0000000000000000000000000000000000000000",


"Timestamp": "0x00",


"Parenthash": "0x0000000000000000000000000000000000000000000000000000000000000000",


"Extradata": "PICC genesisblock",


"Gaslimit": "0xFFFFFFFF"


}



Explain the effects of each parameter:




Mixhash


A hash that is generated by a portion of the previous block in conjunction with a nonce for mining. Note that he and the nonce settings need to meet Ethereum's yellow paper, 4.3.4. Block Header Validity, (44) The conditions described in the chapter:


Nonce


A nonce is a 64-bit random number used to mine mining, noting that his and mixhash settings need to meet the Ethereum yellow paper, 4.3.4. Block Header Validity, (44) The conditions described in the chapter.


Difficulty


The difficulty of setting the current block, if the difficulty is too large, the CPU mining is difficult, here set a small difficulty


Alloc


The number of etheric coins used to pre-provision accounts and account numbers, because the private chain mining is easier, so we do not need to pre-set the account of the currency, when needed to create their own.


Coinbase


The miner's account, just fill it out.


Timestamp


Set the time stamp of the Genesis block


Parenthash


The hash value of the previous chunk, because it is a Genesis block, so this value is 0


Extradata


Additional information, please fill in, can fill in your personal information


Gaslimit


This value sets the total consumption limit for gas, which is used to limit the sum of the transaction information that the block can contain, since we are the private chain, so fill the maximum.




Iv. starting a private chain node


Starting Geth can start the Ethereum blockchain, in order to build a private chain, you need to add some parameters at Geth startup, the Geth parameter meaning is as follows:


Identity


The name of the blockchain, which is used to mark the current network


Init


Specify the location of the Genesis block file and create the initial block


DataDir


Sets the location of the current blockchain network data storage


Port


Network Listening port


Rpc


Initiate RPC communication to deploy and debug smart contracts


Rpcapi


Sets the client that allows RPC to be connected, typically DB,ETH,NET,WEB3


Networkid


Sets the network ID of the current blockchain to distinguish between different networks, which is a number


Console


Start command line mode, you can execute commands in Geth




1. Start the blockchain node in Ubuntu


Under Ubuntu, first switch to the directory you intend to run, the directory should have a configured Piccgenesis.json file, execute the following command


basepath=$ (CD ' DirName $ '; pwd)


Get the current directory


Geth--datadir "$basepath/chain" Init Piccgenesis.json


Create a data store address and initialize the Genesis block


Geth--identity "Piccetherum"--rpc--rpccorsdomain "*"--datadir "$basepath/chain"--port "30303"--rpcapi "db,eth,net, WEB3 "--networkid 95518 Console


After starting the interface as follows, the cursor rests on the last command line and can execute the ethereum command.


I0707 00:45:43.680087 ethdb/database.go:82]alloted 128MB Cache and 1024x768 file handles to/home/lihe/desktop/chain/chaindata


I0707 00:45:43.726008ethdb/database.go:169] closed db:/home/lihe/Desktop/chain/chaindata


I0707 00:45:43.728913 ethdb/database.go:82]alloted 128MB Cache and 1024x768 file handles to/home/lihe/desktop/chain/chaindata


I0707 00:45:43.908795 ethdb/database.go:82]alloted 16MB cache and file handles to/home/lihe/desktop/chain/dapp


I0707 00:45:43.969506 core/genesis.go:92]genesis block already in chain. Writing Canonical number


I0707 00:45:43.980337 Eth/backend.go:274]successfully wrote custom Genesis block : 6e92f8b23bcdfdf34dc813cfaf1d84b71beac80530506b5d63a2df10fe23a660


I0707 00:45:43.980618 eth/backend.go:184]protocol Versions: [[+], Network id:95518


I0707 00:45:43.981567core/blockchain.go:204] Last header: #81 [6193c4b0 ...] td=10836704


I0707 00:45:43.981645core/blockchain.go:205] Last block: #81 [6193c4b0 ...] td=10836704


I0707 00:45:43.981677core/blockchain.go:206] Fast block: #81 [6193c4b0 ...] td=10836704


I0707 00:45:43.985253 p2p/server.go:313]starting Server


I0707 00:45:45.834488p2p/discover/udp.go:217] listening,enode:// 134881790e54c803955715e3661c27f91caaf499be813e29c9f986e2eac62d47e02b13a8e51776c1caea554655614ed26ce0185d84e626da7ac48a83a 60113ff@[::]:30303


I0707 00:45:45.835853 node/node.go:366]http Endpoint opened:http://localhost:8545


I0707 00:45:45.848008 p2p/server.go:556]listening on [::]:30303


I0707 00:45:45.849731 node/node.go:296] Ipcendpoint opened:/home/lihe/Desktop/CHAIN/GETH.IPC


Welcome to the Geth JavaScript console!





Instance:geth/v1.5.0-unstable/linux/go1.5.1/piccetherum


Coinbase:0x93509a2f4b2b974b07ef0b52e07c3992601f5de1


At block:81 (Tue, 21:02:25CST)


DataDir:/home/lihe/Desktop/chain


modules:admin:1.0 debug:1.0 eth:1.0 miner:1.0net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0


>


You can see listening on [::]:30303 and welcome to the Geth JavaScript console! tips that indicate that the success has been started


Note: If you want to use Ubuntu as a permanent blockchain node, the Geth startup parameter console must be removed when using the Nohup command, or Geth will stop automatically.





2. Start the Blockchain node in Windows


Go to the directory under Windows Geth, place the configured Piccgenesis.json file, and execute the following command:


Geth--datadir "%cd%\chain" Init Piccgenesis.json


Create a data store address and initialize the Genesis block


Geth--identity "Piccetherum"--rpc--rpccorsdomain "*"--datadir "%cd%\chain"--port "30303"--rpcapi "DB,ETH,NET,WEB3"- -networkid 95518 Console


When you see listening on [::]:30303 and welcome to the Geth JavaScript console!, instructions have been started successfully






V. Create an account using a node


After the boot node succeeds, it will enter the command line mode of Geth and enter the following command


Personal.newaccount ()


You will be prompted to enter your account password and confirm that a new generated account will be displayed at the end.





Vi. start the private chain graphics node under Windows


First follow the above steps to start Geth and create an account, and then extract Ethereum-wallet, run Ethereum-wallet.exe, that is, start successfully, if the blockchain is normal, the upper right corner of the display "Private-net", click "LAUNCH Application "into the graphical interface.





Vii. Connecting other nodes


First you need to know your node information, enter the command in the Geth command line interface, note the case


Admin.nodeinfo


The system will display


Enode: "enode:// 1e3c1727cd3bee9f25edeb5dbb3b880e03e41f8eec99566557f3ee0422734a8fcad17c161aa93d61bdbfb28ed152c143c7eb501db58bc63502a104a84 b62d742@0.0.0.0:30303 "


which


enode:// 1e3c1727cd3bee9f25edeb5dbb3b880e03e41f8eec99566557f3ee0422734a8fcad17c161aa93d61bdbfb28ed152c143c7eb501db58bc63502a104a84 b62d742@0.0.0.0:30303


Is the information of their own nodes, pay attention to the "0.0.0.0" for your own IP. Send this information to the other nodes and enter them on the command line of the other nodes:


Admin.addpeer (' enode:// 1e3c1727cd3bee9f25edeb5dbb3b880e03e41f8eec99566557f3ee0422734a8fcad17c161aa93d61bdbfb28ed152c143c7eb501db58bc63502a104a84 b62d742@192.168.1.101:30303 ')


If added successfully, the input admin.peers will display the newly added node.





Viii. using nodes for mining


In the Geth command line interface, the input Miner.start () is started mining, mining, will not stop brush screen, input miner.stop () stop, no tube brush screen caused by the command is not complete, the command will be executed normally.


In this step, a network of private chains has been formed, which can be extended as the other blockchain, and in the next article I will describe how to write, debug, and deploy smart contracts on a private chain.

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.