Created
June 23, 2022 16:52
-
-
Save ErbaZZ/c3bacdc46c48c563fee44f38e85b44b0 to your computer and use it in GitHub Desktop.
WSS and HTTPS RPC Connection Tester
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Web3 = require('web3'); | |
const RPC_LIST = [ | |
"wss://bsc-ws-node.nariox.org:443", | |
"https://rpc.ankr.com/eth", | |
] | |
async function main() { | |
for (const rpcUrl of RPC_LIST) { | |
let provider; | |
if (rpcUrl.startsWith("wss://")) { | |
provider = new Web3.providers.WebsocketProvider(rpcUrl, { | |
reconnect: { | |
auto: true, | |
delay: 5000, | |
maxAttempts: 3 | |
} | |
}); | |
} else if (rpcUrl.startsWith("https://")) { | |
provider = new Web3.providers.HttpProvider(rpcUrl); | |
} else return; | |
const web3 = new Web3(provider); | |
web3.eth.getBlockNumber().then(async (blockNumber) => { | |
console.log(rpcUrl + ' is usable: ' + blockNumber); | |
}) | |
} | |
} | |
main().then(async () => { | |
// do nothing | |
}).catch((err) => { | |
process.exit(1); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment