Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: getting all tokens by address #170

Closed
TravelingTechGuy opened this issue Mar 14, 2022 · 2 comments
Closed

Question: getting all tokens by address #170

TravelingTechGuy opened this issue Mar 14, 2022 · 2 comments

Comments

@TravelingTechGuy
Copy link

TravelingTechGuy commented Mar 14, 2022

I would like to get all the tokens owned by a user (address). I see that he main contract imports IERC721Enumerable.sol but does not implement all of its functions (specifically tokenOfOwnerByIndex). Is there an easy way to implement this, based on the data the token maintains already?

One of the other things I thought of doing is emitting a Minted(address, quantity, startIndex, endIndex) event at the end of my mint function, and I assume I can later query for those events, but I'd much rather see if I can get these programmatically.

Thanks!

@Vectorized
Copy link
Collaborator

Vectorized commented Mar 14, 2022

See #115.

If you are listening to events to build up some kind of database, note that each NFT minted emits a Transfer event (with the from address as the zero address). So, emitting a Mint event is not necessary.

@TravelingTechGuy
Copy link
Author

@Vectorized Thanks! Perfect answer there, useful code and use cases.

The reason I added the Minted event is we're not actively listening to the contract, and it'd be far less events to collect than listening to Transfer.

Also, we'll further need to filter to filter Transfer events to those with a from address 0x0, since the event is also used to transferring between accounts, and burning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants