CentOS 7 安装以太坊(Etherum)Geth尝试挖矿

本地私有链尝试以太坊挖矿功能

参考

http://blog.csdn.net/xc70203/article/details/77988473

http://blog.csdn.net/wo541075754/article/details/79260040

虚拟机环境

2C4G20G,CentOS Linux release 7.4.1708 (Core)

安装所需基础工具:
yum update -y && yum install git wget bzip2 vim gcc-c++ ntp epel-release nodejs cmake -y
安装Go
wget https://dl.google.com/go/go1.10.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.10.linux-amd64.tar.gz
echo 'export GOROOT=/usr/local/go' >> /etc/profile  
echo 'export PATH=$PATH:$GOROOT/bin' >> /etc/profile  
echo 'export GOPATH=/root/go' >> /etc/profile
echo 'export PATH=$PATH:$GOPATH/bin' >> /etc/profile
source /etc/profile

验证

$ go version
go version go1.10 linux/amd64
克隆编译项目go-ethereum
git clone https://github.com/ethereum/go-ethereum.git  
cd go-ethereum  
make all
在path中加入geth路径
echo 'export PATH=$PATH:/opt/go-ethereum/build/bin' >> /etc/profile
source /etc/profile

验证

$ geth version
Geth
Version: 1.8.2-unstable
Git Commit: bd6879ac518431174a490ba42f7e6e822dcb3ee1
Architecture: amd64
Protocol Versions: [63 62]
Network Id: 1
Go Version: go1.10
Operating System: linux
GOPATH=/root/go
GOROOT=/usr/local/go
配置私有链初始状态,新建文件genesis.json
{ 
    "config": {
            "chainId": 22, 
            "homesteadBlock": 0, 
            "eip155Block": 0, 
            "eip158Block": 0 
    },
    "alloc" : {},
    "coinbase" : "0x0000000000000000000000000000000000000000", 
    "difficulty" : "0x400", 
    "extraData" : "", 
    "gasLimit" : "0x2fefd8", 
    "nonce" : "0x0000000000000038", 
    "mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000", 
    "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", 
    "timestamp" : "0x00" 
}
初始化区块链,生成创世区块和初始状态
geth --datadir /opt/data init /opt/eth/genesis.json
启动节点,进入Geth的cli界面挖矿
geth --identity "TestNode" --rpc --rpcport "8545" --datadir /opt/data/ --port "30303" --nodiscover console

mine.start()总是null,挖不到,于是清空数据换一种方式启动节点,进入Geth的cli界面并直接开始挖矿

geth --identity "TestNode" --rpc --rpcport "8545" --datadir /opt/data/ --port "30303" --nodiscover --dev --dev.period 1 console

加了两个参数:--dev 表示自动创建一个账户并直接开始挖矿,--dev.period 1表示不用等有交易了才挖,如果设成0的话没有交易挖矿就是null

查看账号
personal.listAccounts
[]
新建账号,密码123456
personal.newAccount(123456)
"0x7d84a2638c9b25a758026446e67c822f34247bd8"
查看cionbase
eth.coinbase
"0x7d84a2638c9b25a758026446e67c822f34247bd8"
查看区块数量
eth.blockNumber
19
查看账号余额
myAddress = "0x7d84a2638c9b25a758026446e67c822f34247bd8"
"0x480086c9411cc3297c4aa6773a2e07c7b1efbafe"
eth.getBalance("0x7d84a2638c9b25a758026446e67c822f34247bd8")
1.15792089237316195423570985008687907853269984665640564039457584007913129639927e+77
换另一个用户挖矿
miner.setEtherbase("0x3e5b31e581546f2900c0f3289153c788c92a2b41")

报错

WARN [03-05|23:08:47] Block sealing failed err="authentication needed: password or unlock"

解锁挖矿用户

personal.unlockAccount(eth.coinbase)

再更换挖矿用户挖,又报错

WARN [03-05|23:18:48] Block sealing failed err=unauthorized

再用谁挖都是null,暂时不试了,再继续深入学习。

  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值