> For the complete documentation index, see [llms.txt](https://docs.metaproprotocol.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.metaproprotocol.com/metapro-protocol/unity-plugin/reference/web3-connection-providers/metamask.md).

# MetaMask

* MetaMask - MetaMaskProviderController.cs &&#x20;

MetaMaskConnectionListener.csMetaMaskProviderController class manages requests for connection with QR code personal sign to MetaMask wallet.&#x20;

MetaMaskConnectionListener class listens to MetaMask plugin responses and based on them calls an action.

```
using System;
using System.Collections;
using System.Threading.Tasks;
using MetaMask.Models;
using MetaMask.Unity;
using metaproSDK.Scripts.Serialization;
using metaproSDK.Scripts.Utils;
using UnityEngine;

namespace metaproSDK.Scripts.Controllers
{
    public class MetaMaskProviderController : ProviderController
    {
        private bool _disconnected = false;
        public override void Initialize()
        {
            MetaMaskUnity.Instance.Initialize();
            MetaMaskUnity.Instance.Wallet.WalletAuthorized += OnWalletConnected;
            MetaMaskUnity.Instance.Wallet.WalletDisconnected += OnWalletDisconnected;
        }

        private void OnDestroy()
        {
            MetaMaskUnity.Instance.Wallet.WalletAuthorized -= OnWalletConnected;
            MetaMaskUnity.Instance.Wallet.WalletDisconnected -= OnWalletDisconnected;
        }

        private void OnWalletConnected(object sender, EventArgs e)
        {
            PluginManager.Instance.OnWalletConnected();
        }

        private void OnWalletDisconnected(object sender, EventArgs e)
        {
            _disconnected = true;
            PluginManager.Instance.DisconnectWallet();
        }

        public override void ShowConnection()
        {
            MetaMaskUnity.Instance.Wallet.Connect();
        }

        public override void RequestSign()
        {
            StartCoroutine(SignLogin());
        }

        private IEnumerator SignLogin()
        {
            yield return new WaitForSeconds(1f);
            var wallet = MetaMaskUnity.Instance.Wallet.SelectedAddress.ToLower();

            var hash = "";
            yield return  StartCoroutine(MetaproServerRequests.GetHashss(wallet, value => hash = value));
            
            var verifyMessage = $"Please sign to let us verify\nthat you are the owner of this address\n{wallet}\n\nRequest ID {hash}";
            
            var paramsArray = new[] { wallet, verifyMessage };

            var request = new MetaMaskEthereumRequest
            {
                Method = "personal_sign",
                Parameters = paramsArray
            };
            
            var task = Task.Run(async () => await MetaMaskUnity.Instance.Wallet.Request(request));
            yield return new WaitUntil(() => task.IsCompleted);
            var loginSignature = task.Result;

            var userData = new UserData();
            yield return StartCoroutine(MetaproServerRequests.LoginWallet(wallet, loginSignature.ToString(), hash, value => userData = value));

            PluginManager.Instance.SetupUserData(userData);
        }

        public override void DisconnectWallet()
        {
            if (_disconnected == false)
            {
                MetaMaskUnity.Instance.Wallet.Disconnect();
            }
            Destroy(gameObject, 1f);
        }
    }
    
}




using System;
using MetaMask.Models;
using MetaMask.Transports.Unity;
using metaproSDK.Scripts.Utils;
using UnityEngine;

namespace metaproSDK.Scripts.Controllers.ConnectionListeners
{
    public class MetaMaskConnectionListener : MonoBehaviour, IMetaMaskUnityTransportListener
    {
        public void OnMetaMaskConnectRequest(string url)
        {
            var qrCodeSprite = QRCodeImamgeHandler.GenerateQRCode(url);
            PluginManager.Instance.ShowQRCodeScreen(qrCodeSprite);
        }

        public void OnMetaMaskRequest(string id, MetaMaskEthereumRequest request)
        {
        }

        public void OnMetaMaskFailure(Exception error)
        {
        }

        public void OnMetaMaskSuccess()
        {
        }
    }
}

```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.metaproprotocol.com/metapro-protocol/unity-plugin/reference/web3-connection-providers/metamask.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
