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智能合 ...
随机推荐
- 【算法笔记】B1042 字符统计
1042 字符统计 (20 分) 请编写程序,找出一段给定文字中出现最频繁的那个英文字母. 输入格式: 输入在一行中给出一个长度不超过 1000 的字符串.字符串由 ASCII 码表中任意可见字符及空 ...
- POJ3322 Bloxorz I 无脑广搜(我死了。。。)
多测不清空,爆零两行泪....我死了QWQ 每个节点3个状态:横坐标,纵坐标,和方向 说一下方向:0:立着,1:竖着躺着,上半部分在(x,y),2:横着躺着,左半部分在(x,y) 然后就有了常量数组: ...
- UVA - 11922 区间反转+拼接 可持久化Treap
题意:一开始给出一个序列\(1,2...n\),然后\(m\)次操作,每次把\([l,r]\)翻转并且拼接到序列的后面,求最后形成的序列 打个pushdown标记就好 #include<iost ...
- bugzilla配置邮箱发送邮件问题
2018-09-25 1.bugzilla注册账号,邮件无法发送 需要登录管理账号,配置邮箱服务 2.Can't locate object method "quit" via p ...
- 论文阅读 | Polygon-RNN:Annotating Object Instances with a Polygon-RNN
论文地址:https://arxiv.org/abs/1704.05548 项目地址:http://www.cs.toronto.edu/polyrnn 概述 Polygon-RNN是一篇收录于CVP ...
- Spark遇到的报错和坑
1. Java版本不一致,导致启动报错. # 解决方法: 在启动脚本最前边添加系统参数,指定Java版本 export JAVA_HOME=/usr/java/jdk1..0_181-amd64/jr ...
- SQL手工注入学习 一
sql注入: (基于DVWA环境的sql注入) 流程: 1.判断是否有SQL注入漏洞 2.判断操作系统.数据库和web应用的类型 3.获取数据库信息看,包括管理员信息(拖库) ...
- Java变量类型,实例变量 与局部变量 静态变量
实例变量: 实例变量在类中声明,但在方法的外面,构造函数或任何块. 当空间分配给某个对象在堆中,插槽为每个实例变量创建值. 当一个对象与使用关键字 “new” 来创建,在对象被销毁销毁创建的实例变量. ...
- Iterator遍历 (遍历集合)
迭代器(Iterator) 迭代器是一种设计模式,它是一个对象,它可以遍历并选择序列中的对象,而开发人员不需要了解该序列的底层结构.迭代器通常被称为“轻量级”对象,因为创建它的代价小. Java中的I ...
- 使用request与正则表达式爬取bangumi动画排行榜
import json import requests from requests.exceptions import RequestException import re import time d ...