Last active
February 11, 2024 23:39
-
-
Save mingderwang/6009936df46d1a2cb6fcdfa334dba5c3 to your computer and use it in GitHub Desktop.
https://wizard.openzeppelin.com/#erc721 and https://docs.openzeppelin.com/contracts/4.x/erc721#constructing_an_erc721_token_contract
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
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.20; | |
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; | |
import "@openzeppelin/contracts/access/Ownable.sol"; | |
import "@openzeppelin/contracts/utils/Counters.sol"; | |
/// @custom:security-contact mingderwang@me.com | |
contract My721Token is ERC721URIStorage, Ownable { | |
uint256 private _nextTokenId; | |
using Counters for Counters.Counter; | |
Counters.Counter private _tokenIds; | |
constructor(address initialOwner) | |
ERC721("My 721 Token", "M721") | |
Ownable(initialOwner) | |
{} | |
function _baseURI() internal pure override returns (string memory) { | |
return "https://m721.muzamint.com/"; | |
} | |
function safeMint(address to) public onlyOwner { | |
uint256 tokenId = _nextTokenId++; | |
_safeMint(to, tokenId); | |
} | |
function awardItem(address player, string memory tokenURI) | |
public | |
returns (uint256) | |
{ | |
uint256 newItemId = _tokenIds.current(); | |
_mint(player, newItemId); | |
_setTokenURI(newItemId, tokenURI); | |
_tokenIds.increment(); | |
return newItemId; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment