#StackBounty: #go-ethereum #web3js #events #websocket Healtcheck on Websocket

Bounty: 50

I’ve looked through the documentation and haven’t found that to be helpful.

I would like to know the best way to do a healthcheck on my websocket connection to geth (Yesterday, I found out that I did not receive the new event from a few days ago without any reason).

I have a solution but it is not likely the best practice approach.

const web3 = new Web3(new Web3.providers.WebsocketProvider(networkUri));

setInterval(() => {
  console.log('Check WS status');
  let subscription;
  new Promise((resolve, reject) => {
    subscription = web3.eth.subscribe('pendingTransactions')
      .on('data', function () {
        return resolve(true);
      .on('error', function () {
        return reject(false);
    .then(() => {
    .catch(() => {
    .finally(() => {
      // unsubscribes the subscription
      subscription.unsubscribe(function (error, success) {
        if (success)
          console.log('Successfully unsubscribed!');
}, 30000);


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.