Skip to content

Instantly share code, notes, and snippets.

@Andrew7234
Created January 27, 2022 10:51
Show Gist options
  • Save Andrew7234/52c88dc60071673988596f00bf17d31b to your computer and use it in GitHub Desktop.
Save Andrew7234/52c88dc60071673988596f00bf17d31b to your computer and use it in GitHub Desktop.
// 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