4

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.

Edoardo Cortese
  • 154
  • 1
  • 12

1 Answers1

3

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;
Petr Hejda
  • 40,554
  • 8
  • 72
  • 100