Getting Current Player

Below we demonstrate how to fetch the current user. This will only work when the TrustedPlatformClient is authenticated with a player access token, as such this query is more relevant on the client side. If you need to fetch a player on the server you can explicitly define the id or name of the player.

var _client: TrustedPlatformClient
var _get_current_player_cb: EnjinCallback

func _init():
    _client = TrustedPlatformClient.new()
    _get_current_player_cb = EnjinCallback.new(self, "_get_current_player")

func get_current_player():
    _client.user_service().get_user(GetUserInput.new(), { "callback": _get_current_player_cb })

func _get_current_player(udata: Dictionary):
    var gql: EnjinGraphqlResponse = udata.gql
    if gql.has_errors() or not gql.has_result():
        return
    var user: Dictionary = gql.get_result()

Getting Player Identities

The example below demonstrates how to include the player identities in the user query:

var _client: TrustedPlatformClient
var _get_player_identities_cb: EnjinCallback

func _init():
    _client = TrustedPlatformClient.new()
    _get_player_identities_cb = EnjinCallback.new(self, "_get_player_identities")

func get_player_identities(name: String):
    var input: GetUserInput = GetUserInput.new().name(name)
    input.user_i.with_identities(true)
    _client.user_service.get_user(input, { "callback": _get_player_identities_cb })

func _get_player_identities(udata: Dictionary):
    pass
    var gql: EnjinGraphqlResponse = udata.gql
    if gql.has_errors() or not gql.has_result():
        return
    var user: Dictionary = gql.get_result()
    var identities: Array = user.identities

Linking A Player

While it is possible to explicitly link an ethereum address to an identity in the SDK, we recommend displaying the linking code or linking code qr to player's so that they can link from within the Enjin Wallet android or iOS app. Below we demonstrate how to get the linking code and qr url:

var _client: TrustedPlatformClient
var _get_identity_code_cb: EnjinCallback

func _init():
    _client = TrustedPlatformClient.new()
    _get_player_identities_cb = EnjinCallback.new(self, "_get_player_identities")

func get_identity_code():
    var input: GetUserInput = GetUserInput.new()
    input.user_i.with_identities(true)
    input.identity_i.with_linking_code(true)
    input.identity_i.with_linking_code_qr(true)
    _client.user_service.get_user(input, { "callback": _get_identity_code_cb })

func _get_identity_code_cb(udata: Dictionary):
    pass
    var gql: EnjinGraphqlResponse = udata.gql
    if gql.has_errors() or not gql.has_result():
        return
    var user: Dictionary = gql.get_result()
    var identity: Dictionary = user.identities[0]
    var text_code = identity.linkingCode
    var qr_code_url = identity.linkingCodeQr

Getting Player Balances

There are a various ways to get player balances. We highly recommend using the wallet service to explicitly fetch balances for an ethereum address. By doing so you can limit the scope of data returned in the response compared to other approaches. For demonstration purpose we will show how to include balances when fetching a player as well as how to fetch the wallet for a specific ethereum address:

var _client: TrustedPlatformClient
var _get_balances_cb: EnjinCallback
var _get_wallet_cb: EnjinCallback

func _init():
    _client = TrustedPlatformClient.new()
    _get_balances_cb = EnjinCallback.new(self, "_get_balances")
    _get_wallet_cb = EnjinCallback.new(self, "_get_wallet")

func get_balances():
    var input: GetUserInput = GetUserInput.new()
    input.user_i.with_identities(true)
    input.identity_i.with_wallet(true)
    input.wallet_input.with_balances(true)
    _client.user_service.get_user(input, { "callback": _get_balances_cb })

func get_wallet(eth_addr: String):
    var input: GetWalletInput = GetWalletInput.new().eth_addr(eth_addr)
    input.wallet_i.with_balances(true)
    _client.wallet_service.get_wallet(input, { "callback": _get_wallet_cb })

func _get_balances_cb(udata: Dictionary):
    pass
    var gql: EnjinGraphqlResponse = udata.gql
    if gql.has_errors() or not gql.has_result():
        return
    var user: Dictionary = gql.get_result()
    var identity: Dictionary = user.identities[0]
    var wallet: Dictionary = identity.wallet
    var balances: Array = wallet.balances
    for balance in balances:
        print("id: %s, index: %s, amount: %s" % [balance.id, balance.index, balance.value])

func _get_wallet_cb(udata: Dictionary):
    pass
    var gql: EnjinGraphqlResponse = udata.gql
    if gql.has_errors() or not gql.has_result():
        return
    var user: Dictionary = gql.get_result()
    var identity: Dictionary = user.identities[0]
    var wallet: Dictionary = identity.wallet
    var balances: Array = wallet.balances
    for balance in balances:
        print("id: %s, index: %s, amount: %s" % [balance.id, balance.index, balance.value])