# Connect Directly to the ME EVM 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 EVM Provider at `magicEden.ethereum` in the Window.

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

```javascript
const getProvider = () => {
  // check if the magicEden object is available
  if ('magicEden' in window) {
    const magicProvider = window.magicEden?.ethereum;
    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.

{% hint style="info" %}
**Note:**

An actual production implementation to detect the provider might want to make use of timeout + some sort of loop to give the provider object time to inject in the window.
{% endhint %}

## 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 and signing messages.

The default way to prompt a connection with a user's ME wallet is with the `window.ethereum.request` function and passing in the `eth_requestAccounts` method.

```typescript
const connect = async () => {
  if (!provider) return;
  try {
    const accounts = await provider.request({ method: "eth_requestAccounts" });
    console.log(accounts[0]);
    // 0x6aDdF38602487b7a159D926bc08151eBaEEF2B70
    
    // do some logic here to update your app context with the connected account	
  } catch (err) {
      console.error(err);
  }
};
```

The `eth_requestAccounts` method will return a Promise that resolves into an array where the connected address is at the 0th index.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs-wallet.magiceden.io/evm/connect-directly-to-the-me-evm-provider.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
