I’m working on a Solidity smart contract where I need to create exactly one unique NFT. Most guides I’ve found focus on creating collections with multiple tokens using ERC721 inheritance. Here’s my current implementation:
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
contract UniqueArtwork is ERC721 {
uint256 public itemCount;
constructor () ERC721 ("CatArt", "CAT"){
itemCount = 0;
}
function mintArtwork(string memory metadataURI) public returns (uint256) {
uint256 currentId = itemCount;
_safeMint(msg.sender, currentId);
_setTokenURI(currentId, metadataURI);
itemCount = itemCount + 1;
return currentId;
}
}
What’s the best way to modify this code so it only allows minting one NFT total? I want to make sure nobody can call the mint function after the first token is created.