My node.js script is able to successfully connect to the Web3 provider when both the private key (using truffle-privatekey-provider
) and the provider host URL are correct.
let privateKey = ...,
providerUrl = ...
const provider = new PrivateKeyProvider(privateKey, providerUrl)
const web3 = new Web3(provider)
try {
await web3.eth.net.isListening();
} catch (e) {
console.log('Error connecting to provider')
}
console.log('Connected!');
Problem: However when the provider host URL is incorrect, the above code does not throw any errors and simply gets stuck in the await
statement.
Is there a way to know when there is an issue connecting to the provider host?
setTimeout
together withweb3.eth.net.isListening()
? Cant seem to figure out the code – Nyxynyx Nov 2 '18 at 21:33