The eth function of the c++ version is very weak, and there is no powerful command of geth, such as the block information cannot be viewed, the account balance cannot be viewed eth.getBalance()
If you want to debug the C++ version of the Ethereum program, you can use the getch command to view the block account data for testing.
1. Prepare to test the genesis block json file genesis.json of the private chain, the content is as follows
{
"nonce": "0x0000000000000042",
"difficulty": "0x200",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"author": "0x0000000000000000000000000000000000000000",
"timestamp": "0x00",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa",
"gasLimit": "0x1388"
}
2. Use C++ client eth to create a private chain
Enter the eth debug directory where the program is compiled
Enter the command line and execute the command eth -d data --genesis genesis.json
The directory of the block is data
After seeing Nodeid start, press several ctrl+c to terminate, you can see that the block folder was created successfully
3. Start the private chain eth -d data --private test -C
4. Open another command window and execute geth
geth attach ipc:\\.\pipe\geth.ipc
personal.newAccount('123456')
As above, create several accounts
Execute personal, you can see the account information
Check the amount of the 0th account, you can see that it is currently 0
eth.getBalance (eth.accounts [0])
Set the default account for mining
eth.defaultAccount=eth.accounts[0]
Start mining
miner.start(1)
You can see the c++ eth command line server, and the mining information appears
Stop mining after a few minutes
miner.stop()
View account information
eth.getBalance (eth.accounts [0])
found to be 0
This is because the default Ethereum mining is too difficult for a single CPU and takes a long time. At this time, a configuration file config.json needs to be enabled and placed in the debug directory of C++ ETH.
"sealEngine": "Ethash",
"params": {
"accountStartNonce": "0x00",
"homesteadForkBlock": "0x118c30",
"daoHardforkBlock": "0x1d4c00",
"EIP150ForkBlock": "0x259518",
"EIP158ForkBlock": "0x28d138",
"byzantiumForkBlock": "0x42ae50",
"constantinopleForkBlock": "0x500000",
"networkID" : "0x01",
"chainID": "0x01",
"maximumExtraDataSize": "0x20",
"tieBreakingGas": false,
"minGasLimit": "0x1388",
"maxGasLimit": "7fffffffffffffff",
"gasLimitBoundDivisor": "0x0400",
"minimumDifficulty": "0x0200",
"difficultyBoundDivisor": "0x080",
"durationLimit": "0x0d",
"blockReward": "0x4563918244F40000"
},
"genesis": {
"nonce": "0x0000000000000042",
"difficulty": "0x200",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"author": "0x0000000000000000000000000000000000000000",
"timestamp": "0x00",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa",
"gasLimit": "0x1388"
},
"accounts": {
"0000000000000000000000000000000000000001": { "precompiled": { "name": "ecrecover", "linear": { "base": 3000, "word": 0 } } },
"0000000000000000000000000000000000000002": { "precompiled": { "name": "sha256", "linear": { "base": 60, "word": 12 } } },
"0000000000000000000000000000000000000003": { "precompiled": { "name": "ripemd160", "linear": { "base": 600, "word": 120 } } },
"0000000000000000000000000000000000000004": { "precompiled": { "name": "identity", "linear": { "base": 15, "word": 3 } } },
"0000000000000000000000000000000000000005": { "precompiled": { "name": "modexp", "startingBlock" : "0x2dc6c0" } },
"0000000000000000000000000000000000000006": { "precompiled": { "name": "alt_bn128_G1_add", "startingBlock" : "0x2dc6c0", "linear": { "base": 500, "word": 0 } } },
"0000000000000000000000000000000000000007": { "precompiled": { "name": "alt_bn128_G1_mul", "startingBlock" : "0x2dc6c0", "linear": { "base": 40000, "word": 0 } } },
"0000000000000000000000000000000000000008": { "precompiled": { "name": "alt_bn128_pairing_product", "startingBlock" : "0x2dc6c0" } }
}
}
重新启动C++ ETH服务端,使用配置文件
eth -d data --private test --config config.json -C
重启getch连接c++ eth服务端
设置挖矿默认账户
miner.setEtherbase(eth.accounts[0])
启动挖矿 miner.start(1)
过几+秒停止挖矿 miner.stop()
查看账户
可以看到该账户挖矿成功了