1

I want to call the ownerOf() function on all of the NFT's in a contract. If the address matches the website user address I want to add the tokenID to an array so I can eventually display all nft's owned by the user.

The code below almost works, I think it breaks when ownerOf() returns an error. Also is calling ownerOf() 1000+ times going to timeout or something?

for (let i = 0; i < 1000; i++) { if(await contract.methods.ownerOf(i).call({ from: window.userAddress }) ===window.userAddress{ list.push(i); }; } alert(Owned by this address ${list});

1 Answer 1

0

You should use an API like Moralis which is designed to easily retrieve information like this. I had the same problem. This was the exact API call I needed:

https://docs.moralis.io/reference/getwalletnfts-1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.