基于ETH发私链

版权声明:本文为博主原创文章,未经博主允许不得转载,如有技术需要联系[email protected]! https://blog.csdn.net/harrison2010/article/details/80026271

目的

成功搭建基于ETH私链,并加入节点.

准备

1.centos 系统
2. windows 系统
3. 下载
geth下载 https://geth.ethereum.org/downloads/
钱包下载 https://github.com/ethereum/mist/releases
eth命令参数 参考地址 https://www.cnblogs.com/tinyxiong/p/7918706.html

具体步骤

centos机器上

创建初始块

    {
       "coinbase": "0x0000000000000000000000000000000000000000",
       "config": {
              "homesteadBlock": 5
        },
       "difficulty": "0x2000",
       "extraData": "0x",
       "gasLimit": "0x2FEFD8",
       "mixhash": "0x00000000000000000000000000000000000000647572616c65787365646c6578",
       "nonce": "0x0",
       "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
       "timestamp": "0x00",
       "alloc": {}
    }

配置说明:
config.chainId // 区块链的ID,在 geth 命令中的 –networkid 参数需要与 chainId 的值一致
config.homesteadBlock // Homestead 硬分叉区块高度,不需要关注 config.eip155Block //
EIP 155 硬分叉高度,不需要关注 config.eip158Block // EIP 158 硬分叉高度,不需要关注 coinbase
// 矿工账号,第一个区块挖出后将给这个矿工账号发送奖励的以太币 difficulty // 难度值,越大越难 extraData //
附加信息随便填 gasLimit // gas 的消耗总量限制,用来限制区块能包含的交易信息总和,因为我们是私有链,所以填最大 nonce
// 一个 64 位随机数 mixhash // 与 nonce 配合用于挖矿,由上一个区块的一部分生成的 hash parentHash
// 上一个区块的 hash 值 alloc // 预设账号以及账号的以太币数量,私有链挖矿比较容易可以不配置

把上面文件保存到一个 /opt/init.json文件中
创建区块链目录/opt/blockchain
执行下面命令 创建初始快.
./geth –datadir “/opt/blockchain” init /opt/init.json

创建初始账号

在命令行中输入 personal.newAccount(“123456”)

启动

./geth –datadir “/opt/blockchain” –rpc –rpcaddr “0.0.0.0” –port “30301” –rpcapi “eth,net,web3,personal” –networkid 110 –rpccorsdomain “*” console

加入其它节点

admin.addPeer(”) 增加地址来处理, 等在windows机器上安装完毕.再来操作这一步

挖矿

miner.start(1)

windows机器上

创建初始块

同样的json初始块保存到一个 d:\eth\init.json文件中
创建区块链目录d:\eth\blockchain
执行下面命令 创建初始快.
geth –datadir “d:\eth\blockchain” init d:\eth\init.json

创建初始账号

在命令行中输入 personal.newAccount(“123456”)

启动

./geth –datadir “/opt/blockchain” –rpc –rpcaddr “0.0.0.0” –port “30301” –rpcapi “eth,net,web3,personal” –networkid 110 –rpccorsdomain “*” console

查看节点信息

admin.nodeInfo命令查看自己的节点信息,并修改最后的ip为自己的ip, 在centos机器上使用admin.addPeer(”).来添加

enode://3f081340edbf8a569cb3fa84affe3cffc93e6e61a979d921ad394f5b067f85244637e2cdf3abf32f0dbe2b6e31391aeb94528dec2f79c460f142c066ad640528@100.64.89.200:30301

windows机器上安装mist钱包

  1. 启动后看到连接私链,
  2. 进去后看到第一次在windows上创建的账号
  3. 还可以通过钱包创建账号
  4. 如果想让钱包里面有ETH,可以通过在centos机器上转账到这个账户,也可以再winidow上启动挖矿命令.
  5. 等钱包账号有ETH了,就可以很轻松的转入转出

猜你喜欢

转载自blog.csdn.net/harrison2010/article/details/80026271