'How to connect binance network in nodejs using web3

I tried to connect with binance testnet in Nodejs. This is my code.

const Web3 = require('web3');
const web3 = new Web3(new Web3.providers.HttpProvider('https://data-seed-prebsc-1-s2.binance.org:8545'));

But I got the error code like

Error: The current provider doesn't support subscriptions: HttpProvider
    at Timeout._onTimeout (E:\test\share1\node_modules\web3-core-subscriptions\lib\subscription.js:176:24)

Please let me know how I can fix it.



Solution 1:[1]

The above web3 part works fine. Please try the below lines,

var Web3 = require('web3');
const web3_bsc = new Web3('https://data-seed-prebsc-1-s2.binance.org:8545');

Then using the web3_bsc, access the functions in your contract or perform any functions that web3 supports.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Eduard