alchemyplatform/alchemy-web3

web3.eth.subscribe("alchemy_fullPendingTransactions") not a valid subscription

Closed this issue · 4 comments

Hey there, Alchemy team!

Trying to use the new alchemy_fullPendingTransactions feature (#15), but it doesn't seem to be working. I get the following stack trace when attempting to subscribe to alchemy_fullPendingTransactions (the correct channel per the docs):

 Unknown subscription: alchemy_fullPendingTransactions
    at SubscriptionsFactory.getSubscription (web3-eth.umd.js:362)
    at SubscriptionsFactory.subscriptionsFactory.getSubscription (index.js:163)
    at Proxy.subscribe (web3-eth.umd.js:414)
    at useAlchemyRpcWeb3.tsx:25
    at commitHookEffectList (react-dom.development.js:22030)
    ...more unrelated react errors

Below is a snippet of code I'm using, it's a basic React hook that runs in the browser:

import { useEffect, useRef } from 'react'
import { createAlchemyWeb3 } from '@alch/alchemy-web3'
import { HTTP_ALCHEMY } from '../utils/connectors'

const useAlchemyRpcWeb3 = (alchemyUrl = HTTP_ALCHEMY) => {
  const alchemyWeb3Ref = useRef(createAlchemyWeb3(alchemyUrl))
  useEffect(() => {
    alchemyWeb3Ref.current = createAlchemyWeb3(alchemyUrl)
  }, [alchemyUrl])

  // Test hook just to see subscriptions
  useEffect(() => {
    if (!alchemyWeb3Ref.current) {
      return
    }
    let sub: any = undefined
    try {
      sub = alchemyWeb3Ref.current.eth.subscribe(
        'alchemy_fullPendingTransactions',
        {},
        (err, item) => {
          if (err) {
            console.log('alchemy_fullPendingTransactions:error', err)
            return
          }
          console.log('alchemy_fullPendingTransactions:item', item)
        },
      )
    } catch (e) {
      console.log('error setting up alchemy sub', e)
    }

    return () => {
      if (sub) {
        sub.unsubscribe()
      }
    }
  }, [alchemyWeb3Ref.current])

  return alchemyWeb3Ref.current
}

export { useAlchemyRpcWeb3 }

I've tried both the HTTP and WSS keys, just in case.

Let me know if you need a better repro, or if I'm just doing something wrong.

Thanks!

Hi @johnrjj , let me look into this for you. To start, can you tell me what version of alchemy-web3 you're on?

@dphilipson Here's a CodeSandbox with a minimal working repro: https://codesandbox.io/s/gracious-black-3l4cf - fill in your alchemy key to see it error out.

I am using the latest version (v0.1.10)

Thank you very much for the repro! I've found the problem and just published a fix in version 0.1.11.

The problem was that alchemy-web3 was incorrectly looking for the string alchemy_newFullPendingTransactions instead of alchemy_fullPendingTransactions. Even though I wrote a note in the readme about the need to watch out for this because it's confusing, I still got confused and got in wrong in my own code, which is embarrassing. Let me know if that solves the problem for you.

No worries at all, works now -- going to close this; Thanks for the quick fix! Have a good one!