Last active
April 12, 2022 02:15
-
-
Save zhouqiang-cl/30f0f5a9ffa635df70d919e410bfe4df to your computer and use it in GitHub Desktop.
doodle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity >=0.4.22 <0.9.0; | |
import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; | |
import "@openzeppelin/contracts/access/Ownable.sol"; | |
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol"; | |
contract test is ERC721, ERC721Enumerable, Ownable { | |
string public PROVENANCE; | |
bool public saleIsActive = false; | |
string private _baseURIextended; | |
bool public isAllowListActive = false; | |
uint256 public constant MAX_SUPPLY = 10000; | |
uint256 public constant MAX_PUBLIC_MINT = 5; | |
uint256 public constant PRICE_PER_TOKEN = 0 ether; | |
mapping(address => uint8) private _allowList; | |
constructor(string memory name_, string memory symbol_) ERC721(name_, symbol_) {} | |
function setIsAllowListActive(bool _isAllowListActive) external onlyOwner { | |
isAllowListActive = _isAllowListActive; | |
} | |
function setAllowList(address[] calldata addresses, uint8 numAllowedToMint) external onlyOwner { | |
for (uint256 i = 0; i < addresses.length; i++) { | |
_allowList[addresses[i]] = numAllowedToMint; | |
} | |
} | |
function numAvailableToMint(address addr) external view returns (uint8) { | |
return _allowList[addr]; | |
} | |
function mintAllowList(uint8 numberOfTokens) external payable { | |
uint256 ts = totalSupply(); | |
require(isAllowListActive, "Allow list is not active"); | |
require(numberOfTokens <= _allowList[msg.sender], "Exceeded max available to purchase"); | |
require(ts + numberOfTokens <= MAX_SUPPLY, "Purchase would exceed max tokens"); | |
require(PRICE_PER_TOKEN * numberOfTokens <= msg.value, "Ether value sent is not correct"); | |
_allowList[msg.sender] -= numberOfTokens; | |
for (uint256 i = 0; i < numberOfTokens; i++) { | |
_safeMint(msg.sender, ts + i); | |
} | |
} | |
function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal override(ERC721, ERC721Enumerable) { | |
super._beforeTokenTransfer(from, to, tokenId); | |
} | |
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721, ERC721Enumerable) returns (bool) { | |
return super.supportsInterface(interfaceId); | |
} | |
function setBaseURI(string memory baseURI_) external onlyOwner() { | |
_baseURIextended = baseURI_; | |
} | |
function _baseURI() internal view virtual override returns (string memory) { | |
return _baseURIextended; | |
} | |
function setProvenance(string memory provenance) public onlyOwner { | |
PROVENANCE = provenance; | |
} | |
function reserve(uint256 n) public onlyOwner { | |
uint supply = totalSupply(); | |
uint i; | |
for (i = 0; i < n; i++) { | |
_safeMint(msg.sender, supply + i); | |
} | |
} | |
function setSaleState(bool newState) public onlyOwner { | |
saleIsActive = newState; | |
} | |
function mint(uint numberOfTokens) public payable { | |
uint256 ts = totalSupply(); | |
require(saleIsActive, "Sale must be active to mint tokens"); | |
require(numberOfTokens <= MAX_PUBLIC_MINT, "Exceeded max token purchase"); | |
require(ts + numberOfTokens <= MAX_SUPPLY, "Purchase would exceed max tokens"); | |
require(PRICE_PER_TOKEN * numberOfTokens <= msg.value, "Ether value sent is not correct"); | |
for (uint256 i = 0; i < numberOfTokens; i++) { | |
_safeMint(msg.sender, ts + i); | |
} | |
} | |
function withdraw() public onlyOwner { | |
uint balance = address(this).balance; | |
payable(msg.sender).transfer(balance); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment