Rabby icon indicating copy to clipboard operation
Rabby copied to clipboard

Wagmi: 'connection.connector.getProvider is not a function'

Open 0xbid opened this issue 1 year ago • 1 comments

With some sites that use Wagmi hooks, the calls to hook will fail with connection.connector.getProvider is not a function', only while using Rabby wallet.

Describe the bug

Periodically, all functions from hooks (e.g. connect, writeContract / writeContractAsync) fails with connection.connector.getProvider is not a function.

Refreshing page fixes it.

It only occurs with Rabby wallet, Metamask stays connected always and does not run into the issue.

Link to Minimal Reproducible Example

No response

Steps To Reproduce

Nextjs 13+ SSR configured

wagmiConfig.ts

export const wagmiConfig = createConfig({
    // Setup chains
    chains: chains,
    transports: {
        [mainnet.id]: http(),
        [goerli.id]: http(),
        [sepolia.id]: http(),
        [holesky.id]: http()
    },

    // Enable SSR support (needs cookies)
    ssr: true,
    storage: createStorage({
        storage: cookieStorage
    }),

    connectors: [injected()]
});

Web3Provider.tsx

'use client';

// ...

const queryClient = new QueryClient();

const Web3Provider = ({
    children,
    initialState
}: {
    children: React.ReactNode;
    initialState: State;
}) => {
    return (
        <>
            <WagmiProvider config={wagmiConfig} initialState={initialState}>
                <QueryClientProvider client={queryClient}> {children}</QueryClientProvider>
            </WagmiProvider>
        </>
    );
};

layout.tsx

// ...
const initialState = cookieToInitialState(wagmiConfig, headers().get('cookie'));
This may also be relevant: I do not use any 3rd party connector (e.g. ConnectKit, Web3Modal, etc). I just do a simple:

'use client';

// ...

       const { connectors, connect } = useConnect();

        if (!isWalletConnected) {
            try {
                connect({ connector: connectors[0] });
            } catch (e) {
               // ...
            }
        }

Wagmi Version

2.3.1

Viem Version

2.4.0

TypeScript Version

10.9.1

Check existing issues

Anything else?

I think it would be really helpful to know more about how connection.connector.getProvider could occur from a dev perspective, e.g. what is going on. Then we can narrow down why it doesn't work with Rabby.

0xbid avatar Feb 12 '24 01:02 0xbid

Looks like issue with wagmi, can you check with wagmi team first?

vvvvvv1vvvvvv avatar Feb 15 '24 04:02 vvvvvv1vvvvvv