Created
February 16, 2025 07:02
-
-
Save lainhathoang/3c0746d4f3ad7d43883794f18ace004c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // SPDX-License-Identifier: MIT | |
| // Compatible with OpenZeppelin Contracts ^5.0.0 | |
| pragma solidity =0.8.20; | |
| import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; | |
| import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol"; | |
| import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; | |
| import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Pausable.sol"; | |
| import "@openzeppelin/contracts/access/Ownable.sol"; | |
| import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol"; | |
| contract MyNFT is ERC721, ERC721Enumerable, ERC721URIStorage, ERC721Pausable, Ownable, ERC721Burnable { | |
| uint256 private _nextTokenId; | |
| constructor(address initialOwner) ERC721("MyNFT", "MTK") Ownable(initialOwner) {} | |
| function pause() public onlyOwner { | |
| _pause(); | |
| } | |
| function unpause() public onlyOwner { | |
| _unpause(); | |
| } | |
| function safeMint(address to, string memory uri) public onlyOwner { | |
| uint256 tokenId = _nextTokenId++; | |
| _safeMint(to, tokenId); | |
| _setTokenURI(tokenId, uri); | |
| } | |
| // The following functions are overrides required by Solidity. | |
| function _update( | |
| address to, | |
| uint256 tokenId, | |
| address auth | |
| ) internal override(ERC721, ERC721Enumerable, ERC721Pausable) returns (address) { | |
| return super._update(to, tokenId, auth); | |
| } | |
| function _increaseBalance(address account, uint128 value) internal override(ERC721, ERC721Enumerable) { | |
| super._increaseBalance(account, value); | |
| } | |
| function tokenURI(uint256 tokenId) public view override(ERC721, ERC721URIStorage) returns (string memory) { | |
| return super.tokenURI(tokenId); | |
| } | |
| function supportsInterface( | |
| bytes4 interfaceId | |
| ) public view override(ERC721, ERC721Enumerable, ERC721URIStorage) returns (bool) { | |
| return super.supportsInterface(interfaceId); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment