Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 715
JGarnie Avatar asked Dec 19 '25 02:12

JGarnie


1 Answers

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.

like image 88
0xSanson Avatar answered Dec 20 '25 17:12

0xSanson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!