hi guys, I'm doing a dapp for NFT. how can i get the nft ids inside my metamask? I have only found solutions that give me the balance. if there is no way how does a marketplace filter them?

Feb 18, 2022, 1:40 AM
erc721 interface has balanceOf(address) same as erc20 interface, for viewing number
Feb 18, 2022, 1:43 AM
as i said above i want the ID and not the balance
Feb 18, 2022, 1:50 AM
NFTs that implement IERC721Enumerable interface are easy, you can call tokenOfOwnerByIndex for each index 0 to (balanceOf() - 1).

For NFTs that don't implement that interface or have a similar function, you will have to rely on querying transfer events and aggregating those, or seeing if they have a subgraph or similar service to fetch tokenIDs per address.
ALternatively, it can sometimes be feasible to iterate the whole collection and call ownerOf() for each token, aggregate that way.
Feb 18, 2022, 2:14 AM
Hey there what is rainmaker games ?
Feb 18, 2022, 2:21 AM
P2E hub: https://rmg.io/
Feb 18, 2022, 2:22 AM
I haven't another way?🤯
Feb 18, 2022, 7:49 AM
for non-enumerable ones, I gave you three ways...I'm not sure if there is another way
Feb 18, 2022, 7:50 AM
Yes sorry. do you have something about the query transfer event? Which one do you recommend?
Feb 18, 2022, 7:53 AM
yeah that's the simplest way for most people. You'd just query all collection transfer events from/to the account (starting at whatever block the contract was deployed, typically). Easy enough to then aggregate what their holdings are now based on what tokens came in and out of their wallet over time
Feb 18, 2022, 7:56 AM
it's not clear to me. Do you have any resources about it?
Feb 18, 2022, 8:15 AM
depends on if you prefer web3.js or ethers.js... They both have good documentation on how to do it. Here's ethers.js section on querying events: https://docs.ethers.io/v5/single-page/#/v5/api/contract/contract/-%23-Contract--events
Feb 18, 2022, 8:17 AM
For now I'm using web3 but I think that ether is better the web3
Feb 18, 2022, 8:24 AM

© 2024 Draquery.com All rights reserved.