私有链搭建
1. 运行一会 MIST 钱包, 让他自动下载好 geth
2. 找到 geth 所在目录
C:\Users\Administrator\AppData\Roaming\Mist\binaries\Geth\unpacked(这是我本人的路径, 大家可以自己根据自己的路径去查找 geth 的目录路径) 将次目录添加到环境变量中
3. 创建创世纪区块, 并放在 geth 所在的目录下 (piccgenesis.JSON)
- {
- "config": {
- "chainId": 10,
- "homesteadBlock": 0,
- "eip155Block": 0,
- "eip158Block": 0
- },
- "alloc" : {
- },
- "coinbase" : "0x0000000000000000000000000000000000000000",
- "difficulty" : "0x02000000",
- "extraData" : "","gasLimit":"0x2fefd8","nonce":"0x0000000000000042","mixhash":"0x0000000000000000000000000000000000000000000000000000000000000000","parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000","timestamp":"0x00"
- }
参数 描述
mixhash 与 nonce 配合挖矿
nonce 一个 64 位的随机数, 用于挖矿
difficulty 设置当前区块难度
alloc 用来预置账号以及账号的以太币数量, 因为私有链挖矿比较容易, 这里不需要设置
coinbase 矿工账号
timestamp 设置创世区块的时间戳
parentHash 上一个区块的 hash 值, 因为是创世区块, 所以是 0
extraData 附加信息, 随便填, 可以写你的个人信息 (中本聪 2009)
gasLimit 设置对 GAS 的消耗总量限制
row 2 col 1 row 2 col 2
4. 通过 geth 命令指定私有链的创世文件
a, 开始 ---》运行 ----》cmd--- 进入控制台
b,cd 命令进入到 geth 的安装目录
C:\Users\Administrator\AppData\Roaming\Mist\binaries\Geth\unpacked
c, 运行 geth --datadir "%cd%\chain" init piccgenesis.JSON 命令, 指定私有链的创世文件 (%cd%: 代表 Geth 安装目录 )
5. 创建数据存放地址并初始化创世块
geth --identity "PICCetherum" --rpc --rpccorsdomain "*" --datadir "%cd%\chain" --port"30303" --rpcapi"db,eth,net,web3" --networkid 95518 console
打开 geth 控制台 geth -datadir "%cd%\chain" --nodiscover console 2
当看到 Listening on [::]:30303 和 Welcome to the Geth JavaScript console! 的提示, 说明已经启动成功
6, 在私有链上创建账号
键入: personal.newAccount() 会提示输入密码, 我输入: 123456
7, 挖矿
开始挖矿 miner.start() 结束挖矿 miner.stop()
8, 命令查看主账户中以太币的数量
eth.getBalance(eth.accounts[0]) 结果不为 0, 说明挖矿成功
9, 换另一个用户挖矿
miner.setEtherbase("0x3e5b31e581546f2900c0f3289153c788c92a2b41")
10, 查看账户余额
eth.getBalance()
来源: http://www.bubuko.com/infodetail-3329537.html