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
  • A token appears in a wallet's tokens list only while the wallet holds a balance of it, so the list always reflects the wallet's current holdings.
  • 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.

Fetching a wallet with the Enjin API

Wallet data is read with the GetAccount query. It takes the network and chain to look up, along with the wallet's address.

SDKs are not yet available

The C# and C++ SDK examples below are out of date and will not work against the current Enjin Platform API. This section will be updated once new SDKs are published. Until then, use the GraphQL, cURL, Javascript, Node.js, or Python examples.

Fetching a wallet's Enjin Coin balance

Include the balance field in the GetAccount response to see how much ENJ a wallet holds.

Query:

query FetchWalletBalance{
GetAccount(network: ENJIN, chain: MATRIX, address: "efQh8FzLm6oH3dmTU3HWqGrtm6Xcuu1WG33N2Ka9fzo5MFFAr"){ #Specify the network, chain, and account address
balance
}
}

Response:

{
"data": {
"GetAccount": {
"balance": "11799982990638599996" //~11.79998... ENJ
}
}
}
Formatting Balances

The API returns the balance field in the base unit (u128), meaning it appears as a large integer without decimals. To obtain the readable ENJ amount, divide the returned value by 10^18.

  • Formula: Base Unit Value / 1,000,000,000,000,000,000 = ENJ Amount
  • Example: A value of 11799982990638599996 converts to approximately 11.80 ENJ.

Fetching the tokens a wallet holds

Include the tokens field in the GetAccount response to list every token the wallet currently holds. Each token also carries its parent collection, so this single query tells you which collections the wallet holds items in as well.

Query:

query FetchWalletTokens{
GetAccount(network: ENJIN, chain: MATRIX, address: "efQh8FzLm6oH3dmTU3HWqGrtm6Xcuu1WG33N2Ka9fzo5MFFAr"){ #Specify the network, chain, and account address
tokens{
id
tokenId
collection{
id
}
attributes{
key
value
}
}
}
}

Response:

{
"data": {
"GetAccount": {
"tokens": [
{
"id": "2100-23",
"tokenId": "23",
"collection": {
"id": "2100"
},
"attributes": [
{
"key": "uri",
"value": "https://etherscapegame.com/crypto/Detritus.json?ver=2"
}
]
},
{
"id": "4265-1",
"tokenId": "1",
"collection": {
"id": "4265"
},
"attributes": [
{
"key": "name",
"value": "test 1"
}
]
},
{
"id": "4001-3",
"tokenId": "3",
"collection": {
"id": "4001"
},
"attributes": []
}
]
}
}
}

Each token's canonical id (for example 2100-23) combines its collection id and tokenId.

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.