Ubuntu系统搭建以太坊私有链

以太坊环境搭建

 

安装go环境

Geth安装

  1. $ sudo apt-get install software-properties-common
  2. $ sudo add-apt-repository -y ppa:ethereum/ethereum
  3. $ sudo apt-get update
  4. $ sudo apt-get install ethereum

geth --help:查看安装已成功

Ubuntu系统搭建以太坊私有链_第1张图片

 

solc安装

sudo apt-get install solc

 

搭建以太坊私有链:

在根目录(~/)下编写创世块文件genesis.json:

{

  "nonce":"0x0000000000000042",

  "mixhash":"0x0000000000000000000000000000000000000000000000000000000000000000",

  "difficulty": "0x4000",

  "alloc": {},

  "coinbase":"0x0000000000000000000000000000000000000000",

  "timestamp": "0x00",

  "parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000",

  "extraData": "0x00000000",

  "gasLimit":"0xffffffff",

  "config" :{

    "chainId": 68,

    "homesteadBlock": 0,

    "eip155Block": 0,

    "eip158Block": 0
  }
}

初始化创世块文件:

geth --datadir "~/.ethereum" init ./genesis.json

Ubuntu系统搭建以太坊私有链_第2张图片

启动以太坊:

geth --datadir "~/.ethereum" console

Ubuntu系统搭建以太坊私有链_第3张图片

如上:已成功进入geth命令行。

 

开始挖矿miner.start(),出现如下错误:

Ubuntu系统搭建以太坊私有链_第4张图片

经查,是因为没有账户,eth.accounts无内容,所以需要先创建账户

personal.newAccount("qhh666888")

Ubuntu系统搭建以太坊私有链_第5张图片

 

如图,创建账户成功,开始挖矿miner.start():

Ubuntu系统搭建以太坊私有链_第6张图片

开始挖矿比较慢,等一段时间就会正式开始挖矿,挖矿成功:

Ubuntu系统搭建以太坊私有链_第7张图片

eth.blockNumber:查看产生块的数量

eth.getBalance(eth.accounts[0]):查看账户0的余额

 

你可能感兴趣的:(Ubuntu系统搭建以太坊私有链)