Skip to content
SDKPlayer ServiceSessionsCreating sessions

Creating sessions

In order to get started with a Session, you will need to call the following method in our C# SDK in the game client.

Disclaimer: Sessions should only be created and initialised on the client side.

            var activeSessionResult = await beamClient.CreateSessionAsync("entity-id-of-user");
            if (activeSessionResult.Status == BeamResultType.Success)
            {
                var session = activeSessionResult.Result;
                // you can now sign Operations without leaving the game
            }

The method handles a couple of things:

  1. It generates a private key in the game client of the user and stores it locally.*
  2. It opens a webview with a constructed url that guides the user through an authentication and authorization flow
  3. If the user approves the session creation, the session gets authorized to sign for transactions on your users behalf
  • NOTE: You can customize storage of Unity SDK using beamClient.SetStorage() method with your implementation of IStorage. It’s important to keep the data on client side.

Once handled, the session (private key) is able to sign transactions on behalf of the user. Note that the session key is limited to run transactions for contracts that were added to your game in the first place. If a new contract was added to your game, calling beamClient.GetActiveSession() will no longer return that session as valid.

Retrieving an active Session

You can retrieve current valid and active Sessions for your user. If local storage was cleared out, your game contracts changed, or the session simply expired - we will not return an active session.

            var activeSessionResult = await beamClient.GetActiveSessionAsync("entity-id-of-user");
            if (activeSessionResult.Status == BeamResultType.Success)
            {
                var session = activeSessionResult.Result;
                var validUntil = session.EndTime;
                // (...)
            }
  • NOTE: You can make development and testing easier by clearing out Player Preferences. This allows you to create Sessions multiple times for the same User, as the private key owning them is lost on removal.