This contract's source code is verified! Compiler
0.7.6+commit.7338295f
File 1 of 15: Address.sol
File 2 of 15: C168.sol
pragma solidity 0.7.6;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.3.0/contracts/token/ERC721/ERC721.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.3.0/contracts/access/Ownable.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.3.0/contracts/math/SafeMath.sol";
contract Collective168 is ERC721, Ownable {
using SafeMath for uint256;
uint256 constant public TOTAL_TOKEN_TO_MINT = 1550;
uint256 constant public OWNER_MINT = 50;
uint256 constant public ITEM_PRICE = 0.05 ether;
uint256 public mintedTokens;
uint256 public startingIpfsId;
uint256 private _lastIpfsId;
bool public isSaleActive;
bool public ownerMinted;
uint256 public limitPerWallet = 5;
address immutable public FUND_WALLET;
mapping(address => uint256) public minted;
constructor (string memory _tokenBaseUri, address _fundWallet) ERC721("Collective 168", "C168-GA1") {
_setBaseURI(_tokenBaseUri);
FUND_WALLET = _fundWallet;
}
function mintTokenOwner() external onlyOwner {
require(!ownerMinted, "Collective168: Owner has already minted");
for (uint256 i = 1; i <= OWNER_MINT; i++) {
require(!_exists(mintedTokens), "Collective168: Token already exist.");
_mint(_msgSender(), i);
}
mintedTokens = mintedTokens + OWNER_MINT;
ownerMinted = true;
}
function mintToken(uint256 _howMany) external payable {
require(isSaleActive, "Collective168: Sale is not active");
require(_howMany > 0, "Collective168: Minimum 1 tokens need to be minted");
require(_howMany <= tokenRemainingToBeMinted(), "Collective168: Mint amount is greater than the token available");
require(ITEM_PRICE.mul(_howMany) == msg.value, "Collective168: Insufficient ETH to mint");
require(minted[_msgSender()] <= limitPerWallet, "Collective168: Max limit exceeds");
require(!_isContract(msg.sender), "Collective168: Caller cannot be contract");
for (uint256 i = 0; i < _howMany; i++) {
_mintToken(_msgSender());
minted[_msgSender()]++;
require(minted[_msgSender()] <= limitPerWallet, "Collective168: Max limit exceeds");
}
}
function _isContract(address _addr) private view returns (bool) {
uint32 _size;
assembly {
_size := extcodesize(_addr)
}
return (_size > 0);
}
function _mintToken(address _to) private {
if(mintedTokens == 50) {
_lastIpfsId = random(51, TOTAL_TOKEN_TO_MINT, uint256(uint160(address(_msgSender()))) + 1);
startingIpfsId = _lastIpfsId;
} else {
_lastIpfsId = getIpfsIdToMint();
}
mintedTokens++;
require(!_exists(mintedTokens), "Collective168: Token already exist.");
_mint(_to, mintedTokens);
_setTokenURI(mintedTokens, uint2str(_lastIpfsId));
}
function uint2str(uint256 _i) private pure returns (string memory _uintAsString) {
if (_i == 0) {
return "0";
}
uint256 j = _i;
uint256 len;
while (j != 0) {
len++;
j /= 10;
}
bytes memory bstr = new bytes(len);
uint256 k = len;
while (_i != 0) {
k = k - 1;
uint8 temp = (48 + uint8(_i - (_i / 10) * 10));
bytes1 b1 = bytes1(temp);
bstr[k] = b1;
_i /= 10;
}
return string(bstr);
}
function burn(uint256 tokenId) public {
require(_exists(tokenId), "Collective168: token does not exist.");
require(_isApprovedOrOwner(_msgSender(), tokenId), "Collective168: caller is not owner nor approved");
_burn(tokenId);
}
function exists(uint256 _tokenId) external view returns (bool) {
return _exists(_tokenId);
}
function tokenRemainingToBeMinted() public view returns (uint256) {
return TOTAL_TOKEN_TO_MINT.sub(mintedTokens);
}
function isAllTokenMinted() public view returns (bool) {
return mintedTokens == TOTAL_TOKEN_TO_MINT;
}
function getIpfsIdToMint() private view returns(uint256 _nextIpfsId) {
require(!isAllTokenMinted(), "All tokens have been minted");
if(_lastIpfsId == TOTAL_TOKEN_TO_MINT && mintedTokens < TOTAL_TOKEN_TO_MINT) {
_nextIpfsId = 51;
} else if(mintedTokens < TOTAL_TOKEN_TO_MINT) {
_nextIpfsId = _lastIpfsId + 1;
}
}
function isApprovedOrOwner(address _spender, uint256 _tokenId) external view returns (bool) {
return _isApprovedOrOwner(_spender, _tokenId);
}
function random(
uint256 from,
uint256 to,
uint256 salty
) private view returns (uint256) {
uint256 seed =
uint256(
keccak256(
abi.encodePacked(
block.timestamp +
block.difficulty +
((uint256(keccak256(abi.encodePacked(block.coinbase)))) / (block.timestamp)) +
block.gaslimit +
((uint256(keccak256(abi.encodePacked(_msgSender())))) / (block.timestamp)) +
block.number +
salty
)
)
);
return seed.mod(to - from) + from;
}
function stopSale() external onlyOwner {
isSaleActive = false;
}
function startSale() external onlyOwner {
isSaleActive = true;
}
function changeWalletLimit(uint256 _limitPerWallet) external onlyOwner {
limitPerWallet = _limitPerWallet;
}
function withdrawETH(uint256 _amount) external onlyOwner {
payable(FUND_WALLET).transfer(_amount);
}
function setTokenURI(uint256 _tokenId, string memory _uri) external onlyOwner {
_setTokenURI(_tokenId, _uri);
}
function setBaseURI(string memory _baseURI) external onlyOwner {
_setBaseURI(_baseURI);
}
function _beforeTokenTransfer(address _from, address _to, uint256 _tokenId) internal virtual override(ERC721) {
super._beforeTokenTransfer(_from, _to, _tokenId);
}
}
File 3 of 15: Context.sol
File 6 of 15: EnumerableMap.sol
File 7 of 15: EnumerableSet.sol
File 8 of 15: IERC165.sol
File 9 of 15: IERC721.sol
File 10 of 15: IERC721Enumerable.sol
File 11 of 15: IERC721Metadata.sol
File 12 of 15: IERC721Receiver.sol
File 13 of 15: Ownable.sol
File 14 of 15: SafeMath.sol
File 15 of 15: Strings.sol
{
"compilationTarget": {
"C168.sol": "Collective168"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"string","name":"_tokenBaseUri","type":"string"},{"internalType":"address","name":"_fundWallet","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[],"name":"FUND_WALLET","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ITEM_PRICE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"OWNER_MINT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TOTAL_TOKEN_TO_MINT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"baseURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"burn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_limitPerWallet","type":"uint256"}],"name":"changeWalletLimit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"exists","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isAllTokenMinted","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_spender","type":"address"},{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"isApprovedOrOwner","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isSaleActive","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"limitPerWallet","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_howMany","type":"uint256"}],"name":"mintToken","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"mintTokenOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"minted","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"mintedTokens","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ownerMinted","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_baseURI","type":"string"}],"name":"setBaseURI","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"string","name":"_uri","type":"string"}],"name":"setTokenURI","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"startSale","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"startingIpfsId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"stopSale","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"tokenByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"tokenOfOwnerByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokenRemainingToBeMinted","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"withdrawETH","outputs":[],"stateMutability":"nonpayable","type":"function"}]