Closed JoyCood closed 1 year ago
Passing in config
to useConnect
is not correct (below). Can you create a minimal reproduction using next.wagmi.sh?
const { connect, isLoading, error, pendingConnector } = useConnect(config);
Passing in
config
touseConnect
is not correct (below). Can you create a minimal reproduction using next.wagmi.sh?const { connect, isLoading, error, pendingConnector } = useConnect(config);
you save my life, it is working now! thank you!
@tmm I'm also getting this error but I can't reproduce it. It doesn't happen everytime, I get this error randomly and it resolves autometically when I try to connect or switch network. This is how I'm creating config (Check below).
import { createConfig, configureChains, CreateConfigParameters, PublicClient, WebSocketPublicClient } from 'wagmi'
import { publicProvider } from 'wagmi/providers/public';
import { MetaMaskConnector } from 'wagmi/connectors/metaMask';
import { avalanche, bsc, mainnet, arbitrum, fantom, polygon, base, optimism} from '@wagmi/chains';
import { alchemyProvider } from 'wagmi/providers/alchemy';
import { infuraProvider } from 'wagmi/providers/infura';
import { FallbackTransport } from 'viem';
const supportedChains = [mainnet, bsc, avalanche, arbitrum, fantom, polygon, base, optimism];
const { chains, publicClient, webSocketPublicClient } = configureChains(
supportedChains,
[
infuraProvider({ apiKey: import.meta.env.VITE_INFURA_KEY }),
alchemyProvider({ apiKey: import.meta.env.VITE_ALCHEMY_KEY }),
publicProvider(),
]
);
const metaMaskConnector = new MetaMaskConnector({ chains, options: {
shimDisconnect: true
}});
const supportedConnectors = [metaMaskConnector];
// Set up wagmi config
const configParameters: CreateConfigParameters<PublicClient<FallbackTransport>, WebSocketPublicClient<FallbackTransport>> = {
autoConnect: true,
connectors: supportedConnectors,
publicClient,
webSocketPublicClient
};
const config = createConfig(configParameters);
export {
config
}
App Root Component
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import "./index.css";
import App from "./App";
import { WagmiConfig } from 'wagmi';
import { config } from './utils/walletConnector';
const rootElement = document.getElementById('root');
const root = createRoot(rootElement!);
root.render(
<StrictMode>
<WagmiConfig config={config}>
<App />
</WagmiConfig>
</StrictMode>
);
Connect Button
import styles from "./style.module.scss";
import { useConnect } from "wagmi";
const ConnectWalletButton = () => {
const { connectAsync, connectors, isLoading, pendingConnector} = useConnect({
onSuccess(data) {
console.log('Connect', data)
},
onError(error, variables) {
console.log('error', { error, variables });
if (variables.connector.id === 'metaMask') {
// log metamask connector related error
}
}
});
return (
<>
{connectors.map((connector) => {
const buttonStatus = connector.ready ? connectButtonText ?? `Connect Wallet` : (!connector.ready ? `${connector.name} (unsupported)` : (isLoading &&
connector.id === pendingConnector?.id) ? `Connecting to ${connector.name}` : '')
return (
<Button
isDisabled={!connector.ready}
key={connector.id}
text={buttonStatus}
isLoading={isLoading}
onClickHandler={() => connectAsync({ connector })}
/>
)
})}
</>
);
};
export default ConnectWalletButton;
This issue has been locked since it has been closed for more than 14 days.
If you found a concrete bug or regression related to it, please open a new bug report with a reproduction against the latest wagmi version. If you have any other comments you can create a new discussion.
package.json:
Originally posted by @youthinn in https://github.com/wagmi-dev/wagmi/issues/838#issuecomment-1544314707