I am having file structure like this:
src/app/globals.css
src/app/layout.tsx
src/app/page.tsx
src/app/providers.tsx
src/balance.tsx
src/sendTransaction.tsx
src/switchNetwork.tsx
src/wagmi.tsx
src/writeContract.tsx
src/Web3AuthConnectorInstance.tsx
Here’s my code for wagmi.ts
import { http, cookieStorage, createConfig, createStorage } from 'wagmi'
import { mainnet, sepolia, rootstockTestnet, hederaTestnet, morphSepolia } from 'wagmi/chains'
import { coinbaseWallet, injected } from 'wagmi/connectors'
import Web3AuthConnectorInstance from "./Web3AuthConnectorInstance"
export function getConfig() {
return createConfig({
chains: [mainnet, sepolia, rootstockTestnet, hederaTestnet, morphSepolia],
connectors: [
injected(),
coinbaseWallet(),
Web3AuthConnectorInstance([mainnet, sepolia, rootstockTestnet, hederaTestnet, morphSepolia]),
],
storage: createStorage({
storage: cookieStorage,
}),
ssr: true,
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
[rootstockTestnet.id]: http(),
[hederaTestnet.id]: http(),
[morphSepolia.id]: http(),
},
})
}
declare module 'wagmi' {
interface Register {
config: ReturnType<typeof getConfig>
}
}
Here’s my code for page.tsx
'use client'
import { useAccount, useConnect, useDisconnect } from 'wagmi'
import { SendTransaction } from "../sendTransaction";
import { SwitchChain } from "../switchNetwork";
import { Balance } from "../balance";
import { WriteContract } from "../writeContract";
function App() {
const account = useAccount()
const { connector, isConnected } = useAccount();
const { connectors, connect, error } = useConnect()
const { disconnect } = useDisconnect()
if (isConnected) {
return (
<div className="main">
<div className="title">Connected to {connector?.name}</div>
<div> Addresses: {account.addresses} </div>
<div> ChainId: {account.chainId} </div>
<button className="card" onClick={disconnect as any}>
Disconnect
</button>
<SendTransaction />
<Balance />
<WriteContract />
<SwitchChain />
</div>
);
} else {
return (
<div className="main">
{connectors.map((connector) => {
return (
<button className="card" key={connector.id} onClick={() => connect({ connector })}>
{connector.name}
</button>
);
})}
{error && <div>{error.message}</div>}
</div>
);
}
}
export default App
Web3AuthConnectorInstance.tsx is same as this link attached. Examples
The issue is at src/wagmi code:
Web3AuthConnectorInstance([mainnet, sepolia, rootstockTestnet, hederaTestnet, morphSepolia]),
By command it out, it functions correctly.
Attached image is the bug happened screenshot.