Management API Reference

Embedded wallets

Create and recover signers

Learn how to configure and use embedded wallets in your Unity game

There are two essential steps to configure Openfort's embedded wallets in your Unity application:

  1. Configure the embedded signer
  2. Wait for the embedded signer to be ready

Embedded Signer Configuration#

The Openfort SDK provides methods to configure a non-custodial embedded signer for blockchain interactions and transaction signing in your Unity game.

Here's how to implement the configuration:


_52
using UnityEngine;
_52
using System;
_52
using System.Threading.Tasks;
_52
using Openfort.OpenfortSDK;
_52
using Openfort.OpenfortSDK.Model;
_52
_52
public class OpenfortManager : MonoBehaviour
_52
{
_52
private OpenfortSDK openfort;
_52
_52
private async void Start()
_52
{
_52
try
_52
{
_52
openfort = await OpenfortSDK.Init("YOUR_OPENFORT_PUBLISHABLE_KEY");
_52
}
_52
catch (Exception e)
_52
{
_52
Debug.LogError($"Initialization error: {e.Message}");
_52
}
_52
}
_52
_52
public async Task ConfigureEmbeddedWallet(string authToken, string password = null)
_52
{
_52
try
_52
{
_52
int chainId = 80002; // Polygon Amoy testnet
_52
_52
// Create shield authentication configuration
_52
var shieldAuth = new ShieldAuthentication(
_52
ShieldAuthType.Openfort, // or ShieldAuthType.Custom for third-party auth
_52
authToken
_52
);
_52
_52
// Create the embedded signer request
_52
var request = new EmbeddedSignerRequest(
_52
chainId,
_52
shieldAuth,
_52
password // Optional: for user-based recovery
_52
);
_52
_52
// Configure the embedded signer
_52
await openfort.ConfigureEmbeddedSigner(request);
_52
Debug.Log("Embedded signer configured successfully");
_52
}
_52
catch (Exception e)
_52
{
_52
Debug.LogError($"Configuration error: {e.Message}");
_52
throw;
_52
}
_52
}
_52
}

Configuration Parameters#

The EmbeddedSignerRequest takes the following parameters:

ParameterDescription
chainIdThe blockchain network identifier. See supported chains
shieldAuthAuthentication configuration including auth type and token
passwordOptional: Recovery password for user-based recovery

The ShieldAuthentication configuration includes:

ParameterDescription
authEither ShieldAuthType.Openfort or ShieldAuthType.Custom
tokenThe access or ID token for user verification

Checking Embedded Signer State#

The embedded signer goes through several states during initialization. It's crucial to wait for the proper state before using the signer.

Embedded States#

StateValueDescription
NONE0Initial SDK state
UNAUTHENTICATED1Before user authentication
EMBEDDED_SIGNER_NOT_CONFIGURED2Before signer configuration
CREATING_ACCOUNT3Creating new account for chainID
READY4Signer ready for use

Here's how to check the embedded signer state:


_10
public class OpenfortManager : MonoBehaviour
_10
{
_10
private OpenfortSDK openfort;
_10
_10
public async UniTask<EmbeddedState> GetEmbeddedState()
_10
{
_10
return await GetOpenfortImpl().GetEmbeddedState();
_10
}
_10
}