1

When calling window.solana.request() in a function, in some browsers phantom opens and I can validate the transaction, and on some browsers nothing happen.

window.solana.connect() works properly and opens phantom, even on browsers where request() doesn't work.

Does anyone knows why is this behaviour happening?

Thank you

1 Answer 1

1

I can't really guess why, I think it might have to do with browser compatibility but try out this code, I believe it might work for you.

const getProvider = async () => {
    if ("solana" in window) {
      await window.solana.connect(); // opens wallet to connect to

      const provider = window.solana;
      if (provider.isPhantom) {
        console.log("Is Phantom installed?  ", provider.isPhantom);
        return provider;
      }
    } else {
      document.write('Install https://www.phantom.app/');
    }
};

window.onload = () => {

    getProvider().then(provider => {
        console.log('key', provider.publicKey.toString())
    })
    .catch(function(error){
        console.log(error)
    });

}

from the original post https://stackoverflow.com/questions/68989348/solana-adding-sollet-phantom-wallet-connect-to-my-website-steps

1
  • i understand you code, but connect() works properly, only request() doesn't work on some browsers.
    – 2095377
    Commented Dec 13, 2022 at 12:02

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.