What is the best way to detect account switching in Phantom Wallet? I am using Nextjs.
1 Answer
From the docs: establishing-a-connection#changing-accounts
There are different methods to detect the provider.
provider.on('accountChanged', (publicKey) => {
if (publicKey) {
// Set new public key and continue as usual
console.log(`Switched to account ${publicKey.toBase58()}`);
}
});