Managing Players

Alpha Documentation

The documentation for the Enjin SDKs pertain to the Project and Player schemas which are currently in an Alpha release. The Project and Player schemas are not yet publicly available and therefore this documentation is limited only to those who already have access. For any queries, please contact Enjin Support.

Creating a New Player

The first step in player management is to create a player for our project. By creating a player for our project we will be able to link their Enjin Wallet to the project enabling us to create interactions for melting, sending, and trading assets within our application for users.

Step 1: Create the Request

To create a player we will be using the CreatePlayer request. For this request we will need to set the ID we want for our player as shown below:
Java
C#
C++
1
import com.enjin.sdk.schemas.project.mutations.CreatePlayer;
2
​
3
CreatePlayer req = new CreatePlayer()
4
.id("<the-player's-id>");
Copied!
1
using Enjin.SDK.ProjectSchema;
2
​
3
CreatePlayer req = new CreatePlayer()
4
.Id("<the-player's-id>");
Copied!
1
#include "enjinsdk/project/CreatePlayer.hpp"
2
​
3
using namespace enjin::sdk::project;
4
​
5
CreatePlayer req = CreatePlayer()
6
.set_id("<the-player's-id>");
Copied!

Step 2: Send the Request

With the CreatePlayer request we have created and our ProjectClient we can now send the request to the platform as shown below:
Java
C#
C++
1
import com.enjin.sdk.graphql.GraphQLResponse;
2
import com.enjin.sdk.models.AccessToken;
3
​
4
// Using a authenticated ProjectClient
5
GraphQLResponse<AccessToken> res = client.createPlayer(req);
Copied!
1
using Enjin.SDK.Graphql;
2
using Enjin.SDK.Models;
3
​
4
// Using a authenticated ProjectClient
5
GraphqlResponse<AccessToken> res = client.CreatePlayer(req).Result;
Copied!
1
#include "enjinsdk/GraphqlResponse.hpp"
2
#include "enjinsdk/models/AccessToken.hpp"
3
​
4
using namespace enjin::sdk::graphql;
5
using namespace enjin::sdk::models;
6
​
7
// Using a authenticated ProjectClient
8
GraphqlResponse<AccessToken> res = client->create_player(req).get();
Copied!
If the request was successful then we will receive the AccessToken for the player in the response. With the AccessToken we may also now authenticate a platform client for our new player if we choose to do so.

Getting an Existing Player

Once there are players created for our project we may want to get the data associated with them. We will go over how may request this data for an individual player in this section.

Step 1: Create the Request

When requesting player data, how we create our request depends on the schema we are using.
To create the GetPlayer request in the project schema we need to specify the ID of the player whose data we are requesting. For this we use a chaining method for setting the ID as shown below:
Java
C#
C++
1
import com.enjin.sdk.schemas.project.queries.GetPlayer;
2
​
3
GetPlayer req = new GetPlayer()
4
.id("<the-player's-id>");
Copied!
1
using Enjin.SDK.ProjectSchema;
2
​
3
GetPlayer req = new GetPlayer()
4
.Id("<the-player's-id>");
Copied!
1
#include "enjinsdk/project/GetPlayer.hpp"
2
​
3
using namespace enjin::sdk::project;
4
​
5
GetPlayer req = GetPlayer()
6
.set_id("<the-player's-id>");
Copied!
When creating the GetPlayer in the player schema we do not specify the player's ID, since the platform infers this from our player client's credentials. This means we need only to instantiate the request as shown below:
Java
C#
C++
1
import com.enjin.sdk.schemas.player.queries.GetPlayer;
2
​
3
GetPlayer req = new GetPlayer();
Copied!
1
using Enjin.SDK.PlayerSchema;
2
​
3
GetPlayer req = new GetPlayer();
Copied!
1
#include "enjinsdk/player/GetPlayer.hpp"
2
​
3
using namespace enjin::sdk::player;
4
​
5
GetPlayer req = GetPlayer();
Copied!

Step 2: Send the Request

After we have created our request we send it to the platform using our client's corresponding get player method. In the platform's response we expect a Player model representing the data we requested, which we may retrieve if the request was successful.
Java
C#
C++
1
import com.enjin.sdk.graphql.GraphQLResponse;
2
import com.enjin.sdk.models.Player;
3
​
4
// Using a authenticated client
5
GraphQLResponse<Player> res = client.getPlayer(req);
6
​
7
Player player = res.getData();
Copied!
1
using Enjin.SDK.Graphql;
2
using Enjin.SDK.Models;
3
​
4
// Using a authenticated client
5
GraphqlResponse<Player> res = client.GetPlayer(req).Result;
6
​
7
Player player = res.Result;
Copied!
1
#include "enjinsdk/GraphqlResponse.hpp"
2
#include "enjinsdk/models/Player.hpp"
3
​
4
using namespace enjin::sdk::graphql;
5
using namespace enjin::sdk::models;
6
​
7
// Using a authenticated client
8
GraphqlResponse<Player> res = client->get_player(req).get();
9
​
10
Player player = res.get_result().value();
Copied!

Linking a Player

Linking Information

In the Player model there exists a LinkingInfo field that contains information we may use to allow our users to link their Enjin Wallet to their player account in our project. When we get a populated LinkingInfo model from the platform it will have two fields we are interested in, the code field which contains the linking code users may enter in their Enjin Wallet to link to the project and the QR field which contains the URL to the QR image we can display and have our users scan in place of using the linking code.
Java
C#
C++
1
import com.enjin.sdk.models.LinkingInfo;
2
​
3
LinkingInfo linkingInfo = /* linking info source */;
4
​
5
String code = linkingInfo.getCode();
6
String qr = linkingInfo.getQr();
Copied!
1
using Enjin.SDK.Models;
2
​
3
LinkingInfo linkingInfo = /* linking info source */;
4
​
5
string code = linkingInfo.Code;
6
string qr = linkingInfo.Qr;
Copied!
1
#include "enjinsdk/models/LinkingInfo.hpp"
2
#include <string>
3
​
4
using namespace enjin::sdk::models;
5
​
6
LinkingInfo linking_info = /* linking info source */;
7
​
8
std::string code = linking_info.get_code().value();
9
std::string qr = linking_info.get_qr().value();
Copied!

Getting the Linking Information

There is a minor variation between the project and player schemas when creating the request for getting the player information. For this reason we will cover the creation of the request separately for each client.

Creating the Request for a Project Client

We may get the player's linking information using the GetPlayer request from the project schema and specify that we want the player data to be returned with the player's linking information set. To do so we use two chaining methods. One to set the player's ID and another to set the request to retrieve the linking information as seen below:
Java
C#
C++
1
import com.enjin.sdk.schemas.project.queries.GetPlayer;
2
​
3
GetPlayer req = new GetPlayer()
4
.id("<the-player's-id>")
5
.withLinkingInfo();
Copied!
1
using Enjin.SDK.ProjectSchema;
2
using Enjin.SDK.Shared;
3
​
4
GetPlayer req = new GetPlayer()
5
.Id("<the-player's-id>")
6
.WithLinkingInfo();
Copied!
1
#include "enjinsdk/project/GetPlayer.hpp"
2
​
3
using namespace enjin::sdk::project;
4
​
5
GetPlayer req = GetPlayer()
6
.set_id("<the-player's-id>")
7
.set_with_linking_info();
Copied!

Creating the Request for a Player Client

In the player schema we use the GetPlayer request, however unlike in the project schema this GetPlayer request does not need the player's ID set, since the platform infers it from our player client's credentials. This means we only need to specify that we want to request the player data with the linking information set for our request as shown below:
Java
C#
C++
1
import com.enjin.sdk.schemas.player.queries.GetPlayer;
2
​
3
GetPlayer req = new GetPlayer()
4
.withLinkingInfo();
Copied!
1
using Enjin.SDK.PlayerSchema;
2
using Enjin.SDK.Shared;
3
​
4
GetPlayer req = new GetPlayer()
5
.WithLinkingInfo();
Copied!
1
#include "enjinsdk/player/GetPlayer.hpp"
2
​
3
using namespace enjin::sdk::player;
4
​
5
GetPlayer req = GetPlayer()
6
.set_with_linking_info();
Copied!

Sending the Request

After creating our request we now send it to the platform by using the method in our client of the same name as our request. Once we have the response when can retrieve the data from it.
Java
C#
C++
1
import com.enjin.sdk.graphql.GraphQLResponse;
2
import com.enjin.sdk.models.LinkingInfo;
3
import com.enjin.sdk.models.Player;
4
​
5
// Using a authenticated client
6
GraphQLResponse<Player> res = client.getPlayer(req);
7
​
8
Player player = res.getData();
9
​
10
LinkingInfo linkingInfo = player.getLinkingInfo();
Copied!
1
using Enjin.SDK.Graphql;
2
using Enjin.SDK.Models;
3
​
4
// Using a authenticated client
5
GraphqlResponse<Player> res = client.GetPlayer(req).Result;
6
​
7
Player player = res.Result;
8
​
9
LinkingInfo linkingInfo = player.LinkingInfo;
Copied!
1
#include "enjinsdk/GraphqlResponse.hpp"
2
#include "enjinsdk/models/LinkingInfo.hpp"
3
#include "enjinsdk/models/Player.hpp"
4
​
5
using namespace enjin::sdk::graphql;
6
using namespace enjin::sdk::models;
7
​
8
// Using a authenticated client
9
GraphqlResponse<Player> res = client->get_player(req).get();
10
​
11
Player player = res.get_result().value();
12
​
13
LinkingInfo linking_info = player.get_linking_info().value();
Copied!
In the event that the player is already linked to a wallet the Player model returned by the platform may not have its LinkingInfo set.

Unlinking a Player

Using the Project Client

Step 1: Get the Wallet Address

Before creating our request to unlink a player's wallet we must first know what their wallet's address is. If we do not already have this value cached in our application we need not worry as we may retrieve it from the platform with the GetPlayer request.
To use the GetPlayer request to get the wallet address we must specify that we want the player data to be returned with the player's wallet data set. For this we use a chaining method for including wallet data on the request as shown below:
Java
C#
C++
1
import com.enjin.sdk.schemas.project.queries.GetPlayer;
2
​
3
GetPlayer req = new GetPlayer()
4
.id("<the-player's-id>")
5
.withWallet();
Copied!
1
using Enjin.SDK.ProjectSchema;
2
using Enjin.SDK.Shared;
3
​
4
GetPlayer req = new GetPlayer()
5
.Id("<the-player's-id>")
6
.WithWallet();
Copied!
1
#include "enjinsdk/project/GetPlayer.hpp"
2
​
3
using namespace enjin::sdk::project;
4
​
5
GetPlayer req = GetPlayer()
6
.set_id("<the-player's-id>")
7
.set_with_wallet();
Copied!
After creating the request we can now send it to the platform and get the player data returned in the response.
Java
C#
C++
1
import com.enjin.sdk.graphql.GraphQLResponse;
2
import com.enjin.sdk.models.Player;
3
​
4
// Using a authenticated ProjectClient
5
GraphQLResponse<Player> res = client.getPlayer(req);
6
​
7
Player player = res.getData();
Copied!
1
using Enjin.SDK.Graphql;
2
using Enjin.SDK.Models;
3
​
4
// Using a authenticated ProjectClient
5
GraphqlResponse<Player> res = client.GetPlayer(req).Result;
6
​
7
Player player = res.Result;
Copied!
1
#include "enjinsdk/GraphqlResponse.hpp"
2
#include "enjinsdk/models/Player.hpp"
3
​
4
using namespace enjin::sdk::graphql;
5
using namespace enjin::sdk::models;
6
​
7
// Using a authenticated ProjectClient
8
GraphqlResponse<Player> res = client->get_player(req).get();
9
​
10
Player player = res.get_result().value();
Copied!
The Player model contains a Wallet model as one of its fields. We can get this field and in turn get the Ethereum address of the wallet.
Java
C#
C++
1
import com.enjin.sdk.models.Wallet;
2
​
3
Wallet wallet = player.getWallet();
4
​
5
String ethAddress = wallet.getEthAddress();
Copied!
1
using Enjin.SDK.Models;
2
​
3
Wallet wallet = player.Wallet;
4
​
5
string ethAddress = wallet.EthAddress;
Copied!
1
#include "enjinsdk/models/Wallet.hpp"
2
#include <string>
3
​
4
using namespace enjin::sdk::models;
5
​
6
Wallet wallet = player.get_wallet().value();
7
​
8
std::string eth_address = wallet.get_eth_address().value();
Copied!
If the player does not have a wallet linked to them then the Wallet field will not be set.

Step 2: Create the Request

Once we know the player's wallet address we can create the UnlinkWallet request and pass it the wallet address as shown below:
Java
C#
C++
1
import com.enjin.sdk.schemas.project.mutations.UnlinkWallet;
2
​
3
UnlinkWallet req = new UnlinkWallet()
4
.ethAddress("<the-player's-eth-address>");
Copied!
1
using Enjin.SDK.ProjectSchema;
2
​
3
UnlinkWallet req = new UnlinkWallet()
4
.EthAddress("<the-player's-eth-address>");
Copied!
1
#include "enjinsdk/project/UnlinkWallet.hpp"
2
​
3
using namespace enjin::sdk::project;
4
​
5
UnlinkWallet req = UnlinkWallet()
6
.set_eth_address("<the-player's-eth-address>");
Copied!

Step 3: Send the Request

With the created request we now pass it to the client's method with the same name as our request. For UnlinkWallet request we expect the returned response to wrap a Boolean value.
Java
C#
C++
1
import com.enjin.sdk.graphql.GraphQLResponse;
2
​
3
// Using a authenticated ProjectClient
4
GraphQLResponse<Boolean> res = client.unlinkWallet(req);
5
​
6
Boolean result = res.getData();
Copied!
1
using Enjin.SDK.Graphql;
2
​
3
// Using a authenticated ProjectClient
4
GraphqlResponse<bool> res = client.UnlinkWallet(req).Result;
5
​
6
bool result = res.Result;
Copied!
1
#include "enjinsdk/GraphqlResponse.hpp"
2
​
3
using namespace enjin::sdk::graphql;
4
​
5
// Using a authenticated ProjectClient
6
GraphqlResponse<bool> res = client->unlink_wallet(req).get();
7
​
8
bool result = res.get_result().value();
Copied!
The Boolean value contained within the response indicates if the unlink operation was successful. A value of true tells us that we successful unlinked our player, whereas a value of false may imply that the wallet was already unlinked when we sent our request.

Using the Player Client

Step 1: Create the Request

Unlike with the project schema when we use the UnlinkWallet request from the player schema the platform determines the player we intend to unlink using the credentials of our PlayerClient. This means that we do not specify our player's wallet address and instead create the UnlinkWallet request with no additional setup as shown below:
Java
C#
C++
1
import com.enjin.sdk.schemas.player.mutations.UnlinkWallet;
2
​
3
UnlinkWallet req = new UnlinkWallet();
Copied!
1
using Enjin.SDK.PlayerSchema;
2
​
3
UnlinkWallet req = new UnlinkWallet();
Copied!
1
#include "enjinsdk/player/UnlinkWallet.hpp"
2
​
3
using namespace enjin::sdk::player;
4
​
5
UnlinkWallet req = UnlinkWallet();
Copied!

Step 2: Send the Request

We now pass our request to the client using the method of the same name. Our expected response will wrap a Boolean value which we may retrieve.
Java
C#
C++
1
import com.enjin.sdk.graphql.GraphQLResponse;
2
​
3
// Using a authenticated PlayerClient
4
GraphQLResponse<Boolean> res = client.unlinkWallet(req);
5
​
6
Boolean result = res.getData();
Copied!
1
using Enjin.SDK.Graphql;
2
​
3
// Using a authenticated PlayerClient
4
GraphqlResponse<bool> res = client.UnlinkWallet(req).Result;
5
​
6
bool result = res.Result;
Copied!
1
#include "enjinsdk/GraphqlResponse.hpp"
2
​
3
using namespace enjin::sdk::graphql;
4
​
5
GraphqlResponse<bool> res = client->unlink_wallet(req).get();
6
​
7
bool result = res.get_result().value();
Copied!
The Boolean value contained within the response indicates if the unlink operation was successful. A value of true tells us that we successful unlinked our player, whereas a value of false may imply that the our player was not linked when we sent our request.
Last modified 3mo ago