Back to All

How do I close a WebSocket opened with the SDK?

After receiving a pendingTransaction's notification through the AlchemySubscription.PENDING_TRANSACTIONS method I open another WebSocket that listens for that transaction to be mined so that I can remove it from the pending transactions list. However, it continues to fire each time it is mined and I was wondering how I would close this WebSocket so that it stops once I clear it from the array of pending transactions.

Here is an example of the WebSocket that I am using.

alchemy.ws.on(
    txnHash,
    (tx) => console.log(tx)
)