Skip to content

Instantly share code, notes, and snippets.

Last active Jun 16, 2021
What would you like to do?
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) {
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