1

NFT contract is on ERC-721

we need the most simple way to check if Token ID from NFT collection is minted so far or not. no matter if it is minted and transferred several times.

just if minted , true

or still not minted, false

Thanks

mhmd
  • 995
  • 2
  • 15
  • 30
  • using openzappelin https://docs.openzeppelin.com/contracts/3.x/erc721 , you can check ```_exists()``` function with token Id as parameter to check if an NFT with that token ID has been minted or not. If you want to check has the contract minted any NFTs at all, you can check if token ID 1 exists (considering your token IDs are not random and start from 1). – Spidy Jul 03 '22 at 09:04

1 Answers1

2

The ERC-721 standard defines the ownerOf() function, accepting the token ID as an input param.

It either returns address of the NFT holder, or throws if the token ID does not exist (i.e. is assigned to address zero).

const collection = new web3.eth.Contract(ABI, ADDRESS);
try {
    await collection.methods.ownerOf(tokenId).call();
    // exists
} catch (e) {
    // does not exist
}
Petr Hejda
  • 40,554
  • 8
  • 72
  • 100