How to mint unique NFTs

I’m working on a NFT project using ERC721 smart contract (with ERC721URIStorage extension) where user can mint unique NFTs.

I have uploaded NFT’s json metadata’s (used for TokenURIs) to IPFS.

In the dapp (using react), there will be a mint button where the user clicks on it to mint a random NFT. I’m struggling though with developing the logic of minting random NFT. I have uploaded to IPFS a text file containing all the TokenURIs, and then reading this file in the mint function in my dapp where a random TokenURI is fetched and then minted. The issue here is that I couldn’t find a way to put a flag on the selected TokenURI on IPFS so next time mint function is called it will not get this TokenURI at all.

I’m not sure if this is the right way to accomplish what I need (mint unique NFTs)

Any help or hint here will be much appreciated.

Maybe store the previously selected TokenURI somewhere in the database, so you can verify it before minting. And if the previously selected TokenURI is present in the database you will pick another random TokenURI from the TokenURI file and continue the loop until you get a TokenURI that is not on the database.

Hope I understood it right.

Thanks for your reply. I’m not currently using a database in my project. I’m depending on IPFS to store all needed metadata and images.

Another way I can think of is by reading from the blockchain itself. You can create a public array in your contract that maps all the minted TokenURIs to a bool value.

So before minting you can verify if the TokenURI is already on the blockchain by reading the bool value.