1

I am using @solana/wallet-adapter with Next js And on a particular wallet, I need the autoConnect on page load. I would've gone with window.solana.connect() but it doesn't detect when the user switches wallet

1
  • If I answered your question please mark this as answered, thank you.
    – vicyyn
    Dec 30, 2022 at 7:27

1 Answer 1

2

You have to add autoConnect in your <WalletProvider .. >

        <ConnectionProvider endpoint={endpoint}>
            <WalletProvider wallets={wallets} autoConnect>
                <WalletModalProvider>
                    <WalletMultiButton />
                    <WalletDisconnectButton />
                    { /* Your app's components go here, nested within the context providers. */ }
                </WalletModalProvider>
            </WalletProvider>
        </ConnectionProvider>
    );

https://github.com/solana-labs/wallet-adapter/blob/master/APP.md

2
  • oh but this would affect the whole site since this is in the app.js I was thinking if I could use it on individual pages. Because I need it on one page only Dec 31, 2022 at 9:51
  • you can set set autoConnect based on what page you are on. e.g. somepage ? autoConnect : None (just an abstract example)
    – vicyyn
    Dec 31, 2022 at 10:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.