Last active
December 7, 2023 17:21
-
-
Save ConnorFM/291b8cded219fafc775a3c559c2461ab to your computer and use it in GitHub Desktop.
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.20; | |
import "@openzeppelin/[email protected]/token/ERC721/ERC721.sol"; | |
import "@openzeppelin/[email protected]/token/ERC721/extensions/ERC721Enumerable.sol"; | |
import "@openzeppelin/[email protected]/token/ERC721/extensions/ERC721URIStorage.sol"; | |
import "@openzeppelin/[email protected]/token/ERC721/extensions/ERC721Burnable.sol"; | |
contract PussyWOC is | |
ERC721, | |
ERC721Enumerable, | |
ERC721URIStorage, | |
ERC721Burnable | |
{ | |
uint256 private _nextTokenId; | |
uint256 MAX_SUPPLY = 4444; | |
string private _key = ""; | |
constructor() ERC721("PussyWOC", "PCAT") {} | |
function tokenExists(uint256 tokenId) internal view returns (bool) { | |
return _ownerOf(tokenId) != address(0); | |
} | |
function safeMint( | |
address to, | |
string memory uri, | |
uint256 mintAmount, | |
string memory key | |
) public { | |
require(keccak256(abi.encodePacked(key)) == keccak256(abi.encodePacked(_key)), "Incorrect key"); | |
uint256 finalTokenId = _nextTokenId + mintAmount; | |
require(finalTokenId <= MAX_SUPPLY, "I'm sorry we reached the cap"); | |
for (uint256 i = 1; i <= mintAmount; i++) { | |
uint256 tokenId = _nextTokenId++; | |
require(tokenId <= MAX_SUPPLY, "I'm sorry we reached the cap"); | |
_safeMint(to, tokenId); | |
_setTokenURI(tokenId, uri); | |
} | |
} | |
function safeMintOne( | |
address to, | |
string memory uri, | |
uint256 tokenId, | |
string memory key | |
) public { | |
require(keccak256(abi.encodePacked(key)) == keccak256(abi.encodePacked(_key)), "Incorrect key"); | |
require(tokenId < MAX_SUPPLY, "I'm sorry we reached the cap"); | |
require(!tokenExists(tokenId), "Token ID already exists"); | |
_safeMint(to, tokenId); | |
_setTokenURI(tokenId, uri); | |
if (tokenId >= _nextTokenId) { | |
_nextTokenId = tokenId + 1; | |
} | |
} | |
function setKey(string memory newKey) public onlyOwner { | |
_key = newKey; | |
} | |
// The following functions are overrides required by Solidity. | |
function _update( | |
address to, | |
uint256 tokenId, | |
address auth | |
) internal override(ERC721, ERC721Enumerable) returns (address) { | |
return super._update(to, tokenId, auth); | |
} | |
function _increaseBalance( | |
address account, | |
uint128 value | |
) internal override(ERC721, ERC721Enumerable) { | |
super._increaseBalance(account, value); | |
} | |
function tokenURI( | |
uint256 tokenId | |
) public view override(ERC721, ERC721URIStorage) returns (string memory) { | |
return super.tokenURI(tokenId); | |
} | |
function supportsInterface( | |
bytes4 interfaceId | |
) | |
public | |
view | |
override(ERC721, ERC721Enumerable, ERC721URIStorage) | |
returns (bool) | |
{ | |
return super.supportsInterface(interfaceId); | |
} | |
} |
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.20; | |
import "@openzeppelin/[email protected]/token/ERC721/ERC721.sol"; | |
import "@openzeppelin/[email protected]/token/ERC721/extensions/ERC721Enumerable.sol"; | |
import "@openzeppelin/[email protected]/token/ERC721/extensions/ERC721URIStorage.sol"; | |
import "@openzeppelin/[email protected]/token/ERC721/extensions/ERC721Burnable.sol"; | |
import "@openzeppelin/[email protected]/access/Ownable.sol"; | |
contract PussyWOC is | |
ERC721, | |
ERC721Enumerable, | |
ERC721URIStorage, | |
ERC721Burnable, | |
Ownable | |
{ | |
uint256 private _nextTokenId; | |
uint256 MAX_SUPPLY = 4444; | |
string private _key = ""; | |
string private baseTokenURI; | |
constructor(address initialOwner) | |
ERC721("PussyWOCTest", "PCATTest") | |
Ownable(initialOwner) | |
{} | |
function tokenExists(uint256 tokenId) internal view returns (bool) { | |
return _ownerOf(tokenId) != address(0); | |
} | |
function safeMint( | |
address to, | |
uint256 mintAmount, | |
string memory key | |
) public { | |
require( | |
keccak256(abi.encodePacked(key)) == | |
keccak256(abi.encodePacked(_key)), | |
"Incorrect key" | |
); | |
uint256 finalTokenId = _nextTokenId + mintAmount; | |
require(finalTokenId <= MAX_SUPPLY, "I'm sorry we reached the cap"); | |
for (uint256 i = 1; i <= mintAmount; i++) { | |
uint256 tokenId = _nextTokenId++; | |
require(tokenId <= MAX_SUPPLY, "I'm sorry we reached the cap"); | |
_safeMint(to, tokenId); | |
_setTokenURI(tokenId, tokenURI(tokenId)); | |
} | |
} | |
function safeMintOne( | |
address to, | |
string memory uri, | |
uint256 tokenId, | |
string memory key | |
) public onlyOwner { | |
require( | |
keccak256(abi.encodePacked(key)) == | |
keccak256(abi.encodePacked(_key)), | |
"Incorrect key" | |
); | |
require(tokenId < MAX_SUPPLY, "I'm sorry we reached the cap"); | |
require(!tokenExists(tokenId), "Token ID already exists"); | |
_safeMint(to, tokenId); | |
_setTokenURI(tokenId, uri); | |
if (tokenId >= _nextTokenId) { | |
_nextTokenId = _nextTokenId + 1; | |
} | |
} | |
function tokenURI(uint256 tokenId) public view override(ERC721, ERC721URIStorage) returns (string memory) { | |
require(tokenExists(tokenId), "Token does not exist"); | |
string memory json = ".json"; | |
string memory tokenIdStr = Strings.toString(tokenId); | |
return string(abi.encodePacked(baseTokenURI, '/', tokenIdStr, json)); | |
} | |
function setTokenURI(uint256 tokenId, string memory newURI) | |
public | |
onlyOwner | |
{ | |
require(tokenExists(tokenId), "Token does not exist"); | |
_setTokenURI(tokenId, newURI); | |
emit TokenURIUpdated(tokenId, newURI); | |
} | |
event TokenURIUpdated(uint256 indexed tokenId, string newURI); | |
function setKey(string memory newKey) public onlyOwner { | |
_key = newKey; | |
} | |
function setBaseURI(string memory newBaseURI) external onlyOwner { | |
baseTokenURI = newBaseURI; | |
} | |
// The following functions are overrides required by Solidity. | |
function _update( | |
address to, | |
uint256 tokenId, | |
address auth | |
) internal override(ERC721, ERC721Enumerable) returns (address) { | |
return super._update(to, tokenId, auth); | |
} | |
function _increaseBalance(address account, uint128 value) | |
internal | |
override(ERC721, ERC721Enumerable) | |
{ | |
super._increaseBalance(account, value); | |
} | |
function supportsInterface(bytes4 interfaceId) | |
public | |
view | |
override(ERC721, ERC721Enumerable, ERC721URIStorage) | |
returns (bool) | |
{ | |
return super.supportsInterface(interfaceId); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment