Test using a localfork

Thanks — this is a great, clear question. Tone: you’re trying to test locally (integration/testing issue). I can help — a few possible ways to get your local fork behaving like Polygon, and I’ll note the minimal things I may need from you to give a targeted answer.

What I extracted so far

  • SDK: MetaMask Embedded Wallets (via Web3Auth)
  • Platform: next.js + wagmi (web)
  • SDK version: not provided — please share if you know it

Quick explanation and options
Because MetaMask Embedded (Web3Auth) expects chains to be configured from the Dashboard, the Embedded UI and the provider metadata will reference the RPC URL configured there. You have two practical ways to test against a local fork while keeping chainId and behavior identical to Polygon:

  1. Temporary public tunnel to your local RPC (recommended for the Dashboard flow)
  • Expose your local fork (localhost) with a tunnel like ngrok or cloudflared and set that tunneled URL as the RPC in the MetaMask Dashboard for the chain (only for your test configuration). The Dashboard will then serve that RPC to the Embedded provider, and wallets created by Web3Auth will point to your fork.
  • Pros: Matches how the Embedded wallet expects RPCs (no runtime hacks). Works for both read/write RPC calls from the Embedded provider.
  • Cons: Requires a tunnel and updating Dashboard during testing.
  1. Override the RPC used by wagmi/public client locally (useful for read operations and local test flows)
  • Keep the Dashboard chain configuration unchanged, but configure wagmi’s provider to use your local RPC for that chain (so wagmi read calls go to your local fork). For example, use wagmi’s jsonRpcProvider and configureChains to return localRPC when in dev. Example pattern:

    import { configureChains, createClient } from ‘wagmi’
    import { jsonRpcProvider } from ‘wagmi/providers/jsonRpc’

    const { chains, publicClient } = configureChains(
    [polygonWithLocal],
    [
    jsonRpcProvider({
    rpc: (chain) => ({
    http: isDev ? localRPC : chain.rpcUrls.default.http[0]
    })
    })
    ]
    )

    const client = createClient({
    autoConnect: true,
    provider: publicClient
    })

  • Pros: No Dashboard change, fast for local-only reads.

  • Cons: The Embedded provider (from Web3Auth) may still advertise/use the Dashboard RPC for some operations (chain switching, internal calls) — you’ll need to ensure components use the wagmi client’s provider where appropriate.

  1. Proxy/wrap the provider at runtime
  • Create a small JSON-RPC proxy that forwards most methods to the Dashboard-configured provider but routes chain-specific calls (eth_call, sendTransaction, etc.) to your local fork when chainId matches. This is more advanced but fully transparent to the Embedded wallet.

Which is best?

  • If you need the Embedded wallet itself to point at your fork (so dapp and wallet are consistent), use option 1 (tunnel + Dashboard change).
  • If you only need your app’s RPC reads/writes to hit your fork (and you control which provider is used), option 2 is most convenient.

A couple of notes about the new Web3AuthProvider + WagmiProvider split

  • The Dashboard controls which chains are available in the Embedded wallet UI, but you still control the provider(s) used by your wagmi client. So overriding wagmi providers works for your app-level calls. If you need the Embedded provider internal RPC to be your local RPC (so the wallet UI and provider-level calls use it), point the Dashboard RPC to a reachable URL (tunnel) or use a proxy.

What I may need from you (only if you want me to dig deeper)

  • web3AuthConfig (the object you pass into )
  • wagmi client initialization / configureChains snippet (where you set polygonWithLocal)
  • SDK/version of MetaMask Embedded / Web3Auth you’re using (if known)
  • Any console errors/screenshots if something’s failing (only if you see errors)

Relevant docs

If you want, paste your web3AuthConfig and the wagmi createClient/configureChains code and I’ll show the exact code you can drop in to route RPCs to your local fork (or give the ngrok steps for option 1).

Note: This response was generated by an AI bot and may require further verification. The MetaMask Community Team has tracked this issue and will be responding as soon as possible.

Additionally, we would recommend you to join our biweekly Office Hours to get this resolved even faster. MetaMask Developer Office Hours