使用Geth设置基于权利证明POA的以太网私有网络

本教程详述如何使用Geth和权威证明(POA)共识机制设置本地以太坊私有网络。内容涵盖操作系统和软件需求、创建工作区、初始化节点、设置bootnode、激活网络以及与节点交互的步骤,旨在帮助开发者构建以太坊开发环境以测试智能合约和DApps。
摘要由CSDN通过智能技术生成

目标:逐步指导,帮助你使用权威证明共识引擎(也称为clique)设置本地私有以太网网络。

简而言之:我们将在同一台机器上设置两个节点,在我们的localhost上创建一个点对点网络。除了两个节点之外,还将设置启动节点(发现服务)。

我花了相当长的时间和广泛的研究和谷歌搜索,最终有一个坚实的以太坊开发环境来测试我的智能合约和我的DApps。

在这篇文章中,我决定分享我如何使用Geth的clique共识引擎设置一个Proof-of-Authority网络。这是我通过回馈感谢社区的方式,并希望让任何愿意探索以太坊宇宙的人都能过上更轻松的生活。

操作系统和软件

我的操作系统是Ubuntu 16.04 LTS(这个tuto是在一个新的虚拟机中完成的)。

对于以太坊客户端,我使用的是Geth(以太坊protocole的Go实现)。我相信Geth很容易安装,有很多很棒的教程,所以我不打算在这里安装任何装置。我目前正在运行Geth 1.7.3-stable:

$ geth version
Geth
Version: 1.7.3-stable
Git Commit: 4bb3c89d44e372e6a9ab85a8be0c9345265c763a
Architecture: amd64
Protocol Versions: [63 62]

和Geth 1.8.1-stable:

$ geth version
Geth
Version: 1.8.1-stable
Git Commit: 1e67410e88d2685bc54611a7c9f75c327b553ccc
Architecture: amd64
Protocol Versions: [63 62]

我强烈建议你查看Geth命令行界面文档。你需要它。非常的。

让我们开始吧

1.0 概述

让我们从头到尾…为了清楚起见,这是你完成第1章后应该得到的。

devnet$ tree -L 2
.
├── accounts.txt
├── boot.key
├── genesis.json
├── node1
│   ├── geth
│   ├── keystore
│   └── password.txt
└── node2
    ├── geth
    ├── keystore
    └── password.txt
1.1 创建工作区
$ mkdir devnet
$ cd devnet
devnet$ mkdir node1 node2
1.2 创建你的帐户

帐户(也称为钱包)拥有与任何区块链交互所需的公私钥对。任何挖掘节点(严格来说我们的节点不会挖掘但投票)需要能够签署交易(使用他们的私钥)并在网络上标识自己(地址来自公钥)。因此,我们至少需要两个帐户,每个节点一个帐户。

在Geth行话中,投票节点称为Sealer。

对于节点1:

devnet$ geth --datadir node1/ account new
Your new account is locked with a password. Please give a password. Do not forget this password.
Passphrase: pwdnode1 (for example)
Repeat passphrase: pwdnode1
Address: {87366ef81db496edd0ea2055ca605e8686eec1e6}

节点2:

devnet$ geth --datadir node2/ account new
Your new account is locked with a password. Please give a password. Do not forget this password.
Passphrase: pwdnode2 (for example)
Repeat passphrase: pwdnode2
Address: {08a58f09194e403d02a1928a7bf78646cfc260b0}

这将创建包含你的帐户文件的keystore/。请注意,keystore/中文件名的最后一部分是你帐户的地址(也在上面的终端中打印)。

我建议从终端屏幕复制这两个地址,并将它们保存在文本文件中。这将在以后简化一些复制粘贴工作。但请记住,你可以从keystore /中的UTC-datetime-address文件中读取这些addesses。

devnet$ echo '87366ef81db496edd0ea2055ca605e8686eec1e6' >> accounts.txt
devnet$ echo '08a58f09194e403d02a1928a7bf78646cfc260b0' >> accounts.txt

对于每个节点,我建议将密码保存在文件中。这将在以后简化某些流程(例如解锁你的帐户)

devnet$ echo 'pwdnode1' > node1/password.txt
devnet$ echo 'pwdnode2' > node2/password.txt
1.3 创建你的Genesis文件

genesis文件是用于初始化区块链的文件。第一个块,称为genesis块,是根据genesis.json文件中的参数精心设计的。

Geth带有一堆expeuables,如puppethbootnode。你可以在Geth github上找到完整列表。Puppeth消除了从头开始创建一个genesis文件的痛苦(并做了更多)。开始吧:

devnet$ puppeth

并愉快地回答问题(每个值都可以在以后手动更新,所以不要花太多时间为第一次试验设计它)。

Please specify a network name to administer (no spaces, please)
> devnet
What would you like to do? (default = stats)
 1. Show network stats
 2. Configure new genesis
 3. Track new remote server
 4. Deploy network components
> 2
Which consensus engine to use? (default = clique)
 1. Ethash - proof-of-work
 2. Clique - proof-of-authority
> 2
How many seconds should blocks take? (default = 15)
> 5 // for example
Which accounts are allowed to seal? (mandatory at least one)
> 0x87366ef81db496edd0ea2055ca605e8686eec1e6 //copy paste from account.txt :)
> 0x08a58f09194e403d02a1928a7bf78646cfc260b0
Which accounts should be pre-funded? (advisable at least one)
> 0x87366ef81db496edd0ea2055ca605e8686eec1e6 // free ethers !
> 0x08a58f09194e403d02a1928a7bf78646cfc260b0
Specify your chain/network ID if you want an explicit one (default = random)
> 1515 // for example. Do not use anything from 1 to 10
Anything fun to embed into the genesis block? (max 32 bytes)
>
What would you like to do? (default = stats)
 1. Show network stats
 2. Manage existing genesis
 3. Track new remote server
 4. Deploy network components
> 2
1. Modify existing fork rules
 2. Export genesis configuration
> 2
Which file to save the genesis into? (default = devnet.json)
> genesis.json
INFO [01-23|15:16:17] Exported existing genesis block
What would you like to do? (default = stats)
 1. Show network stats
 2. Manage existing genesis
 3. Track new remote server
 4. Deploy network components
> ^C // ctrl&#
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值