web3jsnfterc721

check if a given NFT id on a contract is minted or not


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


Solution

  • 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
    }