yuyasugano / pancake-bakery-arbitrage

A sample application invokes a flashswap in PancakeSwap and a monitoring tool in Node.js.
305 stars 194 forks source link

What is the newBlockHeaders subscription for? #11

Closed bart closed 2 years ago

bart commented 2 years ago

Hey, great work and an awesome post you wrote about this topic. Thanks a lot, appreciate it. While looking through your code I saw the subscription on newBlockHeaders event. What is this subscription actually for? Is it just used as a trigger for price monitoring? As far as I can see I could also be replaced by a simple while(true){} loop that sleeps for a couple of seconds every loop, correct? Or do I miss something here?

yuyasugano commented 2 years ago

@bart Please go through web3 documentation. You will find what types you can subscribe for. Here's the link for newBlockHeaders. Thanks. https://web3js.readthedocs.io/en/v1.2.11/web3-eth-subscribe.html#subscribe-newblockheaders