-
Notifications
You must be signed in to change notification settings - Fork 3
Connect Maiar
This section is a step-by-step guide to connect a MultiversX wallet to a Unity app using the Maiar app.
- Open Settings Sindow
Setup is done using the built in Settings Window. Access it using:
Tools -> MultiversX Unity Tools -> Settings Window
- Setup app display properties inside Maiar
From the Settings Window you can configure the display properties inside Maiar:
This is the view from the Maiar login prompt:
- Setup Network Configuration
The first step is to select the network API to use using select button.
Devnet, Testnet and Mainnet are built in, but a custom API can also be added and used.
For each API any number of endpoints can be added. The ones from the image are required for these tools to work properly and are already configured.
From all Endpoint Names an enum will be created to be easily accessible inside the scripts like this:
Manager.GetEndpointUrl(EndpointNames.YourEndpointName);This is useful to not change your code when APIs change. For more detailed examples check the demo scene.
New API can be created using the Settings Window:
- Create an image for QRCode
This step is needed only if the Unity app does not run on a mobile device with the Maiar app already installed.
For the QR code to be displayed, an empty Image component needs to be created, as shown below.
- Connect to Maiar
Call the Connect method as shown bellow.
//qrImage is a reference of the image component created at 4
MultiversXUnityTools.Manager.Connect(OnConnected, OnDisconnected, qrImage);
/// <summary>
/// Triggered when Maiar app connected
/// </summary>
/// <param name="connectedAccount">A class containing informations about the connected wallet</param>
private void OnConnected(Account connectedAccount)
{
//do what you want with the account information here
LoadScreen(Screens.Connected, connectedAccount);
}
/// <summary>
/// Triggered when wallet disconnected
/// </summary>
private void OnDisconnected()
{
//do what you want when disconnected
LoadScreen(Screens.Home);
}After the Connect method is called, a web socket will be created to communicate with the Maiar app, and a QR code will be automatically generated on that blank image from point 4. After the QR code is scanned and the login is approved inside Maiar, the OnConnected callback will be triggered.
- Login on a mobile device
The QR code cannot be scanned if the Maiar app is on the same device, so a method called Deep Linking needs to be used to communicate directly with the Maiar app.
After the Connect method from the previous point is called, from the Unity app, this method needs to be called to trigger the login prompt inside Maiar:
MultiversXUnityTools.Manager.DeepLinkLogin();This has the same result as the QR scanning method. After the login is approved inside Maiar, the OnConnected callback will be triggered.
- Disconnect
To terminate the users active session simply call disconnect
MultiversXUnityTools.Manager.Disconnect();This will trigger the OnDisconnected method and close the web socket.
This concludes the wallet connect Unity tutorial.
Recommended next: Send EGLD Transaction