Detecting the Provider
To detect if a user has already installed Phantom, a web application should check for the existence of a solana object. Phantom's browser extension and mobile in-app browser will both inject a solana object into the window of any web application the user visits. The solana object is also available on window.phantom to prevent namespace collisions.
To make it easy to detect Phantom specifically, Phantom also adds an additional isPhantom flag.
1
const isPhantomInstalled = window.solana && window.solana.isPhantom
Copied!
If Phantom is not installed, we recommend you redirect your users to our website. Altogether, this may look like the following.
1
const getProvider = () => {
2
if ("solana" in window) {
3
const provider = window.solana;
4
if (provider.isPhantom) {
5
return provider;
6
}
7
}
8
window.open("https://phantom.app/", "_blank");
9
};
Copied!
Copy link