Created
January 27, 2022 10:51
-
-
Save Andrew7234/52c88dc60071673988596f00bf17d31b to your computer and use it in GitHub Desktop.
This file contains 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.8.0; | |
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol"; | |
import "@openzeppelin/contracts/access/Ownable.sol"; | |
import "@openzeppelin/contracts/utils/Counters.sol"; | |
contract CryptoHunks is ERC721Enumerable, Ownable { | |
using Counters for Counters.Counter; | |
Counters.Counter private _tokenIds; | |
uint256 public MAX_HUNKS; | |
uint256 public constant hunkPrice = 1000000000000000; //0.01 ETH | |
constructor(uint256 maxNftSupply) ERC721("CryptoHunks", "CHUNKS") { | |
MAX_HUNKS = maxNftSupply; | |
} | |
function withdraw() public onlyOwner { | |
uint balance = address(this).balance; | |
payable(msg.sender).transfer(balance); | |
} | |
function mintHunk() public payable { | |
require(totalSupply() + 1 <= MAX_HUNKS, "Purchase would exceed max supply of hunks"); | |
require(hunkPrice <= msg.value, "Insufficient funds provided"); | |
uint256 mintIndex = totalSupply(); | |
if (totalSupply() < MAX_HUNKS) { | |
_safeMint(msg.sender, mintIndex); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment