Get all NFT tokens in a wallet

After minting multiple tokens using the CIS2 Contract, I want to display all the tokens from the wallet without specifying a tokenId, that means, If a wallet has 5 tokens from a contract, I want to display them all.

I would prefer a JavaScript Solution.

If you want your solution to work for any CIS2Contract deployed, then writing an indexer that listens to the following events to build a database of who owns which token of a specific cis2contract would work. Your backend would construct/maintain such a database and your front end would query the tokens own by a specific account address via an endpoint that your backend exposes.

Cis2Event::Mint , Cis2Event::Transfer, and Cis2Event::Burn events

Here are some (not advised/production ready) solutions, but might work if you just want to hack around:

  • Some CIS2 contracts expose view functions that you can query (assuming the number of NFTs in the contract are small enough).
    concordium-rust-smart-contracts/examples/cis2-nft/src/ at main · Concordium/concordium-rust-smart-contracts · GitHub
  • The walletProxy has an API endpoints that you can query:
    GET /v0/CIS2TokenBalance/{index}/{subindex}/{account address}
    GitHub - Concordium/concordium-wallet-proxy
    e.g. If you open the URL in the browser you get all tokens from that contract.
    Querying the balance of one tokenId:
    Querying the balance of several tokenIds: