Skip to content

Instantly share code, notes, and snippets.

@EtherTyper
Created February 14, 2022 23:07
Show Gist options
  • Save EtherTyper/90b7e3340a64008b32dd71a5639d6aaf to your computer and use it in GitHub Desktop.
Save EtherTyper/90b7e3340a64008b32dd71a5639d6aaf to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.12-nightly.2022.2.10+commit.1210c3e6.js&optimize=false&runs=200&gist=
// 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") {
awardItem(0x9b78dcf2FF15C32F1E33673268e5aC0f5270DA95, "https://i.ytimg.com/vi/eMonGZEB0Ik/maxresdefault.jpg");
}
function awardItem(address player, string memory tokenURI)
private
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