主页 > imtoken钱包下载地址 > 以太坊多节点私链搭建

以太坊多节点私链搭建

imtoken钱包下载地址 2023-02-10 07:43:22

以太坊多节点私链搭建

区块链火了,配置私有以太坊链来玩以太坊节点类型,了解这个疯狂的时代以太坊节点类型,免得被割韭菜

生成私链创世块配置的环境准备 1. 创建账户

# 创建privateNet目录
>mkdir privateNet
# 创建账户
>geth --datadir node0 account new
Your new account is locked with a password. Please give a password.
Passphrase:
Repeat passphrase:
Address: {57cbfdb91c9f78fc3b0ec995c44325e63d6e0a74}
# 密码记录到文件中
>echo node0 > node0/password

在其他节点服务器上,按照上述说明创建账号,例如生成:Address: {d1be0a55270232c2dc03ee453871f43cc045e906}

2.生成创世文件

genesis文件定义了私有链的第一个区块,这里我们使用puppeth工具生成

>puppeth
+-----------------------------------------------------------+
| Welcome to puppeth, your Ethereum private network manager |
|                                                           |
| This tool lets you create a new Ethereum network down to  |
| the genesis block, bootnodes, miners and ethstats servers |
| without the hassle that it would normally entail.         |
|                                                           |

以太经典和以太坊统一_以太坊和以太币有什么区别_以太坊节点类型

| Puppeth uses SSH to dial in to remote servers, and builds | | its network components out of Docker containers using the | | docker-compose toolset. | +-----------------------------------------------------------+ Please specify a network name to administer (no spaces, please) > privateNet Sweet, you can set this via --network= privateNet next time! INFO [03-20|15:25:21] Administering Ethereum network name= privateNet WARN [03-20|15:25:21] No previous configurations found path=/ root/.puppeth/privateNet 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 Which accounts are allowed to seal? (mandatory at least one) > 0xd1be0a55270232c2dc03ee453871f43cc045e906 > 0x57cbfdb91c9f78fc3b0ec995c44325e63d6e0a74 > 0x Which accounts should be pre-funded? (advisable at least one) > 0xd1be0a55270232c2dc03ee453871f43cc045e906 > 0x57cbfdb91c9f78fc3b0ec995c44325e63d6e0a74 > 0x Specify your chain/network ID if you want an explicit one (default = random) > 105 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 = testnet.json) > genesis.json INFO [03-20|15:29:24] 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

genesis.json的部分字段说明

字段说明

链号

链号

随机数

nonce 是用于挖矿的 64 位随机数。 注意it和mixhash的设置需要满足以太坊黄皮书4.3.4描述的条件。 区块头有效性,(44)

混合哈希

与nonce一起用于挖矿,是前一个区块的一部分产生的hash。注意他和nonce的设置需要满足以太坊黄皮书4.3.4描述的条件。 区块头有效性,(44)

困难

以太经典和以太坊统一_以太坊节点类型_以太坊和以太币有什么区别

设置当前区块的难度。 如果难度太高,CPU挖矿就会很困难。 在这里设置一个较小的难度

分配

用于预置账户和账户的以太币数量

币库

矿工账户

时间戳

设置创世块的时间戳

父哈希

上一个区块的哈希值,因为是创世区块,所以这个值为0

额外数据

附加信息,随便填,可以填写你的个人信息

气体限制

该值设置了对GAS总消耗量的限制,用于限制一个区块可以包含的交易信息总和

启动私有链网络 1.启动节点node0

起始节点

  geth --datadir node0 --port 30000 --nodiscover --unlock '0' --password ./node0/password console

2.启动节点node13。 建立节点间连接 4.启动RPC服务

>admin.startRPC("IP0", 8545, "*", "eth,net,web3,admin,personal")

这样我们就可以使用钱包(例如:metamask)连接私链

也可以在命令中加入相关参数,在启动节点时直接开启服务

>geth --networkid 105 --rpc --rpccorsdomain "*" --rpcaddr IP0 --rpcapi "db,eth,net,personal,web3" --datadir node0 --port 30000 --nodiscover --unlock '0' --password ./node0/password console

参数说明

以太坊节点类型_以太坊和以太币有什么区别_以太经典和以太坊统一

字段说明

--rpc

开启rpc连接功能

--rpc端口

指定rpc端口,部署truffle时需要连接

--rpccorsdomain

这可以表示什么URL可以连接到你的节点执行RPC自定义结束任务

--数据目录

数据文件

- 港口

节点服务端口

--rpcapi

支持的rpcapi

--networkid

Chain id,对应创世块的chainId

安慰

进入命令行模式

矿业

在各节点控制台输入以下命令开始挖矿:

> miner.start()
INFO [03-20|17:09:03] Transaction pool price threshold updated price=18000000000
INFO [03-20|17:09:03] Starting mining operation

可信节点的管理

我们的私链采用POA共识算法,这里简单介绍一下

1. POA的特点 2. POA的工作流程 3. 添加和删除可信节点