// SPDX-License-Identifier: MIT pragma solidity 0.8.24; import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol"; import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; /// @title Elysium City Studio NFT collection: public mint at a fixed price up to a max supply. contract StudioNFT is ERC721, Ownable, ReentrancyGuard { uint256 public immutable maxSupply; uint256 public immutable price; uint256 public immutable maxPerTx; uint256 public totalSupply; string private baseURI_; error SoldOut(); error WrongPayment(); error TooMany(); constructor(string memory name_, string memory symbol_, uint256 maxSupply_, uint256 price_, uint256 maxPerTx_, string memory baseURI, address owner_) ERC721(name_, symbol_) Ownable(owner_) { require(maxSupply_ > 0, "max supply"); maxSupply = maxSupply_; price = price_; maxPerTx = maxPerTx_ == 0 ? maxSupply_ : maxPerTx_; baseURI_ = baseURI; } function mint(uint256 quantity) external payable nonReentrant { if (quantity == 0 || quantity > maxPerTx) revert TooMany(); if (totalSupply + quantity > maxSupply) revert SoldOut(); if (msg.value != price * quantity) revert WrongPayment(); for (uint256 i; i < quantity; ++i) { _safeMint(msg.sender, ++totalSupply); } } function setBaseURI(string calldata uri) external onlyOwner { baseURI_ = uri; } function withdraw(address payable to) external onlyOwner nonReentrant { require(to != address(0), "zero address"); (bool ok,) = to.call{value: address(this).balance}(""); require(ok, "withdraw failed"); } function _baseURI() internal view override returns (string memory) { return baseURI_; } }