Integrate a global wallet in Unity
This guide will walk you through adding support for any global wallet into a Unity app by integrating the Mobile Wallet Protocol.
Setup
Install Mobile Wallet Protocol Client
There are two ways to install the SDK:
- Open the Package Manager
- Click the add + button and select "Add package from git URL..."
Enter https://github.com/openfort-xyz/mobile-wallet-protocol-unity-client.git?path=com.openfort.mobile-wallet-protocoland click 'Add'
- Open your project's Packages/manifest.json file
- Add com.openfort.mobile-wallet-protocol:https://github.com/openfort-xyz/mobile-wallet-protocol-unity-client.git?path=com.openfort.mobile-wallet-protocolin the dependencies block
Usage
Mobile Wallet Protocol Client provides an interface for Unity to interact with the Global Wallet, an EIP-1193 compliant provider interface.
The EIP-1193 provider implements a method called request that accepts an object with the following fields:
- method: the name of a JSON-RPC request to send to the wallet
- params: any parameters to include with the request
Methods
| Method | Function Name | 
|---|---|
| eth_requestAccounts | EthRequestAccounts | 
| eth_sendTransaction | EthSendTransaction | 
| personal_sign | PersonalSign | 
| eth_signTypedData_v4 | EthSignTypedDataV4 | 
| wallet_sendCalls | WalletSendCalls | 
| wallet_showCallsStatus | WalletShowCallsStatus | 
| wallet_grantPermissions | WalletGrantPermissions | 
| wallet_getCapabilities | WalletGetCapabilities | 
EIP-1193 Provider
Create a new EIP1193Provider instance, which is EIP-1193 compliant.
using UnityEngine;
using MobileWalletProtocol;
 
public class ClientController : MonoBehaviour
{
    [SerializeField]
    MWPClientOptions m_Options = new MWPClientOptions()
    {
        Metadata = new AppMetadata()
        {
            Name = "Smart Wallet",
            CustomScheme = "exp://",
            ChainIds = new string[] { "0xaa36a7" }
        },
        Wallet = Wallet.CreateWebWallet(
            name: "Rapid fire wallet",
            // The scheme should be the target wallet's URL
            scheme: "https://id.sample.openfort.io#policy=pol_a909d815-9b6c-40b2-9f6c-e93505281137",
            iconUrl: "https://purple-magnificent-bat-958.mypinata.cloud/ipfs/QmfQrh2BiCzugFauYF9Weu9SFddsVh9qV82uw43cxH8UDV"
        )
    };
 
    MWPClient m_Client;
    string m_Account;
 
    void Awake()
    {
        m_Client = new MWPClient(m_Options);
    }
 
    public async void RequestAccounts()
    {
        var result = await m_Client.EthRequestAccounts();
 
        if (result.IsSuccess)
        {
            var accounts = result.Value;
 
            m_Account = accounts[0];
 
            foreach (var account in accounts)
            {
                Debug.Log("Account: " + account);
            }
        }
        else
        {
            Debug.LogError("Error: " + result.Error);
        }
    }
 
    public void Disconnect()
    {
        m_Client.Reset();
    }
}Gas Sponsorship
If you want to sponsor transactions, you need to add #policy=POLICY_ID to the wallet scheme.
#policy=POLICY_IDTroubleshooting
- If no network appears in your wallet transaction request, make sure you:
- Have the correct chain ID in the metadata
- That chain is supported by your global wallet.