Detecting the Provider

Phantom's browser extension and mobile in-app browser will both inject a phantom object into the window of any web application the user visits, provided that site is using https://, on localhost, or is 127.0.0.1. Phantom will not inject the provider into iframes or sites using http://.

If a phantom object exists, Bitcoin & Ordinals dApps can interact with Phantom via the API found at window.phantom.bitcoin. To detect if Phantom is installed, an application should check for an additional isPhantom flag like so:

const isPhantomInstalled = window?.phantom?.bitcoin?.isPhantom

If Phantom is not installed, we recommend you redirect your users to our website. Altogether, this may look like the following:

const getProvider = () => {
  if ('phantom' in window) {
    const anyWindow: any = window;
    const provider = anyWindow.phantom?.bitcoin;
   
    if (provider && provider.isPhantom) {
      return provider;
    }
  }

  window.open('https://phantom.app/', '_blank');
};

When adding a Phantom button to your dApp’s wallet modal, we recommend using the name β€œPhantom” with an SVG/PNG icon which can be found here.

Last updated