2

I'm recently trying to monitor transactions of a contract address on BSC chain for my dex limit order and I finally found a stable solution to monitor the log event -- 'using web sockect connection'.

bsc = "wss://ws-nd-112-055-480.p2pify.com/xxxxxxxxxxxxxxxxxxx"
web3 = Web3(Web3.WebsocketProvider(bsc))
poolAdd = '0x0eD7e52944161450477ee417DE9Cd3a859b14fD0'
block_filter = web3.eth.filter({'fromBlock': 'latest', 'address': poolAdd, 'topics': [sha128Dic['swap']]})
while 1:
    log_new(block_filter)
    time.sleep(1)

However, I tried to change some websokect endpoint provider among below list, there's still some huge time delay of the swap event log. Some of those happens nearly one hour ago.

wss://bsc-ws-node.nariox.org:443

Moralis: https://moralis.io/speedy-nodes/

ANKR: https://app.ankr.com/api

Chainstack: https://chainstack.com/build-better-with-binance-smart-chain/

When I switch back to http provider like: Web3.HTTPProvider('https://bsc-dataseed.binance.org/'). the event log is nearly in time but some 'filter not found exception will be found during the time elapse'.

Here's the note written on BSC websocket introduction: 'You can make eth_getLogs requests with up to a 5K block range. If you need to pull logs frequently, we recommend using WebSockets to push new logs to you when they are available.'

Can anyone help out to find a better way to get a timely websocket endpoint?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Yu Wan
  • 63
  • 2
  • 5

2 Answers2

1

Run your own node for minimizing the latency.

If you cannot do that, open your purse and browse the list of commercial node providers.

Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
0

to optimize the latency you need to run your own node which needs a very powerfull dedicated server or you can get a private node from fastlynode

OUBADI Ahmed
  • 132
  • 2
  • 4
  • Thanks for your reply, fastly node gives me a very nice solution at acceptable price. May I know which VPS should I use for connecting to fastly node? Seems that it's server location is in finland and the lantency is relatively large(0.2s) comparing to default public BSC https node(0.01s) on my AWS VPS HK. AWS Stockholm can lower down the lantency at 0.1s but still not good enough. – Yu Wan Jan 26 '22 at 04:49
  • Can I have your recommendation on server renting for creating my own BSC node at what's the monthly cost for that? – Yu Wan Jan 26 '22 at 04:52
  • 1
    i use their wss link to connect to the blockchain and it's way more performante than the public rpc, to run your own bsc node, you will need a server that has more than 4tb nvme and a ram with 64 or more, wich will cost you about 300$ to 400$ monthly plus you need to maintain the node when it's size get bigger – OUBADI Ahmed Jan 27 '22 at 19:48