Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Presale whitelisting using maps #27

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions contract/SimpleNftLowerGas.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ contract SimpleNftLowerGas is ERC721, Ownable {
bool public paused = true;
bool public revealed = false;

bool public presale = true;
mapping(address => bool) public whitelisted;
uint256 public maxPresaleMintAmount = 2;

constructor() ERC721("NAME", "SYMBOL") {
setHiddenMetadataUri("ipfs://__CID__/hidden.json");
}
Expand All @@ -56,6 +60,15 @@ contract SimpleNftLowerGas is ERC721, Ownable {
require(!paused, "The contract is paused!");
require(msg.value >= cost * _mintAmount, "Insufficient funds!");

if (presale) { //Murf dont allow minting if presale is set and buyer is not in whitelisted map
if ( !isInWhiteList(msg.sender)) {
revert("Buyer is not in Whitelist for Pre-Sale");
}
// //BM check if already bought
if ( balanceOf(msg.sender)+_mintAmount > maxPresaleMintAmount)
revert("Buyer has already pre-sale minted max tokens");
}

_mintLoop(msg.sender, _mintAmount);
}

Expand Down Expand Up @@ -164,4 +177,30 @@ contract SimpleNftLowerGas is ERC721, Ownable {
function _baseURI() internal view virtual override returns (string memory) {
return uriPrefix;
}

//Murf Whitelist Functions
function setPresale(bool _state) public onlyOwner {
presale = _state;
}

function setMaxPresaleMintAmount(uint256 _max) public onlyOwner {
maxPresaleMintAmount = _max;
}

function addToWhiteList(address _addr) public onlyOwner {
whitelisted[_addr] = true;
}

function addArrayToWhiteList(address[] memory _addrs) public onlyOwner {
for (uint256 i=0;i< _addrs.length;i++)
whitelisted[_addrs[i]] = true;
}

function removeFromWhiteList(address _addr) public onlyOwner {
whitelisted[_addr] = false;
}

function isInWhiteList(address _addr) private view returns (bool) {
return whitelisted[_addr] || _addr == owner();
}
}