'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:
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | RiccardoS |