connectkit: [BUG] connectkit (wagmi) is spamming alchemy

Screen Shot 2022-10-23 at 01 09 24

connectkit is sending so many requests to alchemy that it sometimes exceeds concurrent requests limit. You can easily recreate this by going into https://docs.family.co/connectkit/try-it-out and clicking connect, and going in and out of modals several times.

{"jsonrpc":"2.0","id":42,"error":{"code":429,"message":"Your app has exceeded its concurrent requests capacity. If you have retries enabled, you can safely ignore this message. If not, check out https://docs.alchemyapi.io/documentation/rate-limits. Reach out to us if you'd like to increase your limits: https://dashboard.alchemyapi.io/support"}}

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 19 (4 by maintainers)

Commits related to this issue

Most upvoted comments

I seem to have found a fix, I’m still not quite sure what caused this bug though.

In the configureChains hook, explicitly type your apikey in. - I was previously using my .env variable, but for some reason this fixed the spamming of api calls. - when it theory it should be the same… Hope this works for some of you, like it did for me.

If you are using NextJS, try naming your env variables as for example NEXT_PUBLIC_ALCHEMY_ID instead of just ALCHEMY_ID.

Hey everyone, I have some answers that will hopefully provide some help:

Solutions

  • Ensure your environment variables match your frameworks requirements (e.g Next.js requires the NEXT_PUBLIC_ prefix, while create-react-app requires the REACT_APP_ prefix), you can test by console.loging out your env variables to double check that it’s being returned correctly.
  • If you are unsure about your env variables setup, or are still having issues, feel free to supply your API key directly into the client configuration instead of env vars, as these variables are client-side anyway and the env var setup is more of a suggestion based on developer standards.
  • Check you have whitelisted your domains within Infura/Alchemy’s dashboards (don’t forget localhost!)

Why the 429 error

If your Infura/Alchemy key has not been passed through to the WagmiClient (or our getDefaultClient) correctly then wagmi will fall back to an Alchemy provider that uses a shared public API key, in which has been severly rate limited (the 429 error).

For reference, the shared API key for wagmi 0.6.x and below is _gg7wSSi0KMBsdKnGVfHDueq6xMB9EkC and can be found in the wagmi codebase here (which you also can see in the error logs that are returning a 429 error).

If you have updated to wagmi 0.7.x you may have noticed the 429 errors going away. The reason behind this is because this version of wagmi uses a different fallback API key, which although is also rate limited, not as many projects are using this version of wagmi – so at this point in time the new public wagmi key succeeds more often than the older version.

Why the spamming

When Alchemy fails to receive data (i.e the 429 error) it has an auto-retry method baked into it. This auto-retry pings the API a few times a second until it receives data, which explains the spamming. A valid API key supplied to the client configuration will stop this issue.

Further debugging

You can check your apps client configurations by using the useProvider hook and looking at the providerConfigs array to see what configured providers are available.

CleanShot 2022-11-10 at 02 27 27@2x

If you don’t see your provider and API key in here then there may be a different issue with your client configuration. Feel free to open a ticket if this occurs.

I hope this helps resolve everyones issues. There’s also some conversations relating to this issue in https://github.com/family/connectkit/issues/36 if anyone else wants some further reading.

Same here unfortunately. ConnectKit 1.0, have stallTimeout, NEXT_PUBLIC_ALCHEMY_ID. Let me know if need anything else for testing, 🙏

hi @jterskine doing this configuration

const { provider, webSocketProvider } = configureChains(
  supportedChain,
  [
    infuraProvider({ apiKey: infuraId, stallTimeout: 1_000, priority: 0 }),
    alchemyProvider({ apiKey: alchemyId, stallTimeout: 1_000, priority: 1 }),
    publicProvider({ priority: 2 })
  ]
)

Having same issue, even with NEXT_PUBLIC_ALCHEMY_ID

I had the same issue with Next.js + wagmi + RainbowKit after updating packages to latest versions. Despite providing my own apiKey via process.env.NEXT_PUBLIC_ and explicitly, alchemyProvider kept falling back to default public apiKey. The fix was to revert back a few versions on wagmi to 0.5.0 and RainbowKit to 0.4.0

Closing this issue as we believe this isn’t an issue with ConnectKit, but rather how Alchemy handles fallbacks.

If you are having issues please read this comment to help resolve potential setup issues. If you are still having issues feel free to open a new ticket with an reproducible example to help us debug.

I’m having the same issue. Using wagmi and clicking and Alchemy and having same error