Created
February 27, 2022 08:06
-
-
Save marosc/1df5e73f1fcec6a2316a13c0e0f63d02 to your computer and use it in GitHub Desktop.
Sample OpenZeppelin NFT
This file contains 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
pragma solidity ^0.8.0; | |
import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; | |
import "@openzeppelin/contracts/security/Pausable.sol"; | |
import "@openzeppelin/contracts/access/Ownable.sol"; | |
import "@openzeppelin/contracts/utils/Counters.sol"; | |
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; | |
contract MyNFT is ERC721URIStorage, Pausable, Ownable { | |
using Counters for Counters.Counter; | |
string local_baseURI; | |
Counters.Counter private _tokenIdCounter; | |
constructor() ERC721("MPage's NFT", "MPSK") { | |
_tokenIdCounter.increment(); | |
local_baseURI = "https://nft.mpage.sk/meta.php?n="; | |
} | |
function _baseURI() internal view override returns (string memory) { | |
return local_baseURI; | |
} | |
function changeBaseURI(string memory baseURI) public onlyOwner { | |
local_baseURI = baseURI; | |
} | |
function totalSupply() view public returns(uint){ | |
return _tokenIdCounter.current()-1; | |
} | |
function ownerOfToken(uint id) view public returns(bool){ | |
return ownerOfToken(id); | |
} | |
function pause() public onlyOwner { | |
_pause(); | |
} | |
function unpause() public onlyOwner { | |
_unpause(); | |
} | |
function safeMint() public { | |
_safeMint(msg.sender, _tokenIdCounter.current()); | |
_tokenIdCounter.increment(); | |
} | |
function changeTokenURI(string memory uri, uint id) public onlyOwner { | |
_setTokenURI(id,uri); | |
} | |
function _beforeTokenTransfer(address from, address to, uint256 tokenId) | |
internal | |
whenNotPaused | |
override | |
{ | |
super._beforeTokenTransfer(from, to, tokenId); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment