Metamask Klaytn scope “getBalance” of KIP-17 tokens

Hi, I’m working in the frontend of a website and I want the user to log in with Metamask. This seems to work about right, but I want to extract the KIP-17 balance from their Klaytnscope

Is there any method I can write a function that directly extracts this data, maybe a way of reading: Account Address, then Collection/Contract and last the Token ID.

The objective is to show this as text in the index.html.

Hi, thank you for visiting our forum,
First of all, not sure what wallet your frontend will support, you will need to contact to the wallet provider to get information to interface with wallet. Then it will allow you to get the user’s wallet address.

Second, you can use ‘caver-js’ which is correspond to the web3-js of Ethereum.

to Get a balance of NFT (number of NFT the wallet hold), you can use balanceOf. You can find example from our official documents

caver.kct.kip17 - Klaytn Docs

If you are looking for the way to get all tokenIds that wallet have, then you need to use the method called tokenOfOwnerByIndex. Please check below document for this method.

caver.kct.kip17 - Klaytn Docs

Below is the example of the implantation.

const tokenIds = []
let tokenId;
for (let i=0;i<myKIP17.balanceOf(userAddress);i++) {
     tokenId = await myKIP17.tokenOfOwnerByIndex(userAddress, i)
     tokenIds.puch(tokenId);
}

I hope this can answer your questions.
Thanks,