Blockchain Development (I) Building a Private Chain Environment Based on Ethereum Through the methods described in this article and the scripts in the project, we can quickly build our own private chain for blockchain development and testing. This article is based on Ethereum technology and is divided into two parts, one is the construction method under Ubuntu, and the other is the construction method under Windwos. 1. Install Geth client in UbuntuThe reason for using Ubuntu is that Ethereum officially supports Ubuntu very well and it is the easiest to install in various Linux systems. Please refer to the Geth official installation guide Enter 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 —————————————————————————————— After the system is connected to the Internet, the Ethereum client is installed, including geth, bootnode, evm, disasm, rlpdump, and ethtest. If you enter the Geth command at this time, the Ethereum startup screen will appear 2. Install the Geth client under WindowsWindows must be a 64-bit system. Download the compiled win64 client from the official website, unzip it and run it. The download address is as follows: https://github.com/ethereum/go-ethereum/releases/ After downloading, there is only one Geth.exe file. To install the graphical client Mist, you can still download the compiled client from the official address. Download address: https://github.com/ethereum/mist/releases/ After downloading and decompressing, Ethereum-Wallet is the Ethereum graphical interface. 3. Prepare the Genesis Block FileConfiguring your own genesis block is to distinguish the public chain. In the same network, the genesis blocks must be the same, otherwise they cannot be connected. This method is common under Windows and Ubuntu. Create a new file piccgenesis.json, enter the following content and save it —————————————————————————————— { “nonce”:”0×0000000000000042″, “mixhash”:”0×000000000000000000000000000000000000000000000000000000000000000″, “difficulty”: “0×4000″, "alloc": {}, “coinbase”:”0×000000000000000000000000000000000000000″, “timestamp”: “0×00″, “parentHash”:”0×000000000000000000000000000000000000000000000000000000000000000″, "extraData": "PICC GenesisBlock", "gasLimit":"0xffffffff" } —————————————————————————————— Explain the function of each parameter:
4. Start the private chain nodeStarting Geth can start the Ethereum blockchain. In order to build a private chain, some parameters need to be added when starting Geth. The meanings of Geth parameters are as follows:
1. Start the blockchain node in Ubuntu In Ubuntu, first switch to the directory you want to run. There should be a configured piccgenesis.json file in the directory. Execute the following command —————————————————————————————— basepath=$(cd `dirname $0`; pwd) Get the current directory geth –datadir “$basepath/chain” init piccgenesis.json Create data storage address and initialize genesis block geth –identity”PICCetherum” –rpc –rpccorsdomain “*” –datadir “$basepath/chain” –port “30303″ –rpcapi “db,eth,net,web3″ –networkid 95518 console —————————————————————————————— After startup, the interface is as follows. The cursor stays on the last command line and the Ethereum command can be executed. —————————————————————————————— I0707 00:45:43.680087 ethdb/database.go:82]Alloted 128MB cache and 1024 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 1024 file handles to /home/lihe/Desktop/chain/chaindata I0707 00:45:43.908795 ethdb/database.go:82]Alloted 16MB cache and 16 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: [63 62], 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://134881790e54c803955715e3661c27f91caaf499be813e29c9f986e2eac6 2d47e02b13a8e51776c1caea554655614ed26ce0185d84e626da7ac48a83a60113ff@[::]: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, 05 Jul 2016 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 the prompts Listening on [::]:30303 and Welcome to the Geth JavaScript console!, indicating that it has been successfully started. Note: If you want to use Ubuntu as a permanent blockchain node, when using the nohup command, the Geth startup parameter console must be removed, otherwise Geth will stop automatically. 2. Start the blockchain node in Windows Enter the directory of Geth under Windows, place the configured piccgenesis.json file, and execute the following command: —————————————————————————————— geth –datadir “%cd%\chain” init piccgenesis.json Create data storage address and initialize genesis block geth–identity “PICCetherum” –rpc–rpccorsdomain “*” –datadir “%cd%\chain” –port”30303″ –rpcapi”db,eth,net,web3″ –networkid 95518 console —————————————————————————————— When you see the prompts Listening on [::]:30303 and Welcome to the Geth JavaScript console!, it means that it has been successfully started. 5. Create an account using a nodeAfter successfully starting the node, you will enter the Geth command line mode and enter the following command —————————————————————————————— personal.newAccount() —————————————————————————————— The system will prompt you to enter your account and password and confirm, and finally a newly generated account will be displayed. 6. Start the private chain graph node under WindowsFirst, follow the above steps to start Geth and create an account, then decompress Ethereum-Wallet and run Ethereum-Wallet.exe. The startup is successful. If the blockchain is normal, "PRIVATE-NET" will be displayed in the upper right corner. Click "LAUNCH APPLICATION" to enter the graphical interface. 7. Connecting to other nodesFirst, you need to know your node information. Enter the command in the Geth command line interface, paying attention to uppercase and lowercase letters. —————————————————————————————— admin.nodeInfo —————————————————————————————— The system will display enode:”enode://1e3c1727cd3bee9f25edeb5dbb3b880e03e41f8eec99566557f3ee0422734a8f cad17c161aa93d61bdbfb28ed152c143c7eb501db58bc63502a104a84b62d742@0.0.0.0:30303" in enode://1e3c1727cd3bee9f25edeb5dbb3b880e03e41f8eec99566557f3ee0422734a8fcad 17c161aa93d61bdbfb28ed152c143c7eb501db58bc63502a104a84b62d742@0.0.0.0:30303 This is the information of your own node. Please note that you should replace "0.0.0.0" with your own IP address. Send this information to other nodes and enter the following command in the command line of other nodes: —————————————————————————————— admin.addPeer('enode://1e3c1727cd3bee9f25edeb5dbb3b880e03e41f8eec99566557f3ee0422734a8 fcad17c161aa93d61bdbfb28ed152c143c7eb501db58bc63502a104a84b62d742@192.168.1.101:30303') —————————————————————————————— If the addition is successful, entering admin.peers will display the newly added node. 8. Using nodes for miningIn the Geth command line interface, enter miner.start() to start mining. After mining, the screen will refresh continuously. Enter miner.stop() to stop. Don’t worry about the incomplete command caused by refreshing the screen, the command will be executed normally. At this point, a private chain network has been established, and this network can be continuously expanded like other blockchains. In the next article, I will introduce how to deploy and run smart contracts on a private chain. Reference articles: 1. http://tech.lab.carl.pro/kb/ethereum/testnet_setup 2. http://www.ethdocs.org/en/latest/network/test-networks.html#setting-up-a-local-private-testnet 3. https://github.com/ethereum/go-ethereum/wiki/Connecting-to-the-network 4. https://github.com/ethereum/go-ethereum/wiki/JavaScript-Console 5. https://github.com/ethereum/go-ethereum/wiki/Mining 6. https://github.com/ethereum/go-ethereum/wiki/Managing-your-accounts 7. https://github.com/janx/ethereum-bootstrap |
<<: Blockchain-powered social network challenges Facebook and Twitter
>>: Li Lihui: Blockchain solves the trust problem through blood transfusion
1. Broom eyebrow In physiognomy, if a person'...
On August 31, 2016, Hangzhou QuChain Technology r...
Palmistry is a profound subject, so fortune teller...
As of 10:00 today, the total locked value of DeFi...
Cindy, a well-known blogger and joke teller in th...
Double chin man's feelings If a man has a dou...
The neatness and whiteness of teeth not only affe...
Money is what everyone pursues, and everyone hope...
Beauties with dimples on their faces always give ...
At the end of 2008, the world's monetary syst...
As the saying goes: People with great ambitions, ...
In life, some people are willing to treat everyon...
Although Bitcoin Unlimited (BU) has been welcomed...
Whether France can provide policy support to mine...
Feelings are actually resources, but their import...