connectkit: [BUG] ConnectKit failing requests to Alchemy even though I am using Infura

Describe the bug

I am using ConnectKit with Infura and until recently my website was working fine but now it fails to connect with a bunch of errors to Alchemy in the console.

To reproduce

I am using the following code to connect with ConnectKit:

import {
  WagmiConfig,
  createClient,
  useContractRead,
  chain } from "wagmi";
import { ConnectKitProvider, getDefaultClient } from "connectkit";

const contractConfig = {
  addressOrName: contractAddress,
  contractInterface: abiFile,
};

const client = createClient(
  getDefaultClient({
    appName: "Chublins",
    infuraId: process.env.INFURA_ID,
    chains: [chain.mainnet]
  }),
);

You can see the full source code of my website here: https://github.com/Montoya/chublins-website/tree/master

The page that used to work fine but now fails is here: https://chublins.com/view

Expected behavior

The view page should load without issues and allow you to enter an ID to view.

Screenshots

Screen Shot 2022-10-29 at 6 07 50 PM

Environment details

Latest Google Chrome on MacOS

Additional context

Like I said, this was working fine and then stopped working a couple weeks ago without any code changes.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (6 by maintainers)

Commits related to this issue

Most upvoted comments

Left a big writeup on fixes, debugging and reasons for this issue over in https://github.com/family/connectkit/issues/33#issuecomment-1308935780

@Montoya You can check your clients provider configurations by using the useProvider hook and looking at the providerConfigs array to see what configured providers are going to be used. But you can’t see which one is currently being targeted.

I’ve talked with the people over at wagmi about it and there isn’t an easy way to check which provider is currently being targeted due to a limitation with the ethers library. If you feel the need to have this available you can always raise a discussion in the wagmi repo and see where things go from there.

I hope this helps resolve everything! I’m going to close this issue now but if anyone else is still having problems feel free to open your own tickets. 😄

From what I’ve discovered, Alchemy’s API endpoint has started timing out earlier than the Provider’s default stallTimeout, which then falls back to wagmi’s publicProvider (which also uses Alchemy) which is severely rate limited.

To allow for some temporary fixes we’ve now introduced a stallTimeout parameter to our getDefaultClient helper in ConnectKit version 1.0.0.

Update to the latest version of ConnectKit and try something similar to the below, hopefully that will help resolve some issues:

import { WagmiConfig, createClient } from "wagmi";
import { ConnectKitProvider, ConnectKitButton, getDefaultClient } from "connectkit";

const alchemyId = process.env.ALCHEMY_ID;

const client = createClient(
  getDefaultClient({
    appName: "Your App Name",
    alchemyId,
    stallTimeout:5000
  }),
);

const App = () => {
  return (
    <WagmiConfig client={client}>
      <ConnectKitProvider>
        /* Your App */
      </ConnectKitProvider>
    </WagmiConfig>
  );
};