Skip to content
API
Assets
Reading profile assets

Reading profile assets

Depending on your needs, we offer various ways to validate the balance of a profile - whenever that's for an ERC20, ERC721, ERC1155 or the native token on Beam.

However, depending on the token types there are a few caveats, as we are using an indexer for the ERC721 / ERC1155 type contracts, causing there to be a small delay between on-chain events and the actual sdk method response.

NFTs (ERC721, ERC1155)

By running the following method, you will receive all ERC721 and ERC1155 type assets within a profile for all the contracts we registered for your game. As there could be quite a few assets, the response is paginated.

Note that at the moment of writing, we do not expose filtering options yet - but they are expected to drop soon in order for you to filter in different ways to get meaningful results.

const profileAssets = await beam.assetsV2.getProfileAssetsForGamePostV2("entity-id", {
  sortDirection: 'desc';
  sortBy: 'acquiredAt';
  contract: "0x..."; // if you want to get assets only from one collection, null/undefined otherwise
  includeAttributes: true; // defaults to false
  continuation: null; // pagination continuation token
  limit: 20;
});
 
// {
//   "data": [
//     {
//       "id": "string",
//       "name": "string",
//       "imageUrl": "string",
//       "assetType": "string",
//       "assetAddress": "string",
//       "assetId": "string",
//       "quantity": 0
//     }
//   ],
//   "pagination": {
//     "count": 0,
//     "limit": 10,
//     "offset": 0
//   }
// }

Currencies (ERC20 and the native token)

In order to get all ERC20 token balances for a profile, you can run the getProfileCurrencies method. The response model for this enpdoint is not paginated, as we don't expect a single game to have more than a few on-chain currencies to support their in-game economy.

const profileTokens = await beam.assetsV2.getProfileCurrenciesV2("entity-id");
 
// {
//   "data": [
//     {
//       "address": "string",
//       "name": "string",
//       "symbol": "string",
//       "decimals": 0,
//       "logoUri": "string",
//       "chainId": 13337;
//       "balance": "string"
//     }
//   ]
// }

Native token

If you are interested in validating the native currency of a profile, for example to validate whenever the profile has enough BEAM to run a self-paid transaction, you could fetch the native token balance directly by doing the following:

const profileTokens = await beam.assetsV2.getProfileNativeCurrencyV2("entity-id");
 
// {
//   "nativeTokenBalance": {
//     "name": "string",
//     "symbol": "string",
//     "decimals": 0,
//     "logoUri": "string",
//     "chainId": 13337,
//     "balance": "string"
//   }
// }