Skip to content

Instantly share code, notes, and snippets.

@polluterofminds
Created August 23, 2021 15:49
Show Gist options
  • Save polluterofminds/97d68db73c2deac1b683186bd75d52c3 to your computer and use it in GitHub Desktop.
Save polluterofminds/97d68db73c2deac1b683186bd75d52c3 to your computer and use it in GitHub Desktop.
OpenZeppelin Game Item Example
// 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