switchNetwork without logging out

await authenticate({
        provider: "network",
        privateKey: privateKey,
        chainId: 56,
        urls: { 56: "https://rpc.ankr.com/bsc" },
});

which sets the connecter to : NetworkWeb3Connector. In the Docs switchNetwork Docs

it says switchNetwork can only be used with metamask. Only option i can think of to switch networks would be to logout and then log back in using a different network. But this would make UX bad as some of my Pages show based on the authentication state of the user?

is there another way to switch out the provider on the connector, or make a custom connector just like NetworkWeb3Connector that will be able to change the provider, and swap to a different network while maintaining the authenticated state?

Try using enableWeb3() with the same options used in your authenticate but with a different chain to see if that works.

yes that worked.

instead of using switchNetwork i used enableWeb3 and it switched my network.
thanks

1 Like