Web3
March 31, 2025
硬件:一块容量够大的硬盘或 RAID(至少 4 T)
系统:macOS, Windows, Linux 均可
网络环境:国内宽带即可
Geth
+ Lighthouse
Geth
作为执行层,Lighthouse
作为共识层
组一个 2t 的 RAID,挂载至 /mnt/raid
创建数据文件夹
sudo mkdir /mnt/raid/ethereum-data
sudo mkdir /mnt/raid/lighthouse-data
openssl rand -hex 32 | tr -d "\n" > /mnt/raid/ethereum/execution/jwtsecret
Geth
geth --mainnet --http --http.api eth,net,engine,admin --ipcpath=/mnt/raid/ethereum/execution/geth.ipc --datadir /mnt/raid/ethereum/execution --syncmode "snap"
geth --mainnet --datadir /mnt/raid/ethereum/execution --http --ipcpath /mnt/raid/ethereum/execution/geth.ipc
geth --datadir /mnt/raid/ethereum/execution \
--syncmode "snap" \
--http \
--http.addr "0.0.0.0" \
--http.port 8545 \
--http.api "eth,net,web3" \
--authrpc.addr "127.0.0.1" \
--authrpc.port 8551 \
--authrpc.jwtsecret /mnt/raid/ethereum/execution/jwtsecret \
--cache 12288 \
--maxpeers 100 \
--history.transactions 0
Lighthouse
lighthouse beacon --network mainnet \
--datadir /mnt/lv-2t/lighthouse-data \
--checkpoint-sync-url https://mainnet-checkpoint-sync.stakely.io \
--execution-endpoint http://127.0.0.1:8551 \
--execution-jwt /mnt/lv-2t/ethereum-data/jwtsecret \
--port 7000 \
--discovery-port 7002
lighthouse beacon --network mainnet \
--datadir /mnt/lv-2t/lighthouse-data \
--checkpoint-sync-url https://sync.invis.tools \
--execution-endpoint http://127.0.0.1:8551 \
--execution-jwt /mnt/lv-2t/ethereum-data/jwtsecret \
--port 7000 \
--discovery-port 7002
Erigon
相比于 Geth
+ Lighthouse
的方式,Erigon
自带了 Beacon,不要安装额外的共识层。并且,Erigon
对于数据有很大的压缩,存储空间显著降低。
Clone Erigon
Repo
git clone --branch main --single-branch https://github.com/erigontech/erigon.git
Build the Erigon
make erigon
Launch the Erigon
./build/bin/erigon --config ./config.toml
config.toml
"prune.mode" = "archive"
datadir = '/Volumes/Disk/data-archive'
chain = "mainnet"
http = true
"http.addr"="0.0.0.0"
"http.api" = ["eth","debug","net","web3","trace","txpool"]
"torrent.download.rate" = "512mb"
/Volumes/Disk/data-archive
是我存放数据的目录
Erigon
在下载完数据后,支持直接通过 rpcdaemon
开启 JSON-RPC 服务
make rpcdaemon
rpcdaemon
文档 https://github.com/erigontech/erigon/blob/main/cmd/rpcdaemon/README.md
./build/bin/rpcdaemon --datadir=<your_data_dir> --txpool.api.addr=localhost:9090 --private.api.addr=localhost:9090 --http.api=eth,erigon,web3,net,debug,trace,txpool
./build/bin/rpcdaemon --datadir=/Volumes/Disk/data-archive --txpool.api.addr=localhost:9090 --private.api.addr=localhost:9090 --http.api=eth,erigon,web3,net,debug,trace,txpool
curl --location --request GET 'http://localhost:8545/health' \
--header 'X-ERIGON-HEALTHCHECK: min_peer_count1' \
--header 'X-ERIGON-HEALTHCHECK: synced' \
--header 'X-ERIGON-HEALTHCHECK: max_seconds_behind600'
curl -X POST \
-H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"eth_syncing","params":[],"id":1}' \
http://127.0.0.1:8545
curl -X POST \
-H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"eth_syncing","params":[],"id":1}' \
http://192.168.2.11:8545
geth attach /mnt/lv-2t/ethereum-data/geth.ipc
eth.syncing