CRYPTO NEWS

Ethereum price risks a drop below $1K if these key price metrics turn bearish

Two key Ethereum price metrics have yet to turn bearish, but it won’t take much to trigger an ETH drop below $1,000.

Websocket provider reconnects every 1 minute

I’m developing an application on a private Ethereum chain and trying to listen to some events. I wrote a basic indexer script for listening to events and writing them in a database. To listen to the events I am connecting to the provider via Web3.providers.WebsocketsProvider. I realized it keeps losing the connection every minute. And::Listen

I’m developing an application on a private Ethereum chain and trying to listen to some events. I wrote a basic indexer script for listening to events and writing them in a database.

To listen to the events I am connecting to the provider via Web3.providers.WebsocketsProvider. I realized it keeps losing the connection every minute. And actually it does not disconnect, instead, it creates a new connection every minute as I don’t catch any logs from error or end events.

As a workaround, I added reconnect options introduced in web3.js v1.2.7. That’s how I noticed the regular dropping each minute.

Here’s the code:

const Web3 = require('web3'); const TruffleContract = require('@truffle/contract'); const ReviewStorageArtifact = require('./contracts/ReviewStorage.json'); const { logAddedReview } = require('./reviewLogger'); // external module where I write to database.  const providerLink = 'wss://providerLink.org';  // Enable auto reconnection const options = {   reconnect: {     auto: true,     delay: 1000, // ms     maxAttempts: 5,     onTimeout: false   } };  // Connect let provider, web3; provider = new Web3.providers.WebsocketProvider(providerLink, options); web3 = new Web3(provider);  provider.on('connect', init); provider.on('error', e => console.log('WS Error', e)); provider.on('end', e => {   console.log(e);   console.log('WS closed'); });  // Connect to instance and listen event function init() {   const ReviewStorage = TruffleContract(ReviewStorageArtifact);   ReviewStorage.setProvider(web3.currentProvider);   console.log('Trying to conntect weeb3');   ReviewStorage.deployed()     .then(instance => {       console.log('Found instance');       instance.ReviewAdded() // Listen to ReviewAdded events.         .on('data', (event) => logAddedReview(event, instance))         .on('error', console.error);     })     .catch(console.error); } 

Here’s the output how I noticed the regular reconnections. Notice there are no outputs from .on('error') or .on('end'): Output of websocket reconnection

Why could this be happening? Might it be something on the provider side? When I connect to Infura Rinkeby, for example, there are no reconnections taking place. Thanks.

Ethereum price risks a drop below $1K if these key price metrics turn bearish

Shopping cart
There are no products in the cart!
Continue shopping
0