Connect to Ronin Wallet using Unity AppKit
Overview
This tutorial shows how to connect your Unity-based game to the Ronin Wallet mobile app and browser extension using Reown AppKit. By the end of this tutorial, your app can connect with Ronin Wallet, enabling you to make requests to the wallet.
Prerequisites
- Unity 2022.3 or above
- IL2CPP code stripping level in Unity set to Minimal (or lower)
Steps
Step 1. Get Reown project ID
To use Reown AppKit, you need a Reown project ID. Follow these steps:
- Visit cloud.reown.com.
- Sign up for a Reown account or sign in if you already have an account.
- Create a new project or use an existing one.
- Locate and copy the project ID.
Step 2. Install dependencies
Via OpenUPM
To install packages via OpenUPM, you need to have Node.js and openupm-cli installed. Once you have them installed, you can run the following command:
openupm add com.reown.appkit.unity
Manually
You can install packages manually by following the steps described here.
Step 3. Initialize AppKit
- Add
Reown AppKit
prefab fromPackages/Reown.AppKit.Unity/Prefabs
to your scene. - Initialize AppKit from your script
public async void Start()
{
// Create AppKit config object
var config = new AppKitConfig
{
// Project ID from https://cloud.reown.com/
projectId = "YOUR REOWN PROJECT ID",
metadata = new Metadata(
name: "My Game",
description: "Short description",
url: "https://example.com",
iconUrl: "https://example.com/logo.png"
),
// Optional. Can be used to show only specific wallets in AppKit UI
// Wallet IDs can be found at: https://walletguide.walletconnect.network
includedWalletIds = new[]
{
// Ronin Wallet
"541d5dcd4ede02f3afaf75bf8e3e4c4f1fb09edb5fa6c4377ebf31c2785d9adf",
// MetaMask
"c57ca95b47569778a828d19178114f4db188b89b763c899ba0be274e97267d96",
// Trust
"4622a2b2d6af1c9844944291e5e7351a6aa24cd7b23099efac1b2fd875da31a0"
},
supportedChains = new[]
{
ChainConstants.Chains.Ronin,
ChainConstants.Chains.RoninSaigon,
}
};
// Initialize AppKit with config
await AppKit.InitializeAsync(config);
}
- Connect account
public async void Start()
{
// ...
await ResumeSession();
}
public async Task ResumeSession()
{
// Try to resume account connection from the last session
var resumed = await AppKit.ConnectorController.TryResumeSessionAsync();
if (resumed)
{
// Continue to the game
MyAccountConnectedHandler();
}
else
{
// Connect account
AppKit.AccountConnected += (_, e) => MyAccountConnectedHandler();
AppKit.OpenModal();
return;
// On mobile and desktop, you can also connect directly to Ronin Wallet
await AppKit.ConnectAsync("541d5dcd4ede02f3afaf75bf8e3e4c4f1fb09edb5fa6c4377ebf31c2785d9adf");
}
}
- Send signature request
To test the integration, we can send a
personal_sign
request to the wallet and verify the signature.
private async Task SignMessage()
{
const string message = "Hello, Ronin!";
// Sign a message with connected wallet.
// Wallet returns a message signature that we can use to verify user's address
var messageSignature = await AppKit.Evm.SignMessageAsync(message);
var connectedAccount = await AppKit.GetAccountAsync();
var verifyMessageParams = new VerifyMessageSignatureParams
{
Address = connectedAccount.Address,
Message = message,
Signature = messageSignature
};
var isSignatureValid = await AppKit.Evm.VerifyMessageSignatureAsync(verifyMessageParams);
if (isSignatureValid)
{
Debug.Log($"Message signature is valid.");
}
else
{
Debug.LogError($"Message signature is invalid.");
}
}
Additional Resources
- Official AppKit Unity Docs - find usage examples, list of actions, UI customization guide and more
- If something is missing or not working feel free to open an issue in Reown repository
- A sample Unity project that follows this guide; more official samples from Reown can be found here