Skip to content

Instantly share code, notes, and snippets.

@ErbaZZ
Created June 23, 2022 16:52
Show Gist options
  • Save ErbaZZ/c3bacdc46c48c563fee44f38e85b44b0 to your computer and use it in GitHub Desktop.
Save ErbaZZ/c3bacdc46c48c563fee44f38e85b44b0 to your computer and use it in GitHub Desktop.
WSS and HTTPS RPC Connection Tester
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