以下是在linux环境下安装以太坊c++客户端,搭建私有链过程的记录
基于Ubuntu16.04.5系统
一、下载cpp-ethereum源码
1、安装git
输入 sudo apt-get install git
2、下载cpp-ethereum源码
git clone --recursive https://github.com/ethereum/cpp-ethereum.git
二、安装CMake
输入 sudo apt-get install cmake
三、安装依赖项
进入cpp-ethereum文件夹
输入 scripts/install_deps.sh
四、编译
依次输入命令
mkdir build
cd build
cmake ..
make
五、安装以太坊控制台etheconsole
1、下载安装npm
sudo apt-get install npm
2、安装用于安装nodejs的模块n
sudo npm install -g n
3、安装最新版nodejs
sudo n latest
输入 node -v 可查看node版本
4、安装ethconsole
由于直接使用sudo npm install -g ethereum-console 出现错误
于是按照npmjs官方文档中的步骤进行操作:
为全局安装创建一个目录:
mkdir ~/.npm-global
配置npm以使用新的目录路径:
npm config set prefix '~/.npm-global'
打开或创建一个?/ .profile文件并添加以下行:
export PATH=~/.npm-global/bin:$PATH
回到命令行,更新系统变量:
source ~/.profile
安装ethconsole
npm install -g ethereum-console
输入ethconsole出现
ethconsole的命令可以使用则说明安装成功了
六、创建创世区块文件
在cpp-ethereum/build/aleth文件夹创建创世区块文件genesis.json
{
"sealEngine": "Ethash",
"params": {
"accountStartNonce": "0x00",
"frontierCompatibilityModeLimit": "0xffffffff",
"maximumExtraDataSize": "0x0400",
"tieBreakingGas": false,
"minGasLimit": "125000",
"gasLimitBoundDivisor": "0x0400",
"minimumDifficulty": "0x020000",
"difficultyBoundDivisor": "0x0800",
"durationLimit": "0x08",
"blockReward": "0x14D1120D7B160000",
"registrar": "5e70c0bbcd5636e0f9f9316e9f8633feb64d4050",
"networkID" : "0x0"
},
"genesis": {
"nonce": "0x000000000000002a",
"difficulty": "0x20000",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"author": "0x0000000000000000000000000000000000000000",
"timestamp": "0x00",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x",
"gasLimit": "0x2fefd8"
},
"accounts": {
"0000000000000000000000000000000000000001": { "wei": "1", "precompiled": { "name": "ecrecover", "linear": { "base": 3000, "word": 0 } } },
"0000000000000000000000000000000000000002": { "wei": "1", "precompiled": { "name": "sha256", "linear": { "base": 60, "word": 12 } } },
"0000000000000000000000000000000000000003": { "wei": "1", "precompiled": { "name": "ripemd160", "linear": { "base": 600, "word": 120 } } },
"0000000000000000000000000000000000000004": { "wei": "1", "precompiled": { "name": "identity", "linear": { "base": 15, "word": 3 } } },
"dbdbdb2cbd23b783741e8d7fcf51e459b497e4a6": { "wei": "1606938044258990275541962092341162602522202993782792835301376" },
"e6716f9544a56c530d868e4bfbacb172315bdead": { "wei": "1606938044258990275541962092341162602522202993782792835301376" },
"b9c015918bdaba24b4ff057a92a3873d6eb201be": { "wei": "1606938044258990275541962092341162602522202993782792835301376" },
"1a26338f0d905e295fccb71fa9ea849ffa12aaf4": { "wei": "1606938044258990275541962092341162602522202993782792835301376" },
"2ef47100e0787b915105fd5e3f4ff6752079d5cb": { "wei": "1606938044258990275541962092341162602522202993782792835301376" },
"cd2a3d9f938e13cd947ec05abc7fe734df8dd826": { "wei": "1606938044258990275541962092341162602522202993782792835301376" },
"6c386a4b26f73c802f34673f7248bb118f97424a": { "wei": "1606938044258990275541962092341162602522202993782792835301376" },
"e4157b34ea9615cfbde6b4fda419828124b70c78": { "wei": "1606938044258990275541962092341162602522202993782792835301376" }
}
}
七、创建私有链
1、在cpp-ethereum/build/aleth文件夹下
创建一个文件夹ipctest
2、打开终端,进入cpp-ethereum/build/aleth
输入 ./aleth --config genesis.json -m on --network-id 1108 --ipc --listen 30307 --port 30307 -d ipctest --private "myPrivateChain"
私有链启动,开始挖矿
3、ipctest文件夹中出现geth.ipc文件
八、使用控制台连接私有链
打开一个新的终端
输入 ethconsole cpp-ethereum/build/aleth/ipctest/geth.ipc
出现下图情况说明连接成功