Contract Source Code:
File 1 of 1 : FixedSupplyNFT.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.24; contract FixedSupplyNFT { uint256 public constant MAX_SUPPLY = 10000; // Максимальный supply uint256 public totalMinted; // Текущее количество сминченных токенов address public owner; mapping(uint256 => address) private tokenOwners; // Хранение владельцев токенов mapping(address => uint256[]) private ownedTokens; // Хранение токенов, принадлежащих владельцу event Mint(address indexed to, uint256 tokenId); event Transfer(address indexed from, address indexed to, uint256 tokenId); event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); modifier onlyOwner() { require(msg.sender == owner, "Not the owner"); _; } constructor() { owner = msg.sender; totalMinted = 0; } function mint(address to) external onlyOwner { require(totalMinted < MAX_SUPPLY, "Max supply reached"); require(to != address(0), "Invalid address"); totalMinted++; uint256 tokenId = totalMinted; tokenOwners[tokenId] = to; ownedTokens[to].push(tokenId); emit Mint(to, tokenId); } function transfer(address to, uint256 tokenId) external { require(tokenOwners[tokenId] == msg.sender, "Not the token owner"); require(to != address(0), "Invalid address"); // Удаляем токен у текущего владельца uint256[] storage tokens = ownedTokens[msg.sender]; for (uint256 i = 0; i < tokens.length; i++) { if (tokens[i] == tokenId) { tokens[i] = tokens[tokens.length - 1]; tokens.pop(); break; } } // Переводим токен новому владельцу tokenOwners[tokenId] = to; ownedTokens[to].push(tokenId); emit Transfer(msg.sender, to, tokenId); } function tokensOfOwner(address _owner) external view returns (uint256[] memory) { return ownedTokens[_owner]; } function ownerOf(uint256 tokenId) external view returns (address) { return tokenOwners[tokenId]; } function transferOwnership(address newOwner) external onlyOwner { require(newOwner != address(0), "Invalid new owner address"); emit OwnershipTransferred(owner, newOwner); owner = newOwner; } // Позволяет контракту получать эфир receive() external payable {} function withdraw() external onlyOwner { uint256 balance = address(this).balance; require(balance > 0, "No funds to withdraw"); (bool success, ) = payable(owner).call{value: balance}(""); require(success, "Transfer failed"); } }
Please enter a contract address above to load the contract details and source code.
Please DO NOT store any passwords or private keys here. A private note (up to 100 characters) can be saved and is useful for transaction tracking.
This website uses cookies to improve your experience. By continuing to use this website, you agree to its Terms and Privacy Policy.