I am trying to write a Solidity contract that allows minting only one unique NFT. Most guides show how to create multiple tokens using ERC721. I would like a contract that stops additional minting once the single token is created.
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
contract SoloNFT is ERC721URIStorage {
bool public isMinted;
constructor() ERC721("UniqueArt", "UART") {
isMinted = false;
}
function mintToken(string memory tokenLink) public returns (uint256) {
require(!isMinted, "Token already minted");
uint256 newId = 1;
_safeMint(msg.sender, newId);
_setTokenURI(newId, tokenLink);
isMinted = true;
return newId;
}
}
How can I adjust my code so that only one exclusive NFT is ever minted?