从2018年3月份左右,开始接触以太坊Ethereum,搭建了单机或集群环境,也写了一些文档。最近整理电脑时发现,在这里分享出来。。。。
系统: linux ubuntu 16.04
sudo apt-get update
sudo apt-get install -y python-software-properties software-properties-common
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
sudo apt install nodejs-legacy
sudo apt install npm
sudo npm i -g npm
更新npm的包镜像源,方便快速下载(建议)
sudo npm config set registry https://registry.npm.taobao.org
sudo npm config list
全局安装n管理器(用于管理nodejs版本)
sudo npm install n -g
安装最新的nodejs(stable版本)
sudo n stable
sudo node -v
安装nvm
sudo curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
安装node
nvm install v8.11.1
node -v
npm -v
sudo npm install -g [email protected]
sudo npm uninstall -g truffle
truffle version
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install ethereum
sudo add-apt-repository ppa:ethereum/ethereum-qt
sudo add-apt-repository ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install cpp-ethereum
mkdir private-geth
cd private-geth
在private-geth创建log文件夹
mkdir log
vim genesis.json
{
"config": {
"chainId": 128,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"coinbase": "0x0000000000000000000000000000000000000000",
"difficulty": "0x5ffffa",
"extraData": "",
"gasLimit": "0xffffffff",
"nonce": "0x0000000000000042",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp": "0x00",
"alloc": {}
}
参数说明:
mixhash |
与nonce配合用于挖矿,由上一个区块的一部分生成的hash。注意他和nonce的设置需要满足以太坊的Yellow paper, 4.3.4. Block Header Validity, (44)章节所描述的条件。. |
nonce |
nonce就是一个64位随机数,用于挖矿,注意他和mixhash的设置需要满足以太坊的Yellow paper, 4.3.4. Block Header Validity, (44)章节所描述的条件。 |
difficulty |
设置当前区块的难度,如果难度过大,cpu挖矿就很难,这里设置较小难度 |
alloc |
用来预置账号以及账号的以太币数量,因为私有链挖矿比较容易,所以我们不需要预置有币的账号,需要的时候自己创建即可以。 |
coinbase |
矿工的账号,随便填 |
timestamp |
设置创世块的时间戳 |
parentHash |
上一个区块的hash值,因为是创世块,所以这个值是0 |
extraData |
附加信息,随便填,可以填你的个性信息 |
gasLimit |
该值设置对GAS的消耗总量限制,用来限制区块能包含的交易信息总和,因为我们是私有链,所以填最大。 |
"difficulty": "0x5ffffa" 一分钟五个ether
vim init.sh
geth --datadir ./data/00 init genesis.json
chmod 777 init.sh
vim start.sh
nohup geth --identity "fish dev" --datadir ./data/00 --networkid 128 --nodiscover --rpccorsdomain "*" --rpc --rpcapi "db,eth,net,web3,personal,network,txpool" --port 30309 --rpcport 8577 --gasprice 4000000000 --targetgaslimit 4294967295 > ./log/log.log 2>&1 &
chmod 777 start.sh
geth attach ipc:/home/private-geth/data/00/geth.ipc
"enode://404df1d977465e4c59153495ac6e3c6a6d0ddf3f07fbabdfe5f61a199832bdaee326e8df1056d93416da65beb7ceebc311c50ca6a3e63e88082fa320acf0e08a@192.168.30.245:30309"
"enode://7315c517f3632020cbc98b7e2e9f4a037843e1a4e65c028e160d451a5d3b72ea941b41e3b5d473beb50b33b3311515a327f1ff65848c3f4e685823c9274b5417@192.168.30.246:30309"
"enode://9d01da81ac030d01ebeaa96ce5d035c968e94a72708e2160f13ec584e6fef208ae0694b21c5f2796ccb75f4ed1b896bc91caea4cb6d96ec957acc8a2f24a08e3@192.168.30.247:30309"
admin.addPeer("enode://9d01da81ac030d01ebeaa96ce5d035c968e94a72708e2160f13ec584e6fef208ae0694b21c5f2796ccb75f4ed1b896bc91caea4cb6d96ec957acc8a2f24a08e3@192.168.30.247:30309")
admin.addPeer("enode://404df1d977465e4c59153495ac6e3c6a6d0ddf3f07fbabdfe5f61a199832bdaee326e8df1056d93416da65beb7ceebc311c50ca6a3e63e88082fa320acf0e08a@192.168.30.245:30309")
admin.addPeer("enode://7315c517f3632020cbc98b7e2e9f4a037843e1a4e65c028e160d451a5d3b72ea941b41e3b5d473beb50b33b3311515a327f1ff65848c3f4e685823c9274b5417@192.168.30.246:30309")
personal.unlockAccount("0x0c93b8749835ed69d12118cfdb773bb8ffb5dc2e", "123456")
eth.sendTransaction({from:"0x0c93b8749835ed69d12118cfdb773bb8ffb5dc2e",to:"0xa32bc62b9e3886e272b4ed48e4ed99bf312ba3cd", value: web3.toWei(2, "ether")})
"0xbb6bde8f07b8e59587917420446cd1cba07c44409d6007240fa307cf8e76fcf6"
eth.sendTransaction({from:"0x0c93b8749835ed69d12118cfdb773bb8ffb5dc2e",to:"0xf81a1627afc7c5f4794010ff317a43cde66f3b2b", value: web3.toWei(2, "ether")})
"0x7fdc416bc596292111c597f2a5e3acc587999fa974764bb8a43eb5cf98c335cf"
ps -ef | grep "geth --identity"
ps -ef | grep "ethminer"
../truffle-project/digital-copyrights-block-chain
先删除build文件夹,如果有。rm -rf build
truffle compile
truffle migrate --reset
../truffle-project/digital-copyrights-block-chain/egg
npm i
npm start
npm stop
npm run huidu
npm stop