Managing Users
7

Creating a User

In this step, with the access token that you retrieved in the previous step, you will need to pass that as the authorization header when performing the create user mutation.

Your authorization system needs to check to see if a user's account has been created yet.

  • If it hasn't, it should create a new account for them.
  • If it has, then the system should try to log them in.
GraphQL
mutation CreateUser($name: String!) {
 CreateEnjinUser(name: $name) {
   id
   accessTokens
   identities {
     linkingCode
     linkingCodeQr
     wallet {
       ethAddress
     }
   }
 }
}

Once you have created an Enjin account, it's advisable to enter the reference into your database, so you don't repeat this process unnecessarily in the future.

Loggin Your User In

In this final step of integration, once you are have confirmed that your user has an existing account, you can log your user in by following this query:

GraphQL
query RetrievePlayerAccessToken($name: String!) {
 AuthPlayer(id: $name) {
   accessToken
   expiresIn
 }
}

If the API returns a linking code, that means the user's Enjin Wallet is not linked. If no linking code is returned, this means the wallet is linked and you can send the user into the game.

Enjin Identities

Most queries and mutations require an indentity ID. You can use this query to grab the Identity ID's:

GraphQL
query GetIdentities($page: Int) {
 EnjinIdentities(pagination: {page: $page, limit: 50}) {
   id
   linkingCode
   linkingCodeQr
   wallet {
     ethAddress
   }
 }
}

Using this query, should return various pieces of information that will help you with further integration, such as:

  • The App Id.
  • The Linking Code.
  • The Linking Code QR (This is rather useful, you can copy the URL of the linking code QR in a new tab, and scan with the Enjin Wallet to link your Identity ID).
  • The wallet address associated with the identity ID.

Check Linking Code

You can also check your user's linking code whenever you want, by following this query:

GraphQL
query GetIdentityLinkingCode($id: Int!) {
 EnjinIdentities(id: $id) {
   linkingCode
   linkingCodeQr
   wallet {
     ethAddress
   }
 }
}

Unlinking a Wallet

At times, your user may want to change wallets, which they can do this via the Enjin Wallet by going to the "Linked Apps" section, tapping on the project, tap on the 3-dot menu and select "Delete".
Additionally, you can also initiate this on your end.

The following query will unlink their wallet and allow them to re-link it, or link a new one:

GraphQL
mutation UnlinkWalletAddress($id: Int!) {
 DeleteEnjinIdentity(id: $id, unlink: true) {
   linkingCode
   linkingCodeQr
 }
}

Viewing Tokens in a Wallet

Once a player is logged in and linked, the first thing you will want to do is see their inventory so you can provide them with game items to match their tokens.

It's advisable to update the user's balance on your database. That way, your project or game can run efficiently on the data you are holding.

GraphQL
query getBalance($address: String!) {
 EnjinBalances(ethAddress: $address, value_gt: 0) {
   token {
     id
     index
     name
   }
   value
 }
}

It's important to include the value_gt: 0 argument because it prevents the display of melted items. They technically still exist within that blockchain address, even though the user has chosen to destroy/melt them.

View Specific Tokens in a Wallet

When you want to perform a specific action with a token, you can use this to validate whether the token is still there.

GraphQL
query GetWalletTokenBalance($address: String!, $tokenId: String) {
 EnjinBalances(ethAddress: $address, tokenId: $tokenId, value_gt: 0) {
   token {
     id
     index
     name
   }
   value
 }
}

This query displays the token index and balance of the token in question.

You can also choose to request the data for tokenId and id by adding the fields to the query.

View ENJ Balance

You can view the amount of Enjin Coin (ENJ) of a user in the wallet. This can be useful, if you need to know if they have enough Enjin Coin to approve certain transactions and requests.
You can use the following query to retrieve the ENJ balance:

GraphQL
query GetWalletBalance($id: Int!) {
 EnjinUsers(id: $id) {
   identities {
     wallet {
       ethAddress
       enjBalance
     }
   }
 }
}

If you don't know the user ID or the Identity ID, you can use the following query to retrieve the same results, simply with the ethreum address instead:

GraphQL
query GetWalletBalanceByAddress($address: String!) {
 EnjinWallet(ethAddress: $address) {
   enjBalance
   ethBalance
 }
}
Previous
next
On This Page