Developers Forum for XinFin XDC Network

Bobby Jonas
Bobby Jonas

Posted on

Issues subscribing to newBlockHeaders event using web3 npm module

I'm having issues subscribing to newBlockHeaders event using web3 npm module.

Here's some basic code I'm running,


const web3 = new Web3(new Web3.providers.WebsocketProvider('wss://ws.xinfin.network'));
 web3.eth.subscribe('newBlockHeaders', (error, result) => {
    if (error) {
      console.error(error);
    } else {
      console.log(result);
    }
  });
Enter fullscreen mode Exit fullscreen mode

Then I get this error in the console. Using ReactJS btw:

dex.js:262 Uncaught Error: Given address "xdc0000000000000000000000000000000000000000" is not a valid Ethereum address.
    at Object.toChecksumAddress (index.js:262:1)
    at Object.outputBlockFormatter [as outputFormatter] (formatters.js:283:1)
    at push../node_modules/web3-core-subscriptions/lib/subscription.js.Subscription._formatOutput (subscription.js:102:1)
    at subscription.js:235:1
    at Array.forEach (<anonymous>)
    at Object.callback (subscription.js:234:1)
    at WebsocketProvider.data (index.js:99:1)
    at WebsocketProvider.emit (index.js:181:1)
    at index.js:104:1
    at Array.forEach (<anonymous>)
    at push../node_modules/web3-providers-ws/lib/index.js.WebsocketProvider._onMessage (index.js:102:1)
t
Enter fullscreen mode Exit fullscreen mode

Tried with both web3 module version 1.5.2 and 1.6.1

Discussion (3)

Collapse
rupps_blocksscan profile image
Rupali Mestry

Hello @bobby_jonas_cfc8fb6699f6c
Since we haven’t received any response from your side , we are closing the issue as it appears to be resolved. If you still have the issue, please feel free to reopen it.
Thank you!

Collapse
mitali_blocksscan profile image
Mitali_BlocksScan

Hello @bobby_jonas_cfc8fb6699f6c
We hope that the above issue is resolved, if the issue still persists then please let us know about it so that the team can resolve it on priority. It will be grateful to get an update within 72 hours or else it will be considered resolved.
Thank You.

Collapse
mitali_blocksscan profile image
Mitali_BlocksScan

Hey @bobby_jonas_cfc8fb6699f6c,
Please, try with this web socket wss://ews.xinfin.network. and let me know if you still have any issue.