Skip to content

Instantly share code, notes, and snippets.

@mingderwang
Last active February 11, 2024 23:39
Show Gist options
  • Save mingderwang/6009936df46d1a2cb6fcdfa334dba5c3 to your computer and use it in GitHub Desktop.
Save mingderwang/6009936df46d1a2cb6fcdfa334dba5c3 to your computer and use it in GitHub Desktop.
// 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