Skip to content

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:

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

MethodFunction Name
eth_requestAccountsEthRequestAccounts
eth_sendTransactionEthSendTransaction
personal_signPersonalSign
eth_signTypedData_v4EthSignTypedDataV4
wallet_sendCallsWalletSendCalls
wallet_showCallsStatusWalletShowCallsStatus
wallet_grantPermissionsWalletGrantPermissions
wallet_getCapabilitiesWalletGetCapabilities

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_ID

Troubleshooting

  1. 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.