Management API Reference

Create a game in Unity

To make these instructions concrete, we have created a sample cross-app wallet called Rapidfire ID. To interact with it, you can find its SDK in the NPM package directory: @rapidfire/id.

You can check out the GitHub repository for Rapidfire Wallet to learn how to create your own wallet.

This guide will walk you through adding support for any cross-app wallet into a Unity app by integrating the Mobile Wallet Protocol.

TARGET PLATFORM VS UNITY EDITOR PLATFORM

We have added compilation flags to the Unity SDK to ensure that specific Unity editors can only build certain platform targets. Please note that the table below indicates which editor you can use to build a platform target, but it does not determine whether you can run the SDK in that editor.

For example, the SDK allows you to build iOS games using a macOS Unity Editor, but you cannot use the Windows Unity Editor.

Target PlatformWindows Unity EditormacOS Unity Editor
Windows
macOS
Android
iOS
Web

If you need a template or scaffold to start with, you can check out the Cross-app Wallet Unity Example.

Setup#

Install Mobile Wallet Protocol Client#

There are two ways to install the SDK:

  1. Open the Package Manager
  2. 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-protocol and click 'Add'

Usage#

Mobile Wallet Protocol Client provides an interface for Unity to interact with the Cross-app 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.

ClientController.cs

_56
using UnityEngine;
_56
using MobileWalletProtocol;
_56
_56
public class ClientController : MonoBehaviour
_56
{
_56
[SerializeField]
_56
MWPClientOptions m_Options = new MWPClientOptions()
_56
{
_56
Metadata = new AppMetadata()
_56
{
_56
Name = "Smart Wallet",
_56
CustomScheme = "exp://",
_56
ChainIds = new string[] { "0xaa36a7" }
_56
},
_56
Wallet = Wallet.CreateWebWallet(
_56
name: "Rapid fire wallet",
_56
// The scheme should be the target wallet's URL
_56
scheme: "https://id.sample.openfort.xyz#policy=pol_a909d815-9b6c-40b2-9f6c-e93505281137",
_56
iconUrl: "https://purple-magnificent-bat-958.mypinata.cloud/ipfs/QmfQrh2BiCzugFauYF9Weu9SFddsVh9qV82uw43cxH8UDV"
_56
)
_56
};
_56
_56
MWPClient m_Client;
_56
string m_Account;
_56
_56
void Awake()
_56
{
_56
m_Client = new MWPClient(m_Options);
_56
}
_56
_56
public async void RequestAccounts()
_56
{
_56
var result = await m_Client.EthRequestAccounts();
_56
_56
if (result.IsSuccess)
_56
{
_56
var accounts = result.Value;
_56
_56
m_Account = accounts[0];
_56
_56
foreach (var account in accounts)
_56
{
_56
Debug.Log("Account: " + account);
_56
}
_56
}
_56
else
_56
{
_56
Debug.LogError("Error: " + result.Error);
_56
}
_56
}
_56
_56
public void Disconnect()
_56
{
_56
m_Client.Reset();
_56
}
_56
}

Gas Sponsorship#

If you want to sponsor transactions, you need to add #policy=POLICY_ID to the wallet scheme.


_10
#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 cross-app wallet.