搭建私有网络
编译节点程序
git clone git@github.com:zhangxueliang1218/polygon-edge.git
cd polygon-edge/
make build
# 或者
go build -o polygon-edge main.go
# 注意:需要使用go1.17版本,否则编译时会出错。 例如:go1.17.11.linux-amd64.tar.gz
版本信息如下:
[root@VM-24-3-centos polygon-edge]# ./polygon-edge version
[VERSION INFO]
Release version = v0.5.1
Git branch = release/0.5.1
Commit hash = e17a9495d2aab73628336bd81224e0e3d05e480e
Build time = Fri May 26 15:45:26 CST 2023
[root@VM-24-3-centos polygon-edge]#
初始化节点信息
[root@VM-24-3-centos polygon-edge]# ./polygon-edge secrets init --data-dir ./node1
[SECRETS INIT]
Public key (address) = 0xDD90a9c0231cA026eE5567D51547F99f227b6c78
BLS Public key = 0xa37abc993680813cdcfd5ebe3bc3f1563db1352a8405710c7cab0844774617608418b846806518d976d4e055c255b819
Node ID = 16Uiu2HAmS3sXA3URD8J37dpCrfWJwMJHZ6btVG6v589YxxSchrMp
[root@VM-24-3-centos polygon-edge]# ./polygon-edge secrets init --data-dir ./node2
[SECRETS INIT]
Public key (address) = 0x6ac314AbEf58c5B3C813AB233d2197E5919Bd298
BLS Public key = 0x908595e68db799946eb6b69d55a0b3f3132beedd81b79ac89de913c03e31a73e2de863d634227a25e4488cc1363553c4
Node ID = 16Uiu2HAm1YtRQqGaJU7vss2ZWtzg2KCwv44VG3NYYBNjVgURERK4
[root@VM-24-3-centos polygon-edge]# ./polygon-edge secrets init --data-dir ./node3
[SECRETS INIT]
Public key (address) = 0xB7E6a7d9CBF3a4Dc0C6723723A9fB0dEEAbaE95C
BLS Public key = 0x919a5e92ae0c2c6ab345701cfaf484194fd6375a3fb220283e321bdfcd249e71b6f5009647718c0b54d9907c367f4282
Node ID = 16Uiu2HAm1nPwYsMYxCZ3Pq7MV5sVCHuEvfpdNwhjXHth1YK2u2Ld
[root@VM-24-3-centos polygon-edge]# ./polygon-edge secrets init --data-dir ./node4
[SECRETS INIT]
Public key (address) = 0xF1D69F3b0B1373D657DEf6337e45806bC455532d
BLS Public key = 0x89268e18c2e00e994663ee0d922643c7235d9cd2607f1cf215dc3d02f6af11b40c6408639628e75bf36127949fed8ad9
Node ID = 16Uiu2HAmLNu237JPFX8Xo8xUzZ4pk5nup6BLTop4UhrECWb5SoZi
[root@VM-24-3-centos polygon-edge]#
目录结构如下:
[root@VM-24-3-centos polygon-edge]# tree
.
├── node1
│ ├── consensus
│ │ ├── validator-bls.key
│ │ └── validator.key
│ └── libp2p
│ └── libp2p.key
├── node2
│ ├── consensus
│ │ ├── validator-bls.key
│ │ └── validator.key
│ └── libp2p
│ └── libp2p.key
├── node3
│ ├── consensus
│ │ ├── validator-bls.key
│ │ └── validator.key
│ └── libp2p
│ └── libp2p.key
├── node4
│ ├── consensus
│ │ ├── validator-bls.key
│ │ └── validator.key
│ └── libp2p
│ └── libp2p.key
└── polygon-edge
12 directories, 13 files
生成创世文件
注:采用ibft共识
./polygon-edge genesis --consensus ibft --chain-id 1218 --ibft-validators-prefix-path node --bootnode /ip4/127.0.0.1/tcp/10001/p2p/16Uiu2HAmS3sXA3URD8J37dpCrfWJwMJHZ6btVG6v589YxxSchrMp --bootnode /ip4/127.0.0.1/tcp/20001/p2p/16Uiu2HAm1YtRQqGaJU7vss2ZWtzg2KCwv44VG3NYYBNjVgURERK4 --bootnode /ip4/127.0.0.1/tcp/30001/p2p/16Uiu2HAm1nPwYsMYxCZ3Pq7MV5sVCHuEvfpdNwhjXHth1YK2u2Ld --bootnode /ip4/127.0.0.1/tcp/40001/p2p/16Uiu2HAmLNu237JPFX8Xo8xUzZ4pk5nup6BLTop4UhrECWb5SoZi --premine 0xBC1F42383f9567B43C219200D83C71CF144C1146:6666666666666000000000000000000
示例如下:
[root@VM-24-3-centos polygon-edge]# ./polygon-edge genesis --consensus ibft --chain-id 1218 --ibft-validators-prefix-path node --bootnode /ip4/127.0.0.1/tcp/10001/p2p/16Uiu2HAmS3sXA3URD8J37dpCrfWJwMJHZ6btVG6v589YxxSchrMp --bootnode /ip4/127.0.0.1/tcp/20001/p2p/16Uiu2HAm1YtRQqGaJU7vss2ZWtzg2KCwv44VG3NYYBNjVgURERK4 --bootnode /ip4/127.0.0.1/tcp/30001/p2p/16Uiu2HAm1nPwYsMYxCZ3Pq7MV5sVCHuEvfpdNwhjXHth1YK2u2Ld --bootnode /ip4/127.0.0.1/tcp/40001/p2p/16Uiu2HAmLNu237JPFX8Xo8xUzZ4pk5nup6BLTop4UhrECWb5SoZi --premine 0xBC1F42383f9567B43C219200D83C71CF144C1146:6666666666666000000000000000000
[GENESIS SUCCESS]
Genesis written to ./genesis.json
[root@VM-24-3-centos polygon-edge]# cat genesis.json
{
"name": "polygon-edge",
"genesis": {
"nonce": "0x0000000000000000",
"timestamp": "0x0",
"extraData": "0x0000000000000000000000000000000000000000000000000000000000000000f90127f90120f84694dd90a9c0231ca026ee5567d51547f99f227b6c78b0a37abc993680813cdcfd5ebe3bc3f1563db1352a8405710c7cab0844774617608418b846806518d976d4e055c255b819f846946ac314abef58c5b3c813ab233d2197e5919bd298b0908595e68db799946eb6b69d55a0b3f3132beedd81b79ac89de913c03e31a73e2de863d634227a25e4488cc1363553c4f84694b7e6a7d9cbf3a4dc0c6723723a9fb0deeabae95cb0919a5e92ae0c2c6ab345701cfaf484194fd6375a3fb220283e321bdfcd249e71b6f5009647718c0b54d9907c367f4282f84694f1d69f3b0b1373d657def6337e45806bc455532db089268e18c2e00e994663ee0d922643c7235d9cd2607f1cf215dc3d02f6af11b40c6408639628e75bf36127949fed8ad980c28080",
"gasLimit": "0x500000",
"difficulty": "0x1",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"alloc": {
"0xBC1F42383f9567B43C219200D83C71CF144C1146": {
"balance": "0x5425296ac1cc75b84c90680000"
}
},
"number": "0x0",
"gasUsed": "0x70000",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
},
"params": {
"forks": {
"homestead": 0,
"byzantium": 0,
"constantinople": 0,
"petersburg": 0,
"istanbul": 0,
"EIP150": 0,
"EIP158": 0,
"EIP155": 0
},
"chainID": 1218,
"engine": {
"ibft": {
"epochSize": 100000,
"type": "PoA",
"validator_type": "bls"
}
},
"blockGasTarget": 0
},
"bootnodes": [
"/ip4/127.0.0.1/tcp/10001/p2p/16Uiu2HAmS3sXA3URD8J37dpCrfWJwMJHZ6btVG6v589YxxSchrMp",
"/ip4/127.0.0.1/tcp/20001/p2p/16Uiu2HAm1YtRQqGaJU7vss2ZWtzg2KCwv44VG3NYYBNjVgURERK4",
"/ip4/127.0.0.1/tcp/30001/p2p/16Uiu2HAm1nPwYsMYxCZ3Pq7MV5sVCHuEvfpdNwhjXHth1YK2u2Ld",
"/ip4/127.0.0.1/tcp/40001/p2p/16Uiu2HAmLNu237JPFX8Xo8xUzZ4pk5nup6BLTop4UhrECWb5SoZi"
]
}[root@VM-24-3-centos polygon-edge]#
启动节点
node1
./polygon-edge server --data-dir ./node1 --chain ./genesis.json --grpc 0.0.0.0:10000 --libp2p 0.0.0.0:10001 --jsonrpc 0.0.0.0:10002 --seal
node2
./polygon-edge server --data-dir ./node2 --chain ./genesis.json --grpc 0.0.0.0:20000 --libp2p 0.0.0.0:20001 --jsonrpc 0.0.0.0:20002 --seal
node3
./polygon-edge server --data-dir ./node3 --chain ./genesis.json --grpc 0.0.0.0:30000 --libp2p 0.0.0.0:30001 --jsonrpc 0.0.0.0:30002 --seal
node4
./polygon-edge server --data-dir ./node4 --chain ./genesis.json --grpc 0.0.0.0:40000 --libp2p 0.0.0.0:40001 --jsonrpc 0.0.0.0:40002 --seal
获取区块高度
[root@VM-24-3-centos polygon-edge]# curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":["latest", true],"id":1}' http://127.0.0.1:10002
{"jsonrpc":"2.0","id":1,"result":"0x2e"}
curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"eth_getBalance","params":["0xBC1F42383f9567B43C219200D83C71CF144C1146", "latest"],"id":1}' http://127.0.0.1:10002
合约调用
curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_call","params":[{"from":"0xBC1F42383f9567B43C219200D83C71CF144C1146","to":"0x7c4063D66506051117d00B0c62b8d8343364CF68","data":"0x2e64cec1"}],"id":1}' http://127.0.0.1:20002
网友评论