From e62abffd1b8da39d530ace2d118e65791b7eaf6a Mon Sep 17 00:00:00 2001 From: DavidConselvan Date: Fri, 19 May 2023 14:32:18 -0300 Subject: [PATCH] ERC721 Capped --- 2023.1/David Conselvan/ERC721Capped.sol | 63 +++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 2023.1/David Conselvan/ERC721Capped.sol diff --git a/2023.1/David Conselvan/ERC721Capped.sol b/2023.1/David Conselvan/ERC721Capped.sol new file mode 100644 index 0000000..c107fdf --- /dev/null +++ b/2023.1/David Conselvan/ERC721Capped.sol @@ -0,0 +1,63 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.0; + +import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/ERC721.sol"; + +import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol"; + +contract ERC721Capped is ERC721, Ownable { + uint64 totalCap; + + uint64 supply = 0; + uint mintPrice; + bool mintable = false; + + constructor(string memory _name, string memory _symbol, uint64 _cap) ERC721(_name, _symbol) { + totalCap = _cap; + } + + function getTotalSupply() public view returns (uint64) { + return supply; + } + + function getBalance() public view returns (uint256){ + return address(this).balance; + } + + function _createNFT(address _to) internal { + require(supply < totalCap); + supply++; + _mint(_to, supply); + } + + + function ownerMint() public onlyOwner{ + _createNFT(msg.sender); + } + + function publicMint() public payable{ + require(msg.value >= mintPrice); + require(mintable); + _createNFT(msg.sender); + } + + function setMintPrice(uint _newPrice) public onlyOwner { + mintPrice = _newPrice; + } + + function openSales(uint _newPrice) public onlyOwner { + mintable = true; + setMintPrice(_newPrice); + } + + function closeSales() public onlyOwner { + mintable = false; + + } + + function withdraw() external onlyOwner { + address payable _owner = payable(address(owner())); + _owner.transfer(address(this).balance); + } +}