Skip to main content

Reading User Wallets

Fetching wallets is crucial because it allows you to see the contents of a wallet, including all tokens held within.

This is especially important in gaming and app development as it enables you to assign specific utilities or benefits to certain tokens.

For example, if a user has a particular token in their wallet, they might gain access to exclusive in-game items or features within an app, enhancing the user experience and adding value to the tokens.

What you'll need:
Best Practices
  • Only pull data from the collections you need. This will improve performance and ensure your backend infrastructure remains scalable.
  • Always read and check the balance. Sometimes, the player may appear to hold the token but the balance is actually zero, for instance, if the token has been burned. These burned tokens should not have in-game utility.
  • Consider whether you want NFTs that are listed on a marketplace to have utility in your game. Items that are listed for sale don't show up in regular token balance and show up in reserved balance instead. If you want them to have utility, you can check the reserved balance and include the reserved supply.
  • Consider if you need to use pagination. Users can have hundreds of tokens, in this situation you will need to read them in multiple calls.
  • If you plan to utilize metadata from on-chain or external sources, it's important to also read the token's attributes. Typically, you'll find a "uri" attribute that points to the external location of this metadata.
  • When accessing external metadata or media, make sure to do so asynchronously and think about storing it in a local cache for faster retrieval.

Fetching a wallet with the Enjin API

Fetching wallet's Enjin Coin balance

Use the GetWallet query and include the the balances in the query response to see how much ENJ a wallet holds.

Query:

query FetchWalletBalance{
GetWallet(account: "cxLU94nRz1en6gHnXnYPyTdtcZZ9dqBasexvexjArj4V1Qr8f"){ #Specify the account address
balances{
free
reserved
}
}
}

Response:

{
"data": {
"GetWallet": {
"balances": {
"free": "86010842630734264894", //~86.01084... ENJ
"reserved": "13900475000000000000" //~13.90047... ENJ
}
}
}
}
Balances Format

API balances fields are formatted as u128 number type.
to get decimal value, divide the value by 10^18.

Fetch a wallet's collections

Use the GetWallet query and include the the collectionAccounts in the query response to see what collections a wallet holds.

Query:

query FetchingWalletCollections{
GetWallet(account: "cxLU94nRz1en6gHnXnYPyTdtcZZ9dqBasexvexjArj4V1Qr8f"){ #Specify the account address
collectionAccounts{
edges{
node{
collection{
collectionId
attributes{
key
value
}
}
}
}
}
}
}

Response:

{
"data": {
"GetWallet": {
"collectionAccounts": {
"edges": [
{
"node": {
"collection": {
"collectionId": "33866",
"attributes": []
}
}
},
{
"node": {
"collection": {
"collectionId": "36105",
"attributes": [
{
"key": "name",
"value": "My test collection"
}
]
}
}
},
{
"node": {
"collection": {
"collectionId": "36623",
"attributes": [
{
"key": "name",
"value": "Docs Testing Collection"
}
]
}
}
}
]
}
}
}
}
Using Pagination

The response may be displayed on several pages. To view all of it, you may need to follow steps for pagination which allows you to flip through the pages.

Fetch a wallet's tokens

Use the GetWallet query and include the the tokenAccounts in the query response to see what tokens a wallet holds.

Query:

query FetchingWalletTokens{
GetWallet(account: "cxLU94nRz1en6gHnXnYPyTdtcZZ9dqBasexvexjArj4V1Qr8f"){ #Specify the account address
tokenAccounts{
edges{
node{
balance
token{
tokenId
collection{
collectionId
}
attributes{
key
value
}
}
}
}
}
}
}

Response:

{
"data": {
"GetWallet": {
"tokenAccounts": {
"edges": [
{
"node": {
"balance": "1",
"token": {
"tokenId": "0",
"collection": {
"collectionId": "33866"
},
"attributes": []
}
}
},
{
"node": {
"balance": "1",
"token": {
"tokenId": "0",
"collection": {
"collectionId": "36105"
},
"attributes": [
{
"key": "Name",
"value": "Awesome Token!"
}
]
}
}
},
{
"node": {
"balance": "6",
"token": {
"tokenId": "1",
"collection": {
"collectionId": "36105"
},
"attributes": [
{
"key": "name",
"value": "Awesome Token 2!"
}
]
}
}
}
]
}
}
}
}
Using Pagination

The response may be displayed on several pages. To view all of it, you may need to follow steps for pagination which allows you to flip through the pages.

Explore More Arguments

For a comprehensive view of all available arguments for queries and mutations, please refer to our API Reference. This resource will guide you on how to use the GraphiQL Playground to explore the full structure and functionality of our API.