Connect Directly to the ME Solana Provider

Detecting the Provider

If you've built a custom wallet connection solution and want to add support for the Magic Eden Wallet, you can directly access the Solana Provider at magicEden.solana in the Window.

A code snippet to find the provider might look like the following:

const getProvider = () => {
  // check if the magicEden object is available
  if ('magicEden' in window) {
    const magicProvider = window.magicEden?.solana;
    if (magicProvider?.isMagicEden) {
      return magicProvider;
    }
  }
  window.location.href = 'https://wallet.magiceden.io/'
};

The above will return the provider if the user has the extension installed, otherwise it'll redirect the user to the magic eden wallet website to download it.

Connecting

Once the magicEden provider object has been found, a user is able to connect their wallet to the site. The connection request will prompt the user to approve the connection, so that their wallet can be used to make requests, such as sending transactions.

The easiest way to connect to the ME wallet is by calling window.magicEden.solana.connect()

const provider = getProvider();

const handleConnect = async () => {
  try {
    await provider.connect();
  } catch (error) {
    console.error(error);
  }
};

The provider saves information like a user's pubkey once a connection has been established.

More Info

A code demo for basic ME wallet connection can be found here. A demo video can be found in the readme.

Last updated