Created
August 23, 2021 15:49
-
-
Save polluterofminds/97d68db73c2deac1b683186bd75d52c3 to your computer and use it in GitHub Desktop.
OpenZeppelin Game Item Example
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
// contracts/GameItem.sol | |
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; | |
import "@openzeppelin/contracts/utils/Counters.sol"; | |
contract GameItem is ERC721URIStorage { | |
using Counters for Counters.Counter; | |
Counters.Counter private _tokenIds; | |
constructor() ERC721("GameItem", "ITM") {} | |
function awardItem(address player, string memory tokenURI) | |
public | |
returns (uint256) | |
{ | |
_tokenIds.increment(); | |
uint256 newItemId = _tokenIds.current(); | |
_mint(player, newItemId); | |
_setTokenURI(newItemId, tokenURI); | |
return newItemId; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment