Skip to content

Instantly share code, notes, and snippets.

@jakzaizzat
Created August 17, 2022 07:07
Show Gist options
  • Save jakzaizzat/ff7ab6c1ffda6220e0e391348315c330 to your computer and use it in GitHub Desktop.
Save jakzaizzat/ff7ab6c1ffda6220e0e391348315c330 to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/interfaces/IERC2981.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/utils/Address.sol";
contract ORCTownRoad is ERC721, IERC2981, ReentrancyGuard, Ownable {
using Counters for Counters.Counter;
constructor(string memory customBaseURI_) ERC721("ORC Town Road", "OTR") {
customBaseURI = customBaseURI_;
}
/** MINTING LIMITS **/
mapping(address => uint256) private mintCountMap;
mapping(address => uint256) private allowedMintCountMap;
uint256 public constant MINT_LIMIT_PER_WALLET = 2;
function allowedMintCount(address minter) public view returns (uint256) {
return MINT_LIMIT_PER_WALLET - mintCountMap[minter];
}
function updateMintCount(address minter, uint256 count) private {
mintCountMap[minter] += count;
}
/** MINTING **/
uint256 public constant MAX_SUPPLY = 6969;
uint256 public constant MAX_MULTIMINT = 2;
Counters.Counter private supplyCounter;
function mint(uint256 count) public nonReentrant {
require(saleIsActive, "Sale not active");
if (allowedMintCount(msg.sender) >= count) {
updateMintCount(msg.sender, count);
} else {
revert("Minting limit exceeded");
}
require(totalSupply() + count - 1 < MAX_SUPPLY, "Exceeds max supply");
require(count <= MAX_MULTIMINT, "Mint at most 2 at a time");
for (uint256 i = 0; i < count; i++) {
_mint(msg.sender, totalSupply());
supplyCounter.increment();
}
}
function totalSupply() public view returns (uint256) {
return supplyCounter.current();
}
/** ACTIVATION **/
bool public saleIsActive = false;
function setSaleIsActive(bool saleIsActive_) external onlyOwner {
saleIsActive = saleIsActive_;
}
/** URI HANDLING **/
string private customBaseURI;
function setBaseURI(string memory customBaseURI_) external onlyOwner {
customBaseURI = customBaseURI_;
}
function _baseURI() internal view virtual override returns (string memory) {
return customBaseURI;
}
function tokenURI(uint256 tokenId) public view override
returns (string memory)
{
return string(abi.encodePacked(super.tokenURI(tokenId), ".json"));
}
/** PAYOUT **/
function withdraw() public nonReentrant {
uint256 balance = address(this).balance;
Address.sendValue(payable(owner()), balance);
}
/** ROYALTIES **/
function royaltyInfo(uint256, uint256 salePrice) external view override
returns (address receiver, uint256 royaltyAmount)
{
return (address(this), (salePrice * 750) / 10000);
}
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(ERC721, IERC165)
returns (bool)
{
return (
interfaceId == type(IERC2981).interfaceId ||
super.supportsInterface(interfaceId)
);
}
}
// Contract created with Studio 721 v1.5.0
// https://721.so
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment