Unity
Access Wallet

Accessing User's Wallet

When the user is sucessfully authenticated, you can now interact with the user's wallet via the FractalClient a globally accessible class that wraps all of the Client API endpoints.

Fractal Client

The idea is that any other script can access the FractalClient singleton, allowing you to easily connect any game objects to the Fractal Account, such as for example a player inventory prefab can directly fetch wallet's items anywhere in the game or button can generate and request on-chain transaction signing.

FractalClient stores the authenticated session and all of the features can only be acessed when user is sucessfully authenticated with necessary API scopes. In case a particular scope is missing, an appropriate exception is raised and request is not even executed.

You can access the Fractal client globally by acessing FractalSDK.Core namespace and using FractalClient.Instance and calling the appropriate function.

Usage

Fetching functions always returns a instance of appropriate response class that is following the same structure as described in API Reference (opens in a new tab).

In this example we are fetching the user's information and subsequently showing the user's e-mail in text object. To catch any exceptions, we wrap our call to a try-catch block.

try
{
    UserInfo user = await FractalClient.Instance.GetUser();
    authUserText.text = user.email;
}
catch (FractalNotAuthenticated)
{
    Debug.Log("User is not authenticated.");
}
catch (FractalAPIRequestError)
{
    Debug.Log("Device is offline / API Unreachable.");
}

Reference

To explore all of the available calls, move to Unity SDK Reference.