How can I add some additional vaidation to my mint
function to check if the person minting the nft owns an item from a specific NFT collection.
In other words, I own 2 collections. I want a user to only be able to mint from collection A in they already own an item in collection B.
function _mint(address to, uint256 tokenId) internal virtual {
require(to != address(0), "ERC721: mint to the zero address");
require(!_exists(tokenId), "ERC721: token already minted");
// some additional check here?
// psuedocode: _hasItemInCollection(to);
_beforeTokenTransfer(address(0), to, tokenId);
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(address(0), to, tokenId);
}
Edited: I moved this logic to live in the mint
function, not the internal _mint
function. Here is the updated code:
function mint(uint256 _mintAmount) public payable mintCompliance(_mintAmount) {
require(!paused, "The contract is paused!");
// not A *REAL* contract address, your contract address HERE.
address patronAccessToken = 0x000000001234567890ABCDEF0001112022222222;
bool isPatron = (IToken(patronAccessToken).balanceOf(msg.sender) > 0);
if (isPatron == true) {
setCost(0.015 ether);
}
require(msg.value >= cost * _mintAmount, "Insufficient funds!");
_mintLoop(msg.sender, _mintAmount);
}
Thank you for your wisdom!
_balances
or_owners
of collection B. if we are trying to mint in collection A then_balances
in this function are correlated with the current collection (user may have zero or more). I though i'd need to perform a lookup to etherscan or something to check. - sorry I am a newbie