I have add new chain to current web3auth and call function to switch chain. After I switched chain, I call web3.provider to get new provider of switched chain. The web3.provider not updated for me to refresh the provider
SDK Version: @web3auth /no-modal": "^7.3.1,
Platform: Nextjs
add and switch chain
web3auth?.provider // return chainId 0x5
const newChain = {
chainId: "0x1",
rpcTarget: "https://rpc.ankr.com/eth",
displayName: "Ethereum Mainnet",
blockExplorer: "https://goerli.etherscan.io",
ticker: "ETH",
tickerName: "Ethereum",
chainNamespace: CHAIN_NAMESPACES.EIP155,
};
await web3auth?.addChain(newChain);
await web3auth?.switchChain({ chainId: "0x1" });
after switch chain, I get the provider and it doesn’t updated the provider with new chainId for me
web3auth?.provider // still response chainId 0x5
vjgee
March 4, 2024, 7:17am
2
@phuochungdn1999 Welcome Aboard!
The switchchain issue is fixed in latest V8 and Wagmi v6 version.
You may refer to this thread for the usage(if required):
Are you adding the chain first using addChain() that you need to switch to using switchChain() ? It is working for me. Please see the functions below:
If you want to use Wagmi to switch chains, you can utilize NetworkSwitcher function below:
I am connecting to Web3Auth with Google account. I am using this to change the network
const { pendingChainId, switchNetwork, status } = useSwitchNetwork();
switchNetwork(chainId);
but the chain not change after the switchChain success
const { chain } = useNetwork(); // this is not updated to the chain called in the switchchain
version I use
"viem": "^1.16.6",
"wagmi": "^1.4.5"
"@web3auth/no-modal": "^7.3.1",
TomTom
March 6, 2024, 1:06pm
4
hi @phuochungdn1999 ,
Please update to version v8 of no-modal.
Check our last example: