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

news/2024/7/7 14:34:11 标签: 区块链, 以太坊

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

参考

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,暂时不试了,再继续深入学习。


http://www.niftyadmin.cn/n/1531991.html

相关文章

洛谷 P2051 [AHOI2009]中国象棋

题目描述 这次小可可想解决的难题和中国象棋有关,在一个N行M列的棋盘上,让你放若干个炮(可以是0个),使得没有一个炮可以攻击到另一个炮,请问有多少种放置方法。大家肯定很清楚,在中国象棋中炮的…

Fabric简介

翻译自:http://hyperledger-fabric.readthedocs.io/en/latest/blockchain.html Fabric Hyperledger Fabric是一个由模块化架构支撑的分布式账本解决方案平台,提供高度的保密性、弹性、灵活性和伸缩性。它被设计支持不同组件的插拔,并且适应经…

Day02课堂成果

昨日回顾: 一 爬虫基本原理 - 爬虫全过程 1.发送请求 2.接收响应数据 3.解析并提取有价值的数据 4.保存数据 二 Requests请求库 - get url headers cookies - post …

区块链超级账本Hyperledger Fabric架构说明

翻译自:http://hyperledger-fabric.readthedocs.io/en/latest/arch-deep-dive.html 边学习边翻译,很多地方还不明白,请对照原文学习,转载请注明出处。 翻译说明: - peer全部翻译为对等点,是逻辑节点&…

【HTTP】四、HTTP协议常见问题

HTTP协议是一个非常重要的应用层协议,在面试中有很多关于这方面的问题,这里做一个总结,大部分都在前面的文章中提到了,没提到的这里做一个介绍。 1、HTTP协议的基本原理、工作流程 HTTP协议是超文本传输协议,是一个应用…

Linux CentOS安装zsh、oh-my-zsh和autojump

zsh牛逼之处参见:https://www.zhihu.com/question/21418449 安装zsh yum install -y zsh 装完之后验证一下最后一行有/bin/zsh [roothadoop3 ~]# cat /etc/shells /bin/sh /bin/bash /sbin/nologin /usr/bin/sh /usr/bin/bash /usr/sbin/nologin /bin/zsh 切换shel…

C++03:论类的重载/隐藏/覆盖/阻止

一.重载 成员被重载的特征:(1)相同的范围,在同一个类中 (2)函数名字相同 (3)参数不同 …

CentOS 三节点部署蓝鲸运维系统

设备条件 hostnameIPcpumemstoragesystemlanjing1192.168.100.1001C2G20GCentOS Linux release 7.3.1611 (Core)lanjing2192.168.100.1011C2G20GCentOS Linux release 7.3.1611 (Core)lanjing3192.168.100.1021C2G20GCentOS Linux release 7.3.1611 (Core) 关闭防火墙和SELin…