4

I'm currently writing some program to monitor the mempool of a bsc node. As my BSC node is a charged by request count, I'm trying to explore the best way to save the time and cost.

Here's some plan I found:

  1. Use service of mempool explorer. https://www.blocknative.com/. This is obviously not the best plan since I've already paid 99 dollar on quicknode service already and I found some transactions is still not among the list it provided.

  2. User web3py pending filter: new_transaction_filter = w3.eth.filter('pending') new_transaction_filter.get_new_entries() and w3.eth.get_transaction(entry) for each entry. This is also not effcient because it's quite time wasting and cost lots of web3 requests.

  3. Using pending_block = w3.eth.get_block(block_identifier='pending', full_transactions=True) The call only returns transactions with mined block number and obviously not the 'pending' ones.

  4. Use w3.geth.txpool.content(). This can print out all the pending transactions in one shot but when you keep calling it, duplicated record will appears.

Can anyone give me a hint which is the correct way to fetch the mempool?

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

3 Answers3

3

I think option 2 is best, I've been trying to see if theres a way to apply only a specific address to the filter but I've had not luck with that, I've tried option 3 which is too late and option 4 only works on a geth node (I've only been using speedynode so not the best).

James
  • 101
  • 2
  • 10
  • Yes, you are right. I've tried 3 but it only give me the mined block. 2 is the fastest way but will consume lots of gettransaction call(100+ per second) and I need to filter it by my own. 4 is very slow coz everycall will return 3mb+ data and I have to process and remove duplicated ones and also it causes a noticealbe lantency. BTW, what's the difference between speedynode and Geth node? – Yu Wan Jan 26 '22 at 04:44
  • Speedynode is a free node so it’s no use for option 2, a geth node is a lot faster so will work with option 2 – James Feb 25 '22 at 20:53
0

Subscribing to pending transactions with the websockets library may be better than option 2 since it would just listen and receive the hashes in real time rather than using new_transaction_filter.get_new_entries() in a loop. However, I don't believe public nodes will be fast enough to receive them before the block gets mined. Check out this link. It also works with bsc: https://docs.infura.io/infura/tutorials/ethereum/subscribe-to-pending-transactions

0

I think you should use websocket or Webhook connection to a mempool node , then you can set up filters on the node to only receive PancakeSwap V3 txs for example, and avoid straining resources and minimise latency on your side, the BSC Mempool Node from https://mempoolnode.com has been pretty good for that and cheaper than the options mentioned

  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/34526994) – Alez Jun 15 '23 at 07:58