Ubuntu系统搭建以太坊私有链

xiaoxiao2025-04-30  49

以太坊环境搭建

 

安装go环境

Geth安装

$ sudo apt-get install software-properties-common$ sudo add-apt-repository -y ppa:ethereum/ethereum$ sudo apt-get update$ sudo apt-get install ethereum

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

 

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

启动以太坊:

geth --datadir "~/.ethereum" console

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

 

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

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

personal.newAccount("qhh666888")

 

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

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

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

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

 

转载请注明原文地址: https://www.6miu.com/read-5029462.html

最新回复(0)