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:
- Configure the embedded signer
- 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:
_52using UnityEngine;_52using System;_52using System.Threading.Tasks;_52using Openfort.OpenfortSDK;_52using Openfort.OpenfortSDK.Model;_52_52public 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:
Parameter | Description |
---|---|
chainId | The blockchain network identifier. See supported chains |
shieldAuth | Authentication configuration including auth type and token |
password | Optional: Recovery password for user-based recovery |
The ShieldAuthentication
configuration includes:
Parameter | Description |
---|---|
auth | Either ShieldAuthType.Openfort or ShieldAuthType.Custom |
token | The 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#
State | Value | Description |
---|---|---|
NONE | 0 | Initial SDK state |
UNAUTHENTICATED | 1 | Before user authentication |
EMBEDDED_SIGNER_NOT_CONFIGURED | 2 | Before signer configuration |
CREATING_ACCOUNT | 3 | Creating new account for chainID |
READY | 4 | Signer ready for use |
Here's how to check the embedded signer state:
_10public class OpenfortManager : MonoBehaviour_10{_10 private OpenfortSDK openfort;_10_10 public async UniTask<EmbeddedState> GetEmbeddedState()_10 {_10 return await GetOpenfortImpl().GetEmbeddedState();_10 }_10}