Skip to content

Instantly share code, notes, and snippets.

@aeither
Last active September 25, 2021 12:22
Show Gist options
  • Save aeither/ad2f80dcd185ec1c06929aac4f2038ce to your computer and use it in GitHub Desktop.
Save aeither/ad2f80dcd185ec1c06929aac4f2038ce to your computer and use it in GitHub Desktop.
Basic NFT contract
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import 'https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Counters.sol';
import 'https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/extensions/ERC721URIStorage.sol';
import 'https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol';
contract GameItem is ERC721URIStorage, Ownable {
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;
}
function mint(address _to) public onlyOwner {
super._mint(_to, _tokenIds.current());
_tokenIds.increment();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment