Hi, I’m trying to figure out how the websockets are working.
First, there is some confusion on the correct URL. According to OP its wss://<network>.infura.io/ws/v3/<your-project-id>.
According to https://infura.io/docs/ethereum/wss/faq, it’s wss://<network>.infura.io/ws
What is correct?
Second, I’m trying this snippet:
I tried ‘newBlockHeaders’ and also ‘pendingTransactions’ just incase and both are working great against wss://mainnet.infura.io/ws/v3/<your+project+id>
Note that you only get blockHeader when a there’s a new block so the subscription function will not necessary immediately return a new block.
as a sanity check, I use wscat to create a ‘newHeads’ subscription. Anytime you get a new block from the newHeads subscription, you should get a console output for new block header.
Here’s how to create newheads subscription using wscat, just incase: