Created
July 21, 2022 19:25
-
-
Save CeoFred/e4587d7990e03a33611e644b379d8c63 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
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.8.4; | |
import "@openzeppelin/contracts/security/Pausable.sol"; | |
import "@openzeppelin/contracts/access/Ownable.sol"; | |
import "@openzeppelin/contracts/utils/Strings.sol"; | |
import "erc721a/contracts/ERC721A.sol"; | |
// TODO: Change name for production!! | |
contract PhatMan is ERC721A, Pausable, Ownable { | |
using Strings for uint256; | |
mapping(address => bool) public controllers; | |
mapping(address => bool) public whitelist; | |
mapping(address => bool) public freeMint; | |
bool public isRevealed = false; | |
bool public isWhiteList = true; | |
string public notRevealedUri; | |
string baseURI; | |
string public baseExtension = ".json"; | |
uint256 public whitelistCost = 0.1 ether; | |
uint256 public publicCost = 0.125 ether; | |
uint256 public maxSupply = 252; | |
event Payout(address indexed sender, uint256 amount); | |
modifier onlyController() { | |
require(controllers[_msgSender()], "Controller Only"); | |
_; | |
} | |
// TODO: Change this later to production!!!!! | |
// TODO: Mint project mints and giveaways | |
constructor() ERC721A("BHS Season2", "BHS2") { | |
controllers[_msgSender()] = true; | |
freeMint[_msgSender()] = true; | |
} | |
function _baseURI() internal view virtual override returns (string memory) { | |
return baseURI; | |
} | |
function pause() public onlyOwner { | |
_pause(); | |
} | |
function unpause() public onlyOwner { | |
_unpause(); | |
} | |
function setWhiteList(bool flag) public onlyOwner { | |
isWhiteList = flag; | |
} | |
function addWhiteList(address[] memory accounts) public onlyOwner { | |
for (uint256 i = 0; i < accounts.length; i++) { | |
require(accounts[i] != address(0), "ZERO_ADDRESS"); | |
if (!whitelist[accounts[i]]) { | |
whitelist[accounts[i]] = true; | |
} | |
} | |
} | |
function removeWhiteList(address[] memory accounts) public onlyOwner { | |
for (uint256 i = 0; i < accounts.length; i++) { | |
require(accounts[i] != address(0), "ZERO_ADDRESS"); | |
if (whitelist[accounts[i]]) { | |
delete whitelist[accounts[i]]; | |
} | |
} | |
} | |
function addFreeMint(address _minter) public onlyOwner { | |
freeMint[_minter] = true; | |
} | |
function removeFreeMint(address _minter) public onlyOwner { | |
freeMint[_minter] = false; | |
} | |
function withdraw() public onlyOwner { | |
uint256 _balance = address(this).balance; | |
require(_balance > 0, "There are no payout to withdraw"); | |
address payable _owner = payable(owner()); | |
_owner.transfer(_balance); | |
emit Payout(owner(), _balance); | |
} | |
function setNotRevealedURI(string memory _notRevealedURI) | |
public | |
onlyController | |
{ | |
notRevealedUri = _notRevealedURI; | |
} | |
function setController(address feeController) public onlyOwner { | |
controllers[feeController] = true; | |
} | |
function setBaseURI(string memory _newBaseURI) public onlyController { | |
baseURI = _newBaseURI; | |
} | |
function reveal() public onlyController { | |
isRevealed = true; | |
} | |
function setBaseExtension(string memory _newBaseExtension) | |
public | |
onlyController | |
{ | |
baseExtension = _newBaseExtension; | |
} | |
function safeMint(uint256 _mintQty) public payable whenNotPaused { | |
uint256 supply = totalSupply(); | |
require(_mintQty > 0, "You must mint more than 0 tokens"); | |
require(supply + _mintQty <= maxSupply, "Max supply limit reached"); | |
if (isWhiteList && !freeMint[_msgSender()]) { | |
require(whitelist[_msgSender()], "You must be in the whitelist"); | |
} | |
uint256 totalCost; | |
if (isWhiteList) { | |
totalCost = whitelistCost * _mintQty; | |
} else { | |
totalCost = publicCost * _mintQty; | |
} | |
if (freeMint[_msgSender()] != true) { | |
require(msg.value >= totalCost, "You do not have enough funds!"); | |
} | |
_safeMint(_msgSender(), _mintQty); | |
} | |
function getOwnerOfAllNFTs() public view returns (address[] memory) { | |
address[] memory _owners = new address[](totalSupply()); | |
for (uint256 i = 0; i < totalSupply(); i++) { | |
_owners[i] = ownerOf(i); | |
} | |
return _owners; | |
} | |
function tokenURI(uint256 tokenId) | |
public | |
view | |
virtual | |
override | |
returns (string memory) | |
{ | |
require( | |
_exists(tokenId), | |
"ERC721Metadata: URI query for nonexistent token" | |
); | |
if (isRevealed == false) { | |
return notRevealedUri; | |
} | |
string memory currentBaseURI = _baseURI(); | |
return | |
bytes(currentBaseURI).length > 0 | |
? string( | |
abi.encodePacked( | |
currentBaseURI, | |
tokenId.toString(), | |
baseExtension | |
) | |
) | |
: ""; | |
} | |
receive() external payable {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment