Skip to content

[BUG] Internal useEnsFallbackConfig causes Wagmi storage pollution and inconsistent chain state #479

@myxtype

Description

@myxtype

Issue Description

When using ConnectKit, we discovered a problem of Wagmi storage pollution, which leads to inconsistent chain states. Specifically:

  • Multiple Wagmi storage keys appear in the app (e.g., wagmi.store and a custom storage key)
  • After a user manually switches the chain, it reverts to the default chain (Ethereum mainnet) upon reloading the page
  • Chain state appears inconsistent across different components

Root Cause

After debugging, we found that the issue originates from the internal useEnsFallbackConfig hook inside ConnectKit (located at packages/connectkit/src/hooks/useEnsFallbackConfig.ts).

The relevant code:

import { http, createConfig } from 'wagmi';
import { mainnet } from 'wagmi/chains';

const ensFallbackConfig = createConfig({
  chains: [mainnet],
  transports: {
    [mainnet.id]: http(),
  },
});

export function useEnsFallbackConfig(): Config | undefined {
  return !useChainIsSupported(1) ? ensFallbackConfig : undefined;
}

This internal configuration:

  • Creates a separate Wagmi instance, even when the app already provides a custom Wagmi configuration
  • Uses the default storage key, resulting in the coexistence of wagmi.store and the custom storage key
  • Interferes with chain state management — when this fallback config is activated, it can override the user’s manually selected chain

Steps to Reproduce

  1. Configure ConnectKit and Wagmi, setting a custom storage key and default chain (e.g., BSC chain with ID 56).

  2. Manually connect a wallet and switch to the BSC chain.

  3. Refresh or reopen the app.

  4. Observe the behavior: the app reconnects to Ethereum mainnet (chain ID 1).

  5. Check localStorage:

    • wagmi.store contains chain ID 1
    • Custom storage key contains chain ID 56

Expected Behavior

  • The app should use the user-provided Wagmi configuration and storage settings.
  • Chain state should remain consistent and unaffected by any internal fallback config.
  • The user’s manual chain selection should be correctly persisted across sessions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions