以太坊启动测试链命令参考
./geth --datadir /Volumes/exdisk/testnet --rpc --rpcaddr 0.0.0.0 --rpcport 8544 --port '30302' --rpcapi 'eth,web3,personal,net,miner,admin,debug,txpool' --testnet --fast --maxpeers 50 --cache 1024 --ipcpath /goproject/src/github.com/ethereum/go-ethereum/geth.ipc
以太坊搭建私有链
编辑创世区块配置文件
mkidr gethdata
vim getdata/genesis.json
{
"config": {
"chainID": 1024,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0,
"eip150Block": 0,
"byzantiumBlock": 0,
"daoForkSupport": true
},
"alloc": {},
"coinbase": "0x0000000000000000000000000000000000000000",
"difficulty": "0x100",
"extraData": "",
"gasLimit": "0x2fefd8",
"nonce": "0xdeadbeefdeadbeef",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp": "0x00"
}
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的消耗总量限制,用来限制区块能包含的交易信息总和,因为我们是私有链,所以填最大。
根据配置文件创建创世区块
geth --datadir "gethdata/priv" init gethdata/genesis.json
启动geth
geth --datadir "gethdata/priv" --rpc --networkid 314590 --rpcaddr 0.0.0.0 --rpcport 8542 --port '30301' --rpcapi 'eth,web3,personal,net,miner,admin,debug' --ws --wsport 8585 --wsapi 'eth,web3,personal,net,miner,admin,debug'
登录控制台查看节点信息
admin.nodeInfo.enode
"enode://a1e18dd40fbce856d8.......2eabd24e29a@[::]:30303?discport=0"
启动另一个节点
geth --datadir "gethdata/priv" --rpc --networkid 314590 --rpcaddr 0.0.0.0 --rpcport 8543 --port '30302' --rpcapi 'eth,web3,personal,net,miner,admin,debug' --ws --wsport 8585 --wsapi 'eth,web3,personal,net,miner,admin,debug'
尝试加入之前的节点
> admin.addPeer("enode://a1e18dd40fbce856d84b8c6872d4158ab152812a081d1608643fd8a9c7d650ad161b5ef0b0a2a94357d2d6f3a044b380445f9033550233f8ded232eabd24e29a@ip_address:30301")
> net.peerCount
> admin.peers