Open
Description
Suggestion
It would be helpful to have more clarity/examples in the documentation regarding event subscriptions for the lesser used web socket events, for example newHeads
and newPendingTransactions
.
In v5, I would do it like so:
const provider = new WebSocketProvider(...)
provider._subscribe('newHeads', ['newHeads'], (result) => {
const block = provider.formatter.block(result)
console.log(block)
}
In v6 (currently 6.2.3), I'm able to get it working via the following:
const provider = new WebSocketProvider(...)
const sub = new SocketBlockSubscriber(provider)
sub._handleMessage = (result) => {
const block = provider._wrapBlock({ ...result, transactions: [] }, provider._network)
console.log(block)
}
provider._register('newHeads', sub)
sub.start()
Am I doing it right?
I'm not sure what the implications are, but seems like it would be convenient if we could pass custom subscriptions directly into provider.on('event', () => ...)