Reputation: 165
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.
Upvotes: 5
Views: 2763
Reputation: 43561
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;
Upvotes: 3