# \[Archive\] Not able to switch chain using wagmi useSwitchNetwork() hook

**URL:** <https://builder.metamask.io/t/archive-not-able-to-switch-chain-using-wagmi-useswitchnetwork-hook/1601>\
**Category:** Embedded Wallets (Web3Auth)\
**Created:** [January 18, 2024, 1:46pm UTC](https://builder.metamask.io/t/archive-not-able-to-switch-chain-using-wagmi-useswitchnetwork-hook/1601 "2024-01-18T13:46:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dev19](https://avatars.discourse-cdn.com/v4/letter/d/90ced4/32.png) [@dev19](https://builder.metamask.io/u/dev19)\
**Post date:** [January 18, 2024, 1:46pm UTC](https://builder.metamask.io/t/archive-not-able-to-switch-chain-using-wagmi-useswitchnetwork-hook/1601/1 "2024-01-18T13:46:52Z")

</div>

> **🏛 Archived Content from Web3Auth Community**
> 
> This topic was originally posted by **dev19** on 1/18/2024.  
> This content has been migrated from our previous community forum to preserve valuable discussions.

* * *

Not able to switch chain using wagmi useSwitchNetwork() hook.  
When we click on button to change the chain sucess function gets called and we dont get any error but still chain didn’t get switched. As asked I have all the dependencies. web3auth init, instance as well as wagmi provider, login code, component we are using to switch chain and screenshot of browser console.

Note\*\* - we have removed @ from web3auth dependencies because we were not able to create this post.

Package.json - these are dependencies

> dependencies":{  
> “newrelic/next”:“^0.7.0”,  
> “parifi/references”:“0.2.2”,  
> “pythnetwork/pyth-evm-js”:“^1.29.2”,  
> “safe-global/relay-kit”:“^1.3.0”,  
> “toruslabs/eccrypto”:“^4.0.0”,  
> “types/js-cookie”:“^3.0.6”,  
> “web3auth/base”:“^7.1.0”,  
> “web3auth/ethereum-provider”:“^7.1.2”,  
> “web3auth/no-modal”:“^7.1.2”,  
> “web3auth/openlogin-adapter”:“^7.1.2”,  
> “web3auth/web3auth-wagmi-connector”:“^5.0.1”,  
> “newrelic”:“^11.5.0”,  
> “next”:“^14.0.3”,  
> “pino”:“^8.16.2”,  
> “react”:“^18.2.0”,  
> “swr”:“^2.2.4”,  
> “viem”:“^1.19.6”,  
> “wagmi”:“^1.4.13”  
> },  
> “devDependencies”:{  
> “@safe-global/safe-core-sdk-types”:“^2.3.0”,  
> “@types/node”:“^20.9.4”,  
> “@types/react”:“^18.2.38”,  
> “typescript”:“^5.3.2”  
> }

Wagmi and web3auth config and instance

> const USED\_CHAINS= [arbitrumSepolia,arbitrumGoerli]  
> const{ chains,publicClient }= configureChains(USED\_CHAINS, [  
> publicProvider(),  
> alchemyProvider({ apiKey: process.env.NEXT\_PUBLIC\_ALCHEMY\_API\_KEY|| ‘’ }),  
> ]);  
> // Create Web3Auth Instance  
> constchainConfig ={  
> chainNamespace:CHAIN\_NAMESPACES.EIP155,  
> chainId:‘0x’+ chains[0].id.toString(16),  
> rpcTarget: chains[0].rpcUrls.default.http[0],  
> displayName: chains[0].name,  
> tickerName: chains[0].nativeCurrency.name,  
> ticker: chains[0].nativeCurrency.symbol,  
> blockExplorer: chains[0].blockExplorers?.default.url || ‘’,  
> };  
> constoptions:Web3AuthNoModalOptions ={  
> clientId: process.env.NEXT\_PUBLIC\_WEB3\_AUTH\_CLIENT\_ID|| ‘’,  
> chainConfig,  
> web3AuthNetwork:OPENLOGIN\_NETWORK.CYAN,  
> };  
> constweb3AuthInstance =new Web3AuthNoModal(options);  
> // Add openlogin adapter for customisations  
> constprivateKeyProvider =new EthereumPrivateKeyProvider({  
> config:{ chainConfig },  
> });  
> constopenloginAdapterInstance =new OpenloginAdapter({  
> privateKeyProvider,  
> adapterSettings:{  
> network:OPENLOGIN\_NETWORK.CYAN,  
> uxMode:‘redirect’,  
> redirectUrl:  
> process.env.NEXT\_PUBLIC\_WEB3\_AUTH\_REDIRECT\_URL||  
> ‘[https://test-ui-dev.parifi.org/](https://test-ui-dev.parifi.org/)’,//Web3Auth Redirect URL after user sucessfully connect wallet  
> sessionTime:259200, // 3 days (6060243) in seconds\*  
> whiteLabel:{  
> appName:‘Parifi’,  
> appUrl:‘[https://parifi.org](https://parifi.org)’,  
> defaultLanguage:‘en’,// en, de, ja, ko, zh, es, fr, pt, nl  
> theme:{  
> primary:‘#ea633e’,  
> },  
> },  
> },  
> });  
> web3AuthInstance.configureAdapter(openloginAdapterInstance);  
> typeLoginProvider = (typeof LOGIN\_PROVIDER)[keyoftypeof LOGIN\_PROVIDER];  
> exportfunction getWeb3AuthConnector(  
> loginProvider:LoginProvider,  
> hint?:string,  
> ){  
> returnnew Web3AuthConnector({  
> chains: chains,  
> options:{  
> web3AuthInstance,  
> loginParams:{  
> loginProvider: loginProvider,  
> extraLoginOptions:{  
> login\_hint: hint,  
> },  
> },  
> },  
> });  
> }  
> constprojectId =‘be96f3154a4bbc8744b43d4f9d956088’;  
> exportconst coinbaseConnector= newCoinbaseWalletConnector({  
> chains,  
> options:{  
> appName:‘Parifi’,  
> },  
> });  
> exportconst injectedConnector= newInjectedConnector({  
> chains,  
> });  
> exportconst walletConnectConnector= newWalletConnectConnector({  
> chains,  
> options:{ projectId },  
> });  
> constwagmiConfig =createConfig({  
> autoConnect:true,  
> connectors: [  
> injectedConnector,  
> walletConnectConnector,  
> coinbaseConnector,  
> …Object.values(LOGIN\_PROVIDER)  
> .filter(  
> (provider)=\>  
> provider !== ‘email\_passwordless’&& provider !==‘sms\_passwordless’,  
> )  
> .map((provider)=\> getWeb3AuthConnector(provider)),  
> ],  
> publicClient,  
> });  
> exportdefault functionWagmiProvider({children }:{ children:ReactNode }){  
> return\<WagmiConfigconfig={wagmiConfig}\>{children};  
> }

**login code**

> const { connect }= useConnect({  
> onSuccess:(data)=\> {  
> Cookies.set(‘login’,‘true’);  
> Cookies.set(‘chainId’,String(data.chain.id))  
> if (!data.chain.unsupported)  
> router.push(/${chainNameById[data.chain.id]}/perpetuals?market=ETH);  
> },  
> });  
> [//router.push](https://router.push) is not working in onSucess, cookies get set but router.push doesnt work.  
> constgeneralConnector =({  
> connector,  
> loginProvider,  
> }:{  
> connector:Connector\<any,any\>;  
> loginProvider:string;  
> }) =\> {  
> if (!isClientSide()) return;  
> logger.info(‘generalConnector’,{ connector, loginProvider });  
> returnconnect({ connector: connector });  
> };

generalConnector({ connector:getWeb3AuthConnector('google'), loginProvider:'google', }) } {icons.google\_icon}

**SwitchChainComponent -**

> import{ useNetwork,useSwitchNetwork } from’wagmi’  
> constSwitchChain =() =\> {  
> const{ chain }= useNetwork()  
> const{ chains,error,pendingChainId,switchNetwork,status } =  
> useSwitchNetwork({  
> onSuccess:(data)=\> {  
> console.log(“inside onSucess”)  
> console.log(data)  
> }  
> })  
> return (

{chain && 
Using {chain.name}
} {chains.map((x)=\> ( { console.log(switching to ${x.id}) switchNetwork?.(x.id)}} Switch to {x.name} {status === 'loading'&& x.id === pendingChainId &&'…'}

))}

{error && (error?.message ?? 'Failed to switch')}

) } export default SwitchChain

[![Untitled](https://canada1.discourse-cdn.com/flex011/uploads/metamaskbuilderhub/original/1X/b726351db33ff3a9a82fa4195b7fedb784f18124.png)
Untitled693×726 73.4 KB
](https://web3auth.io/community/uploads/default/original/2X/8/858b808434245d11029170882d260cedb3bf4bd5.png "Untitled")

---

<div class="post-metadata">

**Author:** ![vjgee](https://avatars.discourse-cdn.com/v4/letter/v/b5e925/32.png) [@vjgee](https://builder.metamask.io/u/vjgee)\
**Post date:** [January 19, 2024, 4:58am UTC](https://builder.metamask.io/t/archive-not-able-to-switch-chain-using-wagmi-useswitchnetwork-hook/1601/2 "2024-01-19T04:58:19Z")

</div>

@dev19 Welcome Aboard!

Could you please have a look at this [How to switchChain() using Wagmi connectors?](https://web3auth.io/community/t/how-to-switchchain-using-wagmi-connectors/6488) if it solves your issue.

---

<div class="post-metadata">

**Author:** ![dev19](https://avatars.discourse-cdn.com/v4/letter/d/90ced4/32.png) [@dev19](https://builder.metamask.io/u/dev19)\
**Post date:** [January 23, 2024, 3:32am UTC](https://builder.metamask.io/t/archive-not-able-to-switch-chain-using-wagmi-useswitchnetwork-hook/1601/3 "2024-01-23T03:32:11Z")

</div>

Hii @vjgee thanks for response,  
We have already tried these things.  
Also tried add chain and web3auth.switchChain() this also show same behaviour, we dont get any error but chain also didn’t get switched.

---

<div class="post-metadata">

**Author:** ![vjgee](https://avatars.discourse-cdn.com/v4/letter/v/b5e925/32.png) [@vjgee](https://builder.metamask.io/u/vjgee)\
**Post date:** [January 28, 2024, 7:13am UTC](https://builder.metamask.io/t/archive-not-able-to-switch-chain-using-wagmi-useswitchnetwork-hook/1601/4 "2024-01-28T07:13:01Z")

</div>

Your issue is being reviewed by our Dev team and we will get back with updates.

---

<div class="post-metadata">

**Author:** ![vjgee](https://avatars.discourse-cdn.com/v4/letter/v/b5e925/32.png) [@vjgee](https://builder.metamask.io/u/vjgee)\
**Post date:** [February 27, 2024, 3:08am UTC](https://builder.metamask.io/t/archive-not-able-to-switch-chain-using-wagmi-useswitchnetwork-hook/1601/5 "2024-02-27T03:08:16Z")

</div>

@dev19 Thanks for your continued patience.

Our team updated that this issue with Wagmi is fixed on the latest version of [Wagmi](https://www.npmjs.com/package/@web3auth/web3auth-wagmi-connector) and the latest SDK version for [no-modal](https://www.npmjs.com/package/@web3auth/no-modal)

You may refer to our migration guide for more details:

 ![](https://canada1.discourse-cdn.com/flex011/uploads/metamaskbuilderhub/original/1X/4bea15d5fdfd372b2e7fae21263c61fab3da9379.png)

```
  <a href="https://web3auth.io/docs/pnp/migration-guides/no-modal-v7-to-v8" target="_blank" rel="noopener">web3auth.io</a>

```

### [PnP No Modal SDK - v7 to v8 | Documentation | Web3Auth](https://web3auth.io/docs/pnp/migration-guides/no-modal-v7-to-v8)

PnP No Modal SDK - v6 to v7 | Documentation - Web3Auth
