Detecting the Provider
The Phantom browser extension will inject an object calledsolana on the window object of any web application the user visits. The solana object is also available on window.phantom to prevent namespace collisions.
To detect if a browser extension using this API is installed, you can check for the existence of the solana object.
To make it easy to detect Phantom specifically, the extension 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!
Last modified 2mo ago
Copy link