Is there a more direct way of asking the NFT api if a user address owns a specific token id? You can use:
-
getNFTs()
to get all the NFTs owned by an address then do linear search potentially across multiple pages and requests -
getTokenIdOwners()
: which will only be 1 for ERC721 but could be thousands for ERC1155
Ideally youâd be able to further filter getTokenIdOwners
with a user address. Is this possible? (and not documented)
Otherwise youâre left with queries that return more data than needed. Iâd imagine checking ownership of a specific token is a common use case- especially useful for authentication and authorization- and worthy of a direct solution in the API.
With the current functions:
- For ERC721:
getTokenIdOwners()
is optimal as there can be only 1 owner - For ERC1155 itâs a toss up
- If the user doesnât have many NFTs then
getNFTs()
could be less results, but itâs a gamble - If you have foreknowledge of the number of minted 1155 tokens for that id and the number is low then
getTokenIdOwners()
could be the better choice
- If the user doesnât have many NFTs then
- The most simple solution I suppose is just to use
getNFTs()
and hope they donât have that many