我用的是一台学校发的电脑(ip:),一台自己的笔记本
1.查询两台电脑的IP
学校电脑:
文章来源地址https://www.toymoban.com/news/detail-601437.html
C:\Users\admin>ipconfig
Windows IP 配置
以太网适配器 以太网 3:
连接特定的 DNS 后缀 . . . . . . . :
本地链接 IPv6 地址. . . . . . . . : fe80::ac62:352a:be4e:3d9d%17
IPv4 地址 . . . . . . . . . . . . : 192.168.235.46
子网掩码 . . . . . . . . . . . . : 255.255.255.0
默认网关. . . . . . . . . . . . . : 192.168.235.254
笔记本电脑
C:\Users\86159>ipconfig
Windows IP 配置
无线局域网适配器 本地连接* 1:
媒体状态 . . . . . . . . . . . . : 媒体已断开连接
连接特定的 DNS 后缀 . . . . . . . :
无线局域网适配器 本地连接* 2:
媒体状态 . . . . . . . . . . . . : 媒体已断开连接
连接特定的 DNS 后缀 . . . . . . . :
无线局域网适配器 WLAN:
连接特定的 DNS 后缀 . . . . . . . :
本地链接 IPv6 地址. . . . . . . . : fe80::455f:b717:f37b:3c52%18
IPv4 地址 . . . . . . . . . . . . : 10.173.40.12
子网掩码 . . . . . . . . . . . . : 255.255.252.0
默认网关. . . . . . . . . . . . . : 10.173.43.254
以太网适配器 蓝牙网络连接:
媒体状态 . . . . . . . . . . . . : 媒体已断开连接
连接特定的 DNS 后缀 . . . . . . . :
2.将两台电脑的防火墙都关掉(保证互相能够ping通)
3.两台电脑用同一个创世区块
{
"config": {
"chainId": 666,
"homesteadBlock": 0,
"eip150Block": 0,
"eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"eip155Block": 0,
"eip158Block": 0,
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"petersburgBlock": 0,
"istanbulBlock": 0,
"ethash": {}
},
"nonce": "0x0",
"timestamp": "0x5ddf8f3e",
"extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": "0x47b760",
"difficulty": "0x00002",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"alloc": { },
"number": "0x0",
"gasUsed": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}
4.下面代码分别在两台电脑都执行一遍
geth --datadir 20221050033-2 init genesis.json
geth --datadir 20221050033-2 --nodiscover --networkid 1108 --ipcdisable --port 1111 --rpc --rpcport 2222 console
INFO [11-30|15:06:00.767] Maximum peer count ETH=50 LES=0 total=50
INFO [11-30|15:06:00.804] Starting peer-to-peer node instance=Geth/v1.9.10-stable-58cf5686/windows-amd64/go1.13.6
INFO [11-30|15:06:00.806] Allocated trie memory caches clean=256.00MiB dirty=256.00MiB
INFO [11-30|15:06:00.808] Allocated cache and file handles database=C:\\geth-alltools\\privatechain\\20221050033-2\\geth\\chaindata cache=512.00MiB handles=8192
INFO [11-30|15:06:00.826] Opened ancient database database=C:\\geth-alltools\\privatechain\\20221050033-2\\geth\\chaindata\\ancient
INFO [11-30|15:06:00.828] Initialised chain configuration config="{ChainID: 666 Homestead: 0 DAO: <nil> DAOSupport: false EIP150: 0 EIP155: 0 EIP158: 0 Byzantium: 0 Constantinople: 0 Petersburg: 0 Istanbul: 0, Muir Glacier: <nil>, Engine: ethash}"
INFO [11-30|15:06:00.831] Disk storage enabled for ethash caches dir=C:\\geth-alltools\\privatechain\\20221050033-2\\geth\\ethash count=3
INFO [11-30|15:06:00.833] Disk storage enabled for ethash DAGs dir=C:\\Users\\admin\\AppData\\Local\\Ethash count=2
INFO [11-30|15:06:00.835] Initialising Ethereum protocol versions="[64 63]" network=1108 dbversion=<nil>
WARN [11-30|15:06:00.836] Upgrade blockchain database version from=<nil> to=7
INFO [11-30|15:06:00.838] Loaded most recent local header number=0 hash=d3d6bb…c5304a td=2 age=3y2w3d
INFO [11-30|15:06:00.841] Loaded most recent local full block number=0 hash=d3d6bb…c5304a td=2 age=3y2w3d
INFO [11-30|15:06:00.842] Loaded most recent local fast block number=0 hash=d3d6bb…c5304a td=2 age=3y2w3d
INFO [11-30|15:06:00.845] Regenerated local transaction journal transactions=0 accounts=0
INFO [11-30|15:06:00.851] Allocated fast sync bloom size=512.00MiB
INFO [11-30|15:06:00.853] Initialized fast sync bloom items=0 errorrate=0.000 elapsed=0s
INFO [11-30|15:06:00.862] New local node record seq=1 id=643b302852cbb280 ip=127.0.0.1 udp=0 tcp=1111
INFO [11-30|15:06:00.864] Started P2P networking self="enode://902d5ae2ac8f3707becc83050a8b4cd5e32bd82ff8c911896cbdfb875b0b83dcdb898caad6b1c7c842b079e2fdea1f0fa74cb9abda0fab5ab634a85ae7090191@127.0.0.1:1111?discport=0"
INFO [11-30|15:06:00.866] HTTP endpoint opened url=http://127.0.0.1:2222 cors= vhosts=localhost
WARN [11-30|15:06:00.912] Served eth_coinbase reqid=3 t=0s err="etherbase must be explicitly specified"
Welcome to the Geth JavaScript console!
台式电脑:
”enode://902d5ae2ac8f3707becc83050a8b4cd5e32bd82ff8c911896cbdfb875b0b83dcdb898caad6b1c7c842b079e2fdea1f0fa74cb9abda0fab5ab634a85ae7090191@127.0.0.1:1111?discport=0
“
笔记本电脑
"enode://0d1d38a234a12c4d2726c2852ecc3735acfb5da0e223251516025825dfacf7217b3dce11490716f0a29c563714f4a8ada4e550f59ce3f0e3010fcf7f4a6fc572@127.0.0.1:1111?discport=0"
记住这个节点的值
5.将节点加入私链,并查询
将笔记本节点加入台式机节点
admin.addPeer("enode://0d1d38a234a12c4d2726c2852ecc3735acfb5da0e223251516025825dfacf7217b3dce11490716f0a29c563714f4a8ada4e550f59ce3f0e3010fcf7f4a6fc572@10.173.40.12:1111?discport=0")
然后查询结果:
> admin.peers
[{
caps: ["eth/63", "eth/64"],
enode: "enode://0d1d38a234a12c4d2726c2852ecc3735acfb5da0e223251516025825dfacf7217b3dce11490716f0a29c563714f4a8ada4e550f59ce3f0e3010fcf7f4a6fc572@10.173.40.12:1111?discport=0",
id: "d61248975be06520554ecab496451b918cc0cc72755a435c294f474bf2745651",
name: "Geth/v1.9.10-stable-58cf5686/windows-amd64/go1.13.6",
network: {
inbound: false,
localAddress: "192.168.235.46:52910",
remoteAddress: "10.173.40.12:1111",
static: true,
trusted: false
},
protocols: {
eth: {
difficulty: 2,
head: "0xd3d6bb893a6e274cab241245d5df1274c58d664fbb1bfd6e59141c2e0bc5304a",
version: 64
}
}
}]
> net.peerCount
1
同理,台式机节点加入笔记本的私链
admin.addPeer("enode://902d5ae2ac8f3707becc83050a8b4cd5e32bd82ff8c911896cbdfb875b0b83dcdb898caad6b1c7c842b079e2fdea1f0fa74cb9abda0fab5ab634a85ae7090191@192.168.235.46:1111?discport=0")
true
文章来源:https://www.toymoban.com/news/detail-601437.html
到了这里,关于多个节点搭建以太坊私有链(两台电脑测试)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!