centos7部署ethereum私有链
https://github.com/ethereum/go-ethereum/wiki
http://book.8btc.com/books/6/ethereum/_book/public-chain-chain.html
https://www.cnblogs.com/zl03jsj/p/6876064.html
安装客户端
yum -y install golang
go version
> go version go1.8.3 linux/amd64
wget https://gethstore.blob.core.windows.net/builds/geth-alltools-linux-amd64-1.7.3-4bb3c89d.tar.gz
tar xvfz geth-alltools-linux-amd64-1.7.3-4bb3c89d.tar.gz
export PATH=$PATH:/root/geth-alltools-linux-amd64-1.7.3-4bb3c89d
创始块初始化文件genesis.json
{
"config": {
"chainId": 123,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"nonce": "0x0000000000000033",
"timestamp": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": "0x8000000",
"difficulty": "0x100",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x3333333333333333333333333333333333333333",
"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的消耗总量限制,用来限制区块能包含的交易信息总和,因为我们是私有链,所以填最大。
私有链节点初始化
mkdir /opt/blockchain
geth --datadir /opt/blockchain init genesis.json
控制台方式连接私有链
geth --networkid 123 --datadir /opt/blockchain console
建立矿工帐号
# 第1个建立的帐号默认为矿工帐号
> personal.newAccount("me")
"0xdd3381d3d81593bcc4440a634fdf964e19744ed9"
节点默认矿工帐号
> eth.coinbase
Error: etherbase address must be explicitly specified
at web3.js:3143:20
at web3.js:6347:15
at get (web3.js:6247:38)
at <unknown>
建立以后就有了
> eth.coinbase
"0xdd3381d3d81593bcc4440a634fdf964e19744ed9"
后台启动
nohup geth --networkid 123 --datadir /opt/blockchain --mine --nodiscover --rpc --rpcaddr 0.0.0.0 --rpcapi "db,eth,net,web3,admin,personal" --ipcpath /opt/blockchain/geth.ipc &
以太坊钱包连接
/opt/Ethereum Wallet/ethereumwallet --rpc /opt/blockchain/geth.ipc
连接到以太坊私链
geth attach /opt/blockchain/geth.ipc
geth attach http://127.0.0.1:8545
挖矿
miner.start(1)
矿工的以太WEI
> eth.getBalance(eth.coinbase)
2.031e+22
> web3.fromWei(eth.getBalance(eth.coinbase)) # 转成以太币
当前节点值
> admin.nodeInfo.enode
"enode://7ea7808369eef9718e4490b3913bbacc0176f88fe0d8ad6085ca3e614b30eb244a70aa226015aa8cfad58938915946dcefc78ef960f0447c526e221ac62077b2@[::]:30303?discport=0"
当前块号
> eth.blockNumber
255
当前块内容
> eth.getBlock(255)
多节点配置(开发环境的话,1个节点上建立多个帐户即可)
必须使用同样创始块初始化文件genesis.json创建节点,参考前面的操作。
节点1 192.168.48.111
节点2 192.168.48.112
节点3 192.168.48.113
节点4 192.168.48.114
# 查询节点1信息
> admin.nodeInfo.enode or admin.nodeInfo
"enode://9d12900c5b7105d6db5769bacbf16e02574e19f8a8db4d16c8fad2b10a17c566f09e81619c298e3d4bbca0f0f5476ee3ef60e16a2f8cd3fe323ea884025d3fe8@[::]:30303?discport=0"
# 节点2, 3, 4分别添加节点1
# 节点1信息中的 [::] 需要替换为 ip地址 , 使用同一个 networkid
> personal.newAccount("he")
> personal.newAccount("she")
> personal.newAccount("it")
> admin.addPeer("enode://9d12900c5b7105d6db5769bacbf16e02574e19f8a8db4d16c8fad2b10a17c566f09e81619c298e3d4bbca0f0f5476ee3ef60e16a2f8cd3fe323ea884025d3fe8@192.168.48.111:30303?discport=0")
true
#随后自动同步区位块
> INFO [02-09|10:55:42] Block synchronisation started
INFO [02-09|10:55:42] Imported new state entries count=1 elapsed=117.431µs processed=1 pending=0 retry=0 duplicate=0 unexpected=0
INFO [02-09|10:55:45] Imported new block headers count=192 elapsed=2.803s number=192 hash=0a09dc…8adbb1 ignored=0
INFO [02-09|10:55:45] Imported new block receipts count=192 elapsed=3.552ms bytes=768 number=192 hash=0a09dc…8adbb1 ignored=0
INFO [02-09|10:55:45] Imported new block headers count=192 elapsed=106.312ms number=384 hash=a976d1…9df3ae ignored=0
INFO [02-09|10:55:45] Imported new block receipts count=192 elapsed=3.790ms bytes=768 number=384 hash=a976d1…9df3ae ignored=0
INFO [02-09|10:55:46] Imported new block headers count=2048 elapsed=1.262s number=2432 hash=cc5639…98edb1 ignored=0
INFO [02-09|10:55:47] Imported new block receipts count=2048 elapsed=96.143ms bytes=8192 number=2432 hash=cc5639…98edb1 ignored=0
INFO [02-09|10:55:48] Generating ethash verification cache epoch=1 percentage=67 elapsed=3.080s
INFO [02-09|10:55:49] Generated ethash verification cache epoch=1 elapsed=4.515s
INFO [02-09|10:55:59] Imported new block headers count=1792 elapsed=12.194s number=4224 hash=34b889…a9ffca ignored=0
INFO [02-09|10:55:59] Imported new block receipts count=1514 elapsed=79.429ms bytes=6056 number=3946 hash=37d0fc…7484d9 ignored=0
INFO [02-09|10:55:59] Imported new state entries count=1 elapsed=69.436µs processed=2 pending=0 retry=0 duplicate=0 unexpected=0
INFO [02-09|10:55:59] Imported new block receipts count=1 elapsed=102.927µs bytes=4 number=3947 hash=96d4bd…b936ca ignored=0
INFO [02-09|10:55:59] Committed new head block number=3947 hash=96d4bd…b936ca
INFO [02-09|10:55:59] Imported new chain segment blocks=277 txs=0 mgas=0.000 elapsed=239.845ms mgasps=0.000 number=4224 hash=34b889…a9ffca
INFO [02-09|10:55:59] Imported new block headers count=39 elapsed=544.628ms number=4263 hash=df5c71…ee6138 ignored=0
WARN [02-09|10:55:59] Skipping deep transaction reorg depth=4224
INFO [02-09|10:55:59] Imported new chain segment blocks=39 txs=0 mgas=0.000 elapsed=15.711ms mgasps=0.000 number=4263 hash=df5c71…ee6138
INFO [02-09|10:55:59] Fast sync complete, auto disabling
INFO [02-09|10:56:00] Imported new chain segment blocks=3 txs=0 mgas=0.000 elapsed=20.714ms mgasps=0.000 number=4266 hash=327227…dad296
INFO [02-09|10:56:04] Imported new chain segment blocks=1 txs=0 mgas=0.000 elapsed=7.450ms mgasps=0.000 number=4267 hash=759130…d8d811
# 登录节点1查看
> admin.peers
[{
caps: ["eth/63"],
id: "60823ad532b30cebf94013295d08010b657fb4a3c226fd6a3a96578bb85292f9987a4d0b3f24d92cd448dba3d083418dde368f811797c3bc966c3a9775e19553",
name: "Geth/v1.7.3-stable-4bb3c89d/linux-amd64/go1.9.2",
network: {
localAddress: "192.168.48.111:30303",
remoteAddress: "192.168.48.113:37136"
},
protocols: {
eth: {
difficulty: 2097152,
head: "0xb059eea745254c042c4736749d8cbd10d67ea4276b9e312a669e60d56992d967",
version: 63
}
}
}, {
caps: ["eth/63"],
id: "693ea792c9d1ce90c1242e0650cefcaf931de9f4f21ef5cd551047b409a45ee0654bfd769a4b8aa85e57da5aa35fdf86f950979d0e4e9b699857f86152e9d28c",
name: "Geth/v1.7.3-stable-4bb3c89d/linux-amd64/go1.9.2",
network: {
localAddress: "192.168.48.111:30303",
remoteAddress: "192.168.48.112:52756"
},
protocols: {
eth: {
difficulty: 2097152,
head: "0xb059eea745254c042c4736749d8cbd10d67ea4276b9e312a669e60d56992d967",
version: 63
}
}
}, {
caps: ["eth/63"],
id: "b8419370552fb2089d140b78be5c552a69c026b03d76ef88d443e9d5e5b48d27c07726a4e7ad18820426a7d881c82ac94f3d752329b7942d728d87b7c666ddbc",
name: "Geth/v1.7.3-stable-4bb3c89d/linux-amd64/go1.9.2",
network: {
localAddress: "192.168.48.111:30303",
remoteAddress: "192.168.48.114:44970"
},
protocols: {
eth: {
difficulty: 2097152,
head: "0xb059eea745254c042c4736749d8cbd10d67ea4276b9e312a669e60d56992d967",
version: 63
}
}
}]
# 这种控制台添加节点方式,一旦退出控制台就失效,所以使用命令方式添加
nohup geth --networkid 123 --datadir /opt/blockchain --identity "TestChain_112" --mine --port 30303 --nodiscover --rpc --rpcaddr 0.0.0.0 --rpcport 8545 --rpcapi "db,eth,net,web3" --bootnodes "enode://9d12900c5b7105d6db5769bacbf16e02574e19f8a8db4d16c8fad2b10a17c566f09e81619c298e3d4bbca0f0f5476ee3ef60e16a2f8cd3fe323ea884025d3fe8@192.168.48.111:30303" &
nohup geth --networkid 123 --datadir /opt/blockchain --identity "TestChain_113" --mine --port 30303 --nodiscover --rpc --rpcaddr 0.0.0.0 --rpcport 8545 --rpcapi "db,eth,net,web3" --bootnodes "enode://9d12900c5b7105d6db5769bacbf16e02574e19f8a8db4d16c8fad2b10a17c566f09e81619c298e3d4bbca0f0f5476ee3ef60e16a2f8cd3fe323ea884025d3fe8@192.168.48.111:30303" &
nohup geth --networkid 123 --datadir /opt/blockchain --identity "TestChain_114" --mine --port 30303 --nodiscover --rpc --rpcaddr 0.0.0.0 --rpcport 8545 --rpcapi "db,eth,net,web3" --bootnodes "enode://9d12900c5b7105d6db5769bacbf16e02574e19f8a8db4d16c8fad2b10a17c566f09e81619c298e3d4bbca0f0f5476ee3ef60e16a2f8cd3fe323ea884025d3fe8@192.168.48.111:30303" &
centos7部署ethereum私有链的更多相关文章
- 区块链学习(四)truffle部署编译智能合约以太坊私有链
前面我们介绍了以太坊私有链的搭建以及多节点私有链网络,这次我们介绍如何使用truffle框架来部署编译智能合约到我们之前搭建的私有链网络中. 搭建环境及需使用的工具:ubuntu18.04 Truf ...
- 从零构建以太坊(Ethereum)智能合约到项目实战——第20章 搭建自己的私有链网络
P75 .1-以太坊私网建立 .合约编译.部署完全教程(1) 使用此博文进行安装配置:https://blog.csdn.net/w88193363/article/details/79402074 ...
- 区块链开发学习第三章:私有链上部署helloBlockchain简单合约
前面讲了部署私有链以及新增账户,现在进行到了部署合约了,此操作真是踩了无数无数无数的坑,到写文章为止确实是已经部署好了,但是还有些坑是还没有解决的! 一.Solidity编译器 开始的时候用的http ...
- CentOS7搭建以太坊私有链
1. 环境准备:Win10 64位安装 VM VirtualBox,操作系统版本: CentOS-7-x86_64-Everything-1611.iso(7.71G). 切换root账号,方便安装程 ...
- AntShares区块链的节点部署与搭建私有链
近期陆续体验常见的区块链开源项目,比如小蚁OnChain出的AntShares.AntShares跟其它开源区块链项目不一样,他们家是使用C#开发,基于.NET Core执行在Linux,期待未来出G ...
- Truffle 4.0、Geth 1.7.2、TestRPC在私有链上搭建智能合约
目录 目录 1.什么是 Truffle? 2.适合 Truffle 开发的客户端 3.Truffle的源代码地址 4.如何安装? 4.1.安装 Go-Ethereum 1.7.2 4.2.安装 Tru ...
- 区块链--Ubuntu上搭建以太坊私有链
1.搭建私链所需环境 操作系统:ubuntu16.04,开虚拟机的话要至少4G,否则会影响测试挖矿时的速度 软件: geth客户端 Mist和Ethereum Wallet:https://githu ...
- 转:区块链开发(一)搭建基于以太坊go-ethereum的私有链环境
区块链开发(一)搭建基于以太坊go-ethereum的私有链环境 wo541075754 · 2016-11-07 13:00:03 · 3730 次点击 · 预计阅读时间 3 分钟 · 约1小时前 ...
- 以太坊开发(二)使用Ganache CLI在私有链上搭建智能合约
以太坊开发(二)使用Ganache CLI在私有链上搭建智能合约 在上一篇文章中,我们使用Truffle自带的客户端Truffle Develop,在私有链上搭建并运行了官方提供的WebPack智能合 ...
随机推荐
- bootstrap Table从零开始
本文博主将从零开始,一步一步的告诉大家如何在前端用bootstrap Table插件展示一个表格 首先,要下载bootstrap Table插件所必须的js,地址:https://github.c ...
- springboot(四)-项目部署
Springboot和我们之前学习的web应用程序不一样,其本质上是一个java应用程序.部署的方式有两种:打成jar包,或者打成war包. 打成jar包 切换到项目文件中 然后mvn install ...
- springboot(一):入门
什么是springboot Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不 ...
- 1148 Werewolf - Simple Version (20 分)
Werewolf(狼人杀) is a game in which the players are partitioned into two parties: the werewolves and th ...
- archlinux升级firefox的flash插件
参考:http://blog.csdn.net/kingolie/article/details/53066415 1. 在https://get.adobe.com/flashplayer/下载文件 ...
- svn server配置与TortoiseSVN、Ankhsvn+VS使用
Svn服务器与客户端安装 1. 下载安装VisualSvn-Server服务端.(过程略)http://subversion.apache.org/packages.html 2. ...
- hadoop面试题一
1.hadoop运行的原理?xxxxxx 2.mapreduce的原理?xxxxxx 3.HDFS存储的机制?xxxxxx 4.举一个简单的例子说明mapreduce是怎么来运行的 ?xxxxxx 5 ...
- 为什么一段时间后网站后台自动退出 php中session过期时间设置
修改php配置文件中的session.gc_maxlifetime.如果想了解更多session回收机制,继续阅读.(本文环境php5.2) 概述:每一次php请求,会有1/100的概率(默认值)触发 ...
- [SDOI2013]刺客信条
Description 故事发生在1486 年的意大利,Ezio 原本只是一个文艺复兴时期的贵族,后来因为家族成员受到圣殿骑士的杀害,决心成为一名刺客.最终,凭借着他的努力和出众的天赋,成为了杰出的刺 ...
- PHP通过映射类查找类所在文件
$reflectObj = new ReflectionClass(类名); $file_name = $reflectObj->getFileName(); var_dump($file_na ...