Created
April 18, 2024 20:02
-
-
Save magnum/1561de51d09d68dd834cc63b292b64b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function fetchNFTsOwnedByUser() { | |
const transferEvents = await nftContract.queryFilter({ | |
address: nftContractAddress, | |
topics: [ | |
ethers.utils.id("Transfer(address,address,uint256)"), | |
null, | |
ethers.utils.hexZeroPad(userWalletAddress, 32) | |
] | |
}); | |
let ownedTokenIds = new Set(); // Utilizziamo un Set per evitare duplicati | |
for (let event of transferEvents) { | |
// Aggiunge token trasferiti all'utente | |
ownedTokenIds.add(event.args.tokenId.toString()); | |
} | |
console.log("Token IDs owned by user:", Array.from(ownedTokenIds)); | |
return Array.from(ownedTokenIds); | |
} | |
fetchNFTsOwnedByUser().catch(console.error); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment