How to check if NFT is in a specific wallet

Viewed 1377

I need to check if a specific NFT is in a specific wallet, there is an API or a way to do it programmatically?

Thanks a lot.

1 Answers

Assuming the NFT is published onchain and its collection contract implements the ERC-721 standard, you can call the ownerOf() function (defined in the standard) on the collection contract.

Example using web3js:

const collection = new web3.eth.Contract(abiJson, collectionAddress);
const owner = await collection.methods.ownerOf(tokenId).call();
return owner == desiredAddress;

For the ERC-1155 standard, you can use the balanceOf() function.

const balance = await collection.methods.balanceOf(owner, ,tokenId).call();
return balance > 0;
Related