当前位置:   article > 正文

linux搭建 eth节点,以太坊ETH开发1( Go-Ethereum搭建以太坊私链搭建)

go-ethereum make install

## Windown ##

1.首先到[geth-windows-amd64-1.8.11-dea1ce05.exe][] 下载安装包。

2.初始化创世区块(私链才需要这一步,公链不需要)

初始化创世区块时,要在geth根目录先创建一个genesis.json文件,内容如下:

{

"config": {

"chainId": 16,

"homesteadBlock": 0,

"eip155Block": 0,

"eip158Block": 0

},

"alloc": {

"0x83fd95f8e41f6afedd08dd6ae11db607a7a3c60c": {"balance": "666666666"},

"0x0000000000000000000000000000000000000002": {"balance": "222222222"}

},

"coinbase" : "0x0000000000000000000000000000000000000000",

"difficulty" : "0x20000",

"extraData" : "",

"gasLimit" : "0x2fefd8",

"nonce" : "0x0000000000000042",

"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",

"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",

"timestamp" : "0x00"

}

执行初始化命令(datadir为自定义的数据目录)

geth init genesis.json --datadir=D:\ETH\data

3.执行启动命令:

geth --datadir=D:\ETH\data --rpc --rpcport 8545 --rpcaddr "0.0.0.0" --rpcapi "personal,db,eth,net,web3" console

4.一些常用命令:

* 查看账户列表:

web3.eth.accounts

* 创建账户:

web3.personal.newAccount("123456789")

* 开启挖矿:

miner.start(1)

* 停止挖矿:

miner.stop()

* 查询余额

web3.eth.getBalance("0x0000000000000000000000000000000000")

* 解锁账户

web3.personal.unlockAccount(acc0,"123456")

* 转账(解锁之后才能转账,挖矿才能到账)

> acc0 = web3.eth.accounts

0

> “0xbe323cc4fde114269a9513a27d3e985f82b9e25d”

> acc1 = web3.eth.accounts

1

> “0x3b0ec02b4193d14abdc9cc5b264b5e3f39624d70”

> web3.eth.sendTransaction(\{from:acc0,to:acc1,value:web3.toWei(3,“ether”)\})

--------------------

## Linux ##

**1.下载[geth源码][geth],下载zip版本。**

***2.安装go语言环境:***

> rpm -ivh [http://ftp.riken.jp/Linux/fedora/epel/6/i386/epel-release-6-8.noarch.rpm][http_ftp.riken.jp_Linux_fedora_epel_6_i386_epel-release-6-8.noarch.rpm]

> yum install golang

中间有一步需要确认,输入小写的y,然后回车即可

**3.解压第一步的安装包**

进入解压目录执行make编译代码:

> make

在go-ethereum-xx/build/bin目录下创建genesis.json的文本文件,内容如下:

\{

“config”: \{

“chainId”: 16,

“homesteadBlock”: 0,

“eip155Block”: 0,

“eip158Block”: 0

\},

“alloc”: \{

“0x83fd95f8e41f6afedd08dd6ae11db607a7a3c60c”: \{“balance”: “666666666”\},

“0x0000000000000000000000000000000000000002”: \{“balance”: “222222222”\}

\},

“coinbase” : “0x0000000000000000000000000000000000000000”,

“difficulty” : “0x20000”,

“extraData” : “”,

“gasLimit” : “0x2fefd8”,

“nonce” : “0x0000000000000042”,

“mixhash” : “0x0000000000000000000000000000000000000000000000000000000000000000”,

“parentHash” : “0x0000000000000000000000000000000000000000000000000000000000000000”,

“timestamp” : “0x00”

\}

**4.执行初始化命令(datadir为自定义的数据目录):**

./geth --datadir /opt/eth/go-ethereum-1.8.11/build/bin/data init genesis.json

**5.启动节点:**

./geth --datadir=/opt/eth/go-ethereum-1.8.11/build/bin/data --rpc --rpcport 8545 --rpcaddr 0.0.0.0 --rpcapi personal,db,eth,net,web3 console

## Mac ##

Mac下的安装方式跟Linux一摸一样,只是genesis.json文件的内容要替换如下:

{

"config": {

"chainId": 10,

"homesteadBlock": 0,

"eip155Block": 0,

"eip158Block": 0

},

"alloc" : {},

"coinbase" : "0x0000000000000000000000000000000000000000",

"difficulty" : "0x20000",

"extraData" : "",

"gasLimit" : "0x2fefd8",

"nonce" : "0x0000000000000042",

"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",

"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",

"timestamp" : "0x00"

}

## 后台启动 ##

在命令前后加上nohup … &,

打开控制台:./geth attach /datadir/geth.ipc

[geth-windows-amd64-1.8.11-dea1ce05.exe]: https://geth.ethereum.org/downloads/

[geth]: https://github.com/ethereum/go-ethereum/releases

[http_ftp.riken.jp_Linux_fedora_epel_6_i386_epel-release-6-8.noarch.rpm]: http://ftp.riken.jp/Linux/fedora/epel/6/i386/epel-release-6-8.noarch.rpm

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/608534
推荐阅读
相关标签
  

闽ICP备14008679号