I have seen a Solidity smart contract made by Polkamon, which is used to store NFT hashes, so that users can create an NFT without minting it, so that they can save Gas fees if they don't like their new NFT.
I am confused about the significance of one particular line of code, it is a require function that makes sure that a hash is found in the list of hashes that have been generated by users of the NFT platform.
require(registeredHashes[to][keccak256(abi.encode(to, ids))], "Hash not registered" );
What exactly is going on here?
Here is the rest of the smart contract:
contract SoftMinter is Ownable {
// Mapping from address to bool, if egg was already claimed
// The hash is about the userId and the nftIds array
mapping(address => mapping(bytes32 => bool)) public registeredHashes;
mapping(uint256 => bool) public alreadyMinted;
CanMint private _nftContract;
constructor(CanMint nftContract) public {
_nftContract = nftContract;
}
function mint(
address to,
uint256[] memory ids,
uint256 indexToMint
) public {
require(
registeredHashes[to][keccak256(abi.encode(to, ids))],
"Hash not registered"
);
require(!alreadyMinted[ids[indexToMint]], "Already minted");
if (registeredHashes[to][keccak256(abi.encode(to, ids))]) {
alreadyMinted[ids[indexToMint]] = true;
_nftContract.mint(to, ids[indexToMint]);
}
}
//adding hash
function addHash(address to, bytes32 dataHash) public onlyOwner {
require(!registeredHashes[to][dataHash], "Hash already registered");
registeredHashes[to][dataHash] = true;
}
}