How to use Emergence as a login validation system for your game

This is an added step that you may want to include in your game. This check essentially validates that your client, who has connected their wallet in game, is indeed the owner. These can be very helpful checks especially for multiplayer games. We know that in server based gaming, hacking is a thing that exists in the gaming industry. What we are providing here is a handy way for you to be able to validate that the current user is indeed the owner of the wallet in question.

This tutorial assumes your game makes use of a dedicated server.

First, make a login menu that opens the overlay, and create a "login" button that only appears once the player has a valid persona (see "Getting the current persona"). This login button should tell the client to connect to your game server.

Once the player connects to your server, use some code to tell the client to send the player's Emergence access token, current persona details and wallet address to the server - there are many ways you can do this, such as an RPC method, but Unreal Engine 4 multiplayer basics are out of the scope of this tutorial.

On the server-side, listen for player logins with a gamemode event such as OnPostLogin - here, you can use ValidateAccessToken to check the player is who they say they are, and not a hacker with a modified client sending whoever's wallet address they want! If ValidateAccessToken responds false, something is fishy with the player's access token, kick this player from your server.

You may wish to use your own signed token, rather than the Emergence token - you can learn how to do this in "How to use access tokens for offchain services & verify them".

Last updated