Skip to content

Instantly share code, notes, and snippets.

@a2468834
Created March 12, 2022 20:14
Show Gist options
  • Save a2468834/2a1222625e98ea34537548eb4df3733e to your computer and use it in GitHub Desktop.
Save a2468834/2a1222625e98ea34537548eb4df3733e to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.0 <0.9.0;
contract PreSaleMint {
address public immutable _owner;
mapping(address => uint256) public addressMintedBalance; // # of NFTs minted by every address
address[] public whitelistedAddresses; // Dynamic array version of the whitelist
mapping(address => bool) public whitelistedAddressesMap; // Mapping version of the whitelist
modifier onlyOwner() {
require(msg.sender == _owner, "Caller is not the owner of the contract.");
_;
}
constructor() {
_owner = msg.sender;
}
function isWhitelisted(address _user) public view returns (bool) {
for(uint i = 0; i < whitelistedAddresses.length; i++) {
if(whitelistedAddresses[i] == _user)
return true;
}
return false;
}
function whitelistUsers(address[] calldata _users) public onlyOwner {
delete whitelistedAddresses;
whitelistedAddresses = _users;
}
function whitelistUsersMap(address[] calldata _users) public onlyOwner {
for(uint i = 0; i < _users.length; i++) {
whitelistedAddressesMap[_users[i]] = true;
}
}
function preSaleMintCarMan(uint256 _mintAmount) public {
require(isWhitelisted(msg.sender), "User is not in the whitelist.");
for (uint256 i = 1; i <= _mintAmount; i++) {
addressMintedBalance[msg.sender]++;
//_safeMint();
}
}
function preSaleMintModify(uint256 _mintAmount) public {
require(whitelistedAddressesMap[msg.sender], "User is not in the whitelist.");
for(uint256 i = 1; i <= _mintAmount; i++) {
addressMintedBalance[msg.sender]++;
//_safeMint();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment