In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of "how to build the private chain of Ethernet Square". The editor shows you the operation process through the actual case, and the operation method is simple, fast and practical. I hope this article "how to build the private chain of Ethernet Square" can help you solve the problem.
Install geth
Download offline installation address: https://geth.ethereum.org/downloads/, and select the corresponding operation version
Initialize the creation block to create the workspace directory
Block description file
The syntax of the file structure is configured in json data format, and the contents of the genesis.json file are as follows
{"config": {"chainId": 7777, "homesteadBlock": 0, "eip155Block": 0, "eip158Block": 0}, "alloc": {}, "coinbase": "0x0000000000000000000000000000000000000000", "difficulty": "0x20000", "extraData": "", gasLimit ":" 0x2fefd8 "," nonce ":" 0x0000000000000042 "," mixhash ":" 0x0000000000000000000000000000000000000000000000000000000000000000 " "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "timestamp": "0x00"} config.chainId / / ID of the block chain The-networkid parameter in the geth command needs to be the same as the chainId value config.homesteadBlock / / Homestead hard bifurcation block height, do not need to pay attention to the config.eip155Block / / EIP 155hard bifurcation height, do not need to pay attention to the config.eip158Block / / EIP 158hard bifurcation height, do not need to pay attention to the coinbase / / miner account, after the first block is dug out, the difficulty / / difficulty value of the reward will be sent to the miner account The larger the extraData / / additional information, the more difficult it is to fill in the total consumption limit of gasLimit / / gas, which is used to limit the sum of transaction information that the block can contain. Because we are a private chain, we fill in the maximum nonce / / a 64-bit random number mixhash / / combined with nonce for mining. The hashparentHash / / the hash value of the previous block generated by part of the previous block alloc / / preset account and the number of Ethernet coins of the account. Private chain mining is easier without configuring run commands:
. / geth-- datadir. / privateChain/data0 init genesis.json
After naming, the following structural directories and files are produced in privateChain
Start the private chain node
/ geth-- identity "TestNode1"-- datadir ". / privateChain/data0"-- rpc-- rpcapi "db,eth,net,web3"-- rpcaddr "127.0.0.1"-- rpcport "8486"-- port "30304"-- networkid "7777" console
The main body of the order is geth console, which means to start the node and enter the interactive console, the-- datadir option specifies that data0 is used as the data directory, and the-- networkid option is followed by a number, here 7777, indicating that the network id of the private chain is specified as 7777. The network id is used when connecting to other nodes. The network id of the Ethernet public network is 1. In order not to conflict with the public chain network, you should specify your own network id when running the private chain node. After running the above command, you start the blockchain node and enter the Javascript Console: only the console command and the attach command enter the js interaction window.
Use the command geth-h to view geth-related help documentation. Here I would like to talk about a few common attributes. -- Identity: node identity, give a name-- datadir: specify the location where the node exists, "data0"-- rpc: enable http-rpc server-- rpcapi: based on the api interface provided by http-rpc. Eth,net,web3,db...-- rpcaddr: http-rpc server interface address: default "127.0.0.1"-- rpcport: http-rpc port (do not repeat when multi-node)-- port: node port number (do not repeat when multi-node)-- networkid: network identifier randomly specify an id (ensure that multiple nodes are unified and consistent)
This is an interactive Javascript execution environment where you can execute Javascript code, where > is the command prompt. In this environment, there are also built-in Javascript objects for manipulating Ethernet Square, which can be used directly. These objects mainly include:
Eth: contains some methods related to manipulating block chains
Eth.accounts: accounts in the enumeration system; eth.getBalance (): check the account balance and return the value in Wei (Wei is the smallest unit of currency denomination in Ethernet Square, similar to Cong in Bitcoin, 1 ether = 10 ^ 18 Wei); eth.blockNumber: list the total number of chunks; eth.getTransaction (): get transactions; eth.getBlock (): get chunks
Net: contains the following methods to view the status of a P2P network
Admin: contains some methods related to managing nodes
Admin.addPeer (): connect to another node admin.nodeInfo.enode to view the enode of this node
Miner: including some methods to start-stop mining
Miner.start (): start digging
Miner.stop (): stop digging
Personal: mainly contains some methods for managing accounts
Personal.newAccount (): create an account
Personal.unlockAccount (): a protection mechanism for unlocking the account in Tai Fong, which automatically locks the account from time to time.
Txpool: contains some ways to view the transaction memory pool
Txpool.status: status in the deal pool
Web3: contains the above objects, as well as some unit conversion methods
Web3.fromWei (): Wei is converted into Ethernet currency
Web3.toWei (): convert Ethernet currency into Wei
Add other P2P node information to this node to view node information
Add a node admin.addPeer ("enode://2f86dbb18242371fa0a8e7098cb13a012ad9d8ee80f0bbba94a798b16d3c6c3c247d3e333b8da27a591b38365f927a25359376d4bf38575bb0371a1365294f91@ [:]: 30301?discport=0") to the same creation chain
Note: when connecting to other nodes on the same network, the value of the first field above, enode, is used.
According to the above, a private chain decentralization cluster can be established and formed. Any node mining, after digging to the block, will be synchronized to the other two nodes. If the genesis.json file is different or the networkid is different, it cannot be added successfully. Different genesis.json will generate different creation blocks. Different networkid means two different networks, so you can't add them successfully.
This is the end of the content about "how to build the private chain of Ethernet Square". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.