-
Notifications
You must be signed in to change notification settings - Fork 1
/
chains_rpc_validate.js
30 lines (29 loc) · 1.12 KB
/
chains_rpc_validate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const { ethers } = require('ethers')
const { readFile } = require('fs/promises')
async function main() {
const chains_rpc = JSON.parse(await readFile('chains_rpc.json', 'utf-8'))
for (const chain of Object.keys(chains_rpc)) {
console.log(`CHAIN: ${chain}`)
let chainId
for (const rpc of chains_rpc[chain]) {
console.log(rpc)
let currentChainId
try {
const provider = new ethers.providers.JsonRpcProvider({
url: rpc,
timeout: 5000
})
currentChainId = (await provider.getNetwork()).chainId
chainId ??= currentChainId
console.log(`chainId ${chainId}, currentChainId ${currentChainId}`)
} catch(e) {
console.log(`not active`)
continue;
}
if (chainId != currentChainId) throw `chain: ${chain}, chainId: ${chainId}, currentChainId: ${currentChainId}, rpc: ${rpc}`
}
if(chainId === undefined) throw `not has active rpc. chain ${chain}`
console.log(`\n`)
}
}
main()