文章目录
环境准备
Layer1网络在l1-test1
、l1-test2
和l1-test3
三台虚拟机上部署,笔者采用erigon作为节点客户端。之所以使用erigon是因为其原生支持区块链浏览器otterscan,只需要启动一个docker服务即可,本文中会提供部署方式。除此之外geth也可以用作Layer1的节点客户端,用户可以自行实验,本文中只介绍erigon的部署方式。
以下操作均在当前用户目录下进行:
$ pwd
/home/polygon
首先在三个虚拟机上安装erigon,目前erigon的最新版本为v2.60.10,如果下载失败可能需要配置HTTP代理(命令前边加上HTTP_PROXY=10.20.0.1:10809 HTTPS_PROXY=http://10.20.0.1:10809
),如下所示:
$ wget https://github.com/erigontech/erigon/releases/download/v2.60.10/erigon_v2.60.10_linux_amd64.tar.gz
下载完后解压并将目录改为erigon
$ tar -zxvf erigon_v2.60.10_linux_amd64.tar.gz
$ mv erigon_v2.60.10_linux_amd64 erigon
将erigon目录加入PATH环境变量,编辑.bashrc
文件,追加内容
$ echo 'export PATH=$PATH:/home/polygon/erigon' >> ~/.bashrc
$ source ~/.bashrc
确认下erigon是否配置完毕:
$ erigon -v
erigon version 2.60.10-3afee08b
然后安装foundry,foundry是一套智能合约开发工具集合,我们将在后边使用该工具(如连接失败请添加HTTP代理设置--proxy http://10.20.0.1:10809
)
$ curl -L https://foundry.paradigm.xyz | bash
先更新下环境变量,然后执行foundryup
命令,该命令会自动下载工具箱中的其他程序(如连接失败请在foundryup
命令前添加HTTP代理设置HTTP_PROXY=10.20.0.1:10809 HTTPS_PROXY=10.20.0.1:10809
)
$ source ~/.bashrc
$ foundryup
如显示以下日志说明安装成功:
foundryup: installed - forge 0.2.0 (7a23a5c 2024-12-01T00:29:15.606542954Z)
foundryup: installed - cast 0.2.0 (7a23a5c 2024-12-01T00:29:15.562664824Z)
foundryup: installed - anvil 0.2.0 (7a23a5c 2024-12-01T00:29:15.516286677Z)
foundryup: installed - chisel 0.2.0 (7a23a5c 2024-12-01T00:29:15.567586053Z)
foundryup: done!
节点初始化
以上操作均完成后继续erigon节点的配置,首先在当前用户目录下创建文件夹data
作为节点数据目录:
$ mkdir data
然后分别在三个虚拟机中执行以下命令生成出块账户私钥:
$ cast wallet new-mnemonic
分别得到以下结果:
l1-test1节点:
Generating mnemonic from provided entropy...
Successfully generated a new mnemonic.
Phrase:
time welcome ostrich hat junior garbage trigger dwarf cushion carbon praise expose
Accounts:
- Account 0:
Address: 0x8Be48b57E25BF1a63454fDFbBb6e2C2C81fd9fbc
Private key: 0xc7e63c4c63cb30e086e69efab01385442336e77cd41e83324d57389ebb65d2e8
l1-test2节点:
Generating mnemonic from provided entropy...
Successfully generated a new mnemonic.
Phrase:
insect possible quarter draw seminar pulp romance pencil jeans wonder vague attitude
Accounts:
- Account 0:
Address: 0x62A6c64a066E16e68F40f55f4c92Ee49CA81Dc9e
Private key: 0x168deb831eca9717ace19957e6ada0bf383056d413c81b2348b2f0a05a9b838e
l1-test3节点:
Generating mnemonic from provided entropy...
Successfully generated a new mnemonic.
Phrase:
crystal edge thunder earn scissors below laundry seven unlock quiz ranch play
Accounts:
- Account 0:
Address: 0xEf976e616D202856c4914ad2653843BfA3101395
Private key: 0x2376936f215e4aa33af4753a130c1b0f4d9fee32e7cc28e6eec1e69c6c646e84
生成的三个账户作为相应节点的出块账户,请读者根据自己环境的实际执行结果进行后续操作,生成的Private key
写入各自data
目录的privatekey
文件中
l1-test1节点:
$ echo c7e63c4c63cb30e086e69efab01385442336e77cd41e83324d57389ebb65d2e8 >> /home/polygon/data/privatekey
l1-test2节点:
$ echo 168deb831eca9717ace19957e6ada0bf383056d413c81b2348b2f0a05a9b838e >> /home/polygon/data/privatekey
l1-test3节点:
$ echo 2376936f215e4aa33af4753a130c1b0f4d9fee32e7cc28e6eec1e69c6c646e84>> /home/polygon/data/privatekey
然后再生成一个管理员账户用来接收初始发行的token
$ cast wallet new-mnemonic
Generating mnemonic from provided entropy...
Successfully generated a new mnemonic.
Phrase:
cup wire wash thought present around tomorrow very olive problem goat just
Accounts:
- Account 0:
Address: 0x9aEa7f991b78EFfFDCEA0A1a024d1B22159E2c2a
Private key: 0x5df8051fe2401ba24ff71500c0dc459accf7aeb449897b5b2d4f75e1f5914450
接下来在l1-test1
的/home/polygon/data
目录下编辑创世文件genesis.json
:
$ vi data/genesis.json
内容如下
{
"config":