(I'm a little white, I can't find the information. I figured out this construction process myself. If there are any mistakes, please ask Haihan. Thank you. At the same time, you are welcome to point out my mistakes.)
Condition: linux system (64 bit ubuntu)
cpp-ethereum source code
ethconsole console
1. Download the source code from github and enter it in the linux terminal
git clone --recursive https://github.com/ethereum/cpp-ethereum.git
(If git is not installed, you need to enter sudo apt-get install git to install git)
After the download is complete, enter
cdcpp-ethereum
Enter the good cpp-ethereum folder.
2. Install cmake, and related components.
enter
sudo apt-get install cmake
sudo apt-get install libboost-all-dev libleveldb-devlibcurl4-openssl-dev libmicrohttpd-dev libminiupnpc-dev libgmp-dev
3. Start building
Enter in order
mkdir build creates a build folder
cd build into the created folder
cmake .. generates a makefile (makefile)
make builds that makefile
make -j<number> number is the number of cores used for execution
4. Install ethconsole
First download npm
enter
sudo apt-get install npm
npm install -g ethereum-console
If nothing else, there should be an error here that cannot be installed, as follows
WARN engine servify@xxx:wanted:{“node”:”>=6”}(current:{“node”:”4.2.6”})
This is because the default node version of npm is too low, and Node needs to be upgraded
Execute the following commands:
sudo npm install -g n
Think about the node version you want to install, here is an example of installing version 7.10.0
sudo n stable 7.10.0
enter
node -v
Check if the installation is successful. enter
ethconsole
as long as it doesn't appear
ethconsole: command not found
That is, the installation is successful
5. Start building a private chain.
First switch the folder to eth to operate
cd eth
(Writing a small episode, the eth in the eth directory is not complete, some commands are not, but considering that we do not need to operate through the console, we can not download the complete eth.)
Create a new json file in the eth folder with the following format
{
"config": {
"chainId": 1000,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"coinbase" : "0x0000000000000000000000000000000000000000",
"difficulty" : "0x400",
"extraData" : "Oh My God!",
"gasLimit" : "0x2fefd8",
"nonce" : "0x0000000000000042",
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp" : "0x00",
"alloc": {}
}
This file is the configuration file of the genesis block you want. The meaning of each parameter is as follows:
config.chainId // The ID of the blockchain, the --networkid parameter in the geth command needs to be consistent with the value of chainId config.homesteadBlock // Homestead hard fork block height, do not need to pay attention to config.eip155Block // EIP 155 hard Fork height, do not need to pay attention to config.eip158Block // EIP 158 hard fork height, do not need to pay attention to coinbase // Miner account, after the first block is mined, the miner account will be rewarded with ether difficulty // difficulty Value, the bigger the more difficult extraData // Additional information just fill in gasLimit //The total gas consumption limit is used to limit the sum of transaction information that the block can contain, because we are a private chain, so fill in the maximum nonce // A 64 -bit random Number mixhash // used for mining in conjunction with nonce , the hash generated by part of the previous block parentHash //
The hash value of the previous block
alloc // The default account and the amount of ether in the account, private chain mining is easier and can not be configured
Name this file zero.json, which will be used later. Create a new folder under the eth folder and name it data0, which will be used to store block data later.
Here are a few commonly used eth operations,
--help or -h: show help list
--no-discovery : eth connects to full nodes by default. By entering --no-discovery, our private chain does not link to full nodes.
--genesis : The usage of the genesis node to initialize the private chain is --genesis <filename>
--network-id: Your id name, which is a number, is the same as the chainid in your json file, which will be used to connect to other nodes in the future.
--datadir <filename>: The name of the folder where you want to store block data.
--private <name>: The name of the block you created.
--m <on/off/number>: on allows mining for you, off is not allowed, and number specifies the number of blocks for you.
………..
Enter the following:
./eth--genesis zero.json --d data0 –no-discovery -m on –network-id 1000
(If an error is reported, you can try to replace the json file I gave above with the example json file provided by the system)
Open the data0 folder and a file with an .ipc suffix will be generated. Remember the absolute path to this file.
Open a new terminal, enter ethconsole + path, for example:
ethconsole cpp-ethereum/build/eth/data0/geth.ipc
You can connect to your private chain. And do it through ethconsole. Note that the connection is automatically terminated when you turn off mining.
About the operation method of ethconsole and how to operate directly through eth, the blogger will update it later. Readers can either visit
as well as
http://web3js.readthedocs.io/en/1.0/