// SPDX-License-Identifier: MIT pragma solidity ^0.8.7; // Import the OZ 1155 standard and ownable contract import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; // Initialize our contract contract MySuperSecure1155 is ERC1155, Ownable { uint public totalMinted; string public name; string public symbol; uint256 public total; uint256 public cost; uint256 public _feeAmount; bool public paused = false; bool public whitelistedBuyersOnly = true; uint public constant maxSupply = 1111; address public whitelist = []; mapping(address => bool) public whitelisted; mapping (uint => uint) private tokenMintCounts; mapping (uint256 => string) private _uris; bool internal locked; constructor() ERC1155("{{myIPFSLINK}}/{id}.json") { name = "MySuperSecureNFT"; symbol = "MSSN"; setWhitelistedAddresses(whitelist); // Set resale fee amount _feeAmount = (cost*1/10^18); setCost(whitelistedBuyersOnly); } // Initiate reentrancy guard modifier reentrancyGuard() { require(!locked); locked = true; _; locked = false; } // make the withdraw function non reentrant, stops same token being double spent function withdraw() public noReentrant { uint256 amount = balances[msg.sender]; balances[msg.sender] = 0; require(msg.sender.call.value(amount)()); } // set whitelist mapping from initial array of hodlers function setWhitelistedAddresses(address[] memory users) internal { for(uint i = 0; i < users.length; i++) { whitelisted[users[i]] = true; } } // mint function function mint(address _to, uint _id) public payable { // Checks max supply isnt reached require(totalMinted != maxSupply, "Sold Out !"); // Checks that token isnt sold out for 1 - 1 require(tokenMintCounts[_id] == 0, "The token you tried to mint has sold out"); // Checks to make sure contract isnt paused require(!paused, "Contract is currently paused"); // Allows owner to mint for free if (msg.sender != owner()) { if (whitelistedBuyersOnly == true) { // require user is on whitelist to be able to mint require(whitelisted[msg.sender], "Error, whitelist only at this time"); } // Ensures users pays cost require(msg.value >= cost, "Please supply the proper amount of funds for minting"); // Splits funds after user pays. splitFunds(cost); } // run the mint _mint(_to, _id, 1, ""); // Incremet mint count for token ID tokenMintCounts[_id] = 1; // Increment mint count for all tokens totalMinted++; } // Function for registering token uri function uri(uint256 tokenId) override public pure returns (string memory) { return( string(abi.encodePacked( "{{myIPFSLink}", Strings.toString(tokenId), ".json" )) ); } // returns cost function getPrice() public view returns(uint) { return cost; } // returns mint count function getMintCount() public view returns(uint) { return totalMinted; } // returns collection max supply function getMaxSupply() public pure returns(uint) { return maxSupply; } // add user to the whitelisted function addUserToWhitelist(address _user) public onlyOwner() { whitelisted[_user] = true; } // returns user is whitelisted function checkUserWhitelistStatus(address _user) public view onlyOwner() returns(bool) { return whitelisted[_user]; } // add user to the whitelisted function removeUserFromWhitelist(address _user) public onlyOwner() { whitelisted[_user] = false; } // allows owner to pause contract function pause(bool _state) public onlyOwner { paused = _state; } // allows owner to turn on/off whitelisted buyers sale function setWhitelistBuyersOnly(bool _state) public onlyOwner { whitelistedBuyersOnly = _state; setCost(whitelistedBuyersOnly); } // function to change the price when whitelist is on function setCost(whitelistedBuyersOnly) public { if(whitelistedBuyersOnly) { cost = .0035 ether; } else { cost = .0045 ether; } } // Function thats fired every time token is sold function safeTransferFrom() external payable { if (msg.sender != owner()) { // Allows owner to sell for free require(msg.value >= cost * _feeAmount, "Please supply the proper amount of funds for minting"); // Ensures users pays cost splitFunds(cost * _feeAmount); // Splits funds after user pays. } } // allows owner to split funds to team function splitFunds(uint256 fundsToSplit) public payable { require(fundsToSplit >= address(this).balance, "Contract balance is insufficient"); require(payable(Payee1).send(fundsToSplit * 15/100)); require(payable(Payee2).send(fundsToSplit * 15/100)); require(payable(Payee3).send(fundsToSplit * 15/100)); require(payable(Payee4).send(fundsToSplit * 4/100)); require(payable(Payee5).send(fundsToSplit * 51/100)); } // Catches funds sent to contract with no call data receive() external payable { splitFunds(cost * _feeAmount); } // Catches funds sent to contract with no call data fallback() external payable { splitFunds(cost * _feeAmount); } }
0.7.1