0

I use latest Web3 version (1.6.1) code in Node.js as provided in docs. But when I run:

var Web3 = require('web3');
var web3 = new Web3( new Web3.providers.WebsocketProvider('wss://dex.binance.org/api/ws'));
web3.onopen = function (evt) {
    console.log('WS opened');
}

it never connects. When I try plain WS:

var WebSocket= require('ws');
var WS = new WebSocket('wss://dex.binance.org/api/ws');
WS.onopen = function (evt) {
    console.log('WS opened');
}

It works. What is the issue and how to make Web3 to work with WebSockets.


(note, I've tried this but neither those codes work, and I dont want to use 2years old version package which was "working")

1 Answer 1

1

All available end-point rpc url are here https://docs.binance.org/smart-chain/developer/rpc.html. HttpProvider works well. For Websocket run your own BSC Full node or Light Node.

3
  • Thanks for answer. yeah, i was searching for Websocket. Can you point me any good tutorial for running Light Node (i dont even know about them).
    – T.Todua
    Nov 30, 2021 at 17:07
  • docs.binance.org/light-client.html use this tutorial for light node, only websocket provider lets you get pending transactions Nov 30, 2021 at 19:49
  • Saman, many thanks to you ! I've awarded & upvoted the answer. I've successfully connected WS and now getting pending transactions. But my last question, as I am getting tons of new transactions: how to specifically check pending transaction in my token's pool? i.e. wbnb/mycoin (contract address 0x123456....). I've also achieved getting transactions from txpool (example here) but it's polling version.
    – T.Todua
    Nov 30, 2021 at 20:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.