Untitled
unknown
plain_text
2 years ago
2.5 kB
5
Indexable
// SPDX-License-Identifier: MIT pragma solidity ^0.8.9; import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; import "@openzeppelin/contracts/interfaces/IERC2981.sol"; import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/utils/Counters.sol"; contract MAGNETNFT is ERC721, ERC721URIStorage, ERC721Burnable, Ownable, IERC2981 { using Counters for Counters.Counter; Counters.Counter private _tokenIdCounter; constructor() ERC721("MAGNETNFT", "MNFT") {} function safeMint(address to, string memory uri, uint256 royaltyPercent) public onlyOwner { uint256 tokenId = _tokenIdCounter.current(); _tokenIdCounter.increment(); _safeMint(to, tokenId); _setTokenURI(tokenId, uri); _setRoyalty(newTokenId, royaltyPercentage); } //supporting IERC2981 interface function supportsInterface(bytes4 interfaceId) public view override(IERC2981) returns (bool) { return super.supportsInterface(interfaceId); } // The following functions are overrides required by Solidity. function _burn(uint256 tokenId) internal override(ERC721, ERC721URIStorage) { super._burn(tokenId); } //onlyOwner callable self destruction function impl function selfDestroy() public onlyOwner { selfdestruct(payable(msg.sender)); } function tokenURI(uint256 tokenId) public view override(ERC721, ERC721URIStorage) returns (string memory) { return super.tokenURI(tokenId); } function royaltyInfo(uint256 tokenId, uint256 value) public view returns (address receiver, uint256 royaltyAmount) { // Get the creator of the token address creator = ownerOf(tokenId); // Calculate the royalty amount as 10% of the value uint256 _royaltyAmount = value / 10; return (creator, _royaltyAmount); } function royaltyFeeUpdate (uint256 tokenId, uint256 value, uint256 rate) public view returns ( uint256 royaltyAmount) { require(_msgSender() == ownerOf(_tokenId), "Only the owner can update royalty fee"); // Get the creator of the token address creator = ownerOf(tokenId); uint256 _royaltyAmount = value / rate; return (creator, _royaltyAmount); } }
Editor is loading...