Search code examples
reactjssolidityweb3jsipfs

list all token IDs by owner at ERC721


I have a simple ERC721 smart contract used for testing purposes, I was wondering if it is possible to query the token IDs a specific wallet owns in that smart contract.

eventually I would like to display the NFTs minted by the user in the website.

balanceOf in the contract returns the number of tokens owned by the user, but no further info.

my test smart contract:

https://mumbai.polygonscan.com/token/0x263d3b61ad4f4c44f694a4464a8f2a0b6514c064?a=0x330d7ac5f24dc3570c2afe3f3a57d9c66e0795e8#readContract


Solution

  • Looks like your contract inherits an extension of ERC721 called ERC721Enumerable.

    This extension adds a function called tokenOfOwnerByIndex(address owner, uint256 index), which can used to list all tokens owned by a user (owner). So you can call this function multiple times, looping index from 0 to balanceOf(owner) to get all tokens ids.