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.
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 Platform | Windows Unity Editor | macOS 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:
- 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-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 walletparams
: 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.
Gas Sponsorship#
If you want to sponsor transactions, you need to add #policy=POLICY_ID
to the wallet scheme.
_10#policy=POLICY_ID
Troubleshooting#
- 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.