Skip to content

Instantly share code, notes, and snippets.

@defijesus
Created December 18, 2021 20:28
Show Gist options
  • Save defijesus/68d3881a77acf55f18d46d3a9d7b6141 to your computer and use it in GitHub Desktop.
Save defijesus/68d3881a77acf55f18d46d3a9d7b6141 to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: MIT
/*
_ ΞΞΞΞ _
/_;-.__ / _\ _.-;_\
`-._`'`_/'`.-'
`\ /`
| /
/-.(
\_._\
\ \`;
> |/
/ //
|//
\(\
``
defijesus.eth
*/
pragma solidity ^0.8.2;
import "@openzeppelin/contracts@4.4.0/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts@4.4.0/access/Ownable.sol";
error NonExistantToken();
error WrongArraySize();
contract HiddenStarsClub is ERC721, Ownable {
mapping(uint256 => string) public URIs;
uint256 public currentSupply = 0;
constructor() ERC721("Hidden Stars Club", "STAR") {}
// PUBLIC
function tokenURI(uint256 tokenId) public view override returns (string memory) {
if (!_exists(tokenId)) {
revert NonExistantToken();
}
return URIs[tokenId];
}
// ONLY OWNER
function mint(string calldata url) external onlyOwner {
URIs[currentSupply] = url;
safeMint(msg.sender);
}
function mintTo(string calldata url, address to) external onlyOwner {
URIs[currentSupply] = url;
safeMint(to);
}
function mintMultiple(string[] calldata urls) external onlyOwner {
unchecked {
for (uint256 i = 0; i < urls.length; i++) {
URIs[currentSupply] = urls[i];
safeMint(msg.sender);
}
}
}
function mintMultipleTo(string[] calldata urls, address[] calldata tos) external onlyOwner {
if (urls.length != tos.length) {
revert WrongArraySize();
}
unchecked {
for (uint256 i = 0; i < urls.length; i++) {
URIs[currentSupply] = urls[i];
safeMint(tos[i]);
}
}
}
function setTokenURIs(uint256[] calldata tokenIDs, string[] calldata tokenURLs) external onlyOwner {
if (tokenIDs.length != tokenURLs.length) {
revert WrongArraySize();
}
unchecked {
for (uint256 i = 0; i < tokenIDs.length; i++) {
URIs[tokenIDs[i]] = tokenURLs[i];
}
}
}
// INTERNAL
function safeMint(address to) internal {
_safeMint(to, currentSupply);
currentSupply += 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment