-
-
Save Azarch1/785508cd5ab1afbeb3477073c1ac3382 to your computer and use it in GitHub Desktop.
This file contains 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
pragma solidity ^0.8.0; | |
import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; | |
import "@openzeppelin/contracts/utils/Counters.sol"; | |
contract DropToken is ERC721 { | |
using Counters for Counters.Counter; | |
Counters.Counter private _tokenIds; | |
constructor() ERC721("DropTicket", "DRT") {} | |
struct Item { | |
uint256 id; | |
address creator; | |
string uri; | |
} | |
uint256 newItemId; | |
mapping(uint256 => Item) public Items; | |
function createItem(string memory uri) public returns (uint256) { | |
_tokenIds.increment(); | |
newItemId = _tokenIds.current(); | |
_safeMint(msg.sender, newItemId); | |
Items[newItemId] = Item(newItemId, msg.sender, uri); | |
return newItemId; | |
} | |
// prettier-ignore | |
function tokenURI(uint256 tokenId)public view override returns (string memory){ | |
require(_exists(tokenId),"ERC721Metadata: URI query for nonexistent token"); | |
return Items[newItemId].uri; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment