Skip to content

Instantly share code, notes, and snippets.

@fassko
Created March 23, 2022 19:59
Show Gist options
  • Save fassko/9da3f651721f6361ce90525cc8d9b37b to your computer and use it in GitHub Desktop.
Save fassko/9da3f651721f6361ce90525cc8d9b37b 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.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
//SPDX-License-Identifier: Unlicensed
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";
contract NFTTallinnTicket is ERC721URIStorage {
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
constructor() ERC721("NFTTallin", "NFTL") {}
function creatTicket(address visitor, string memory tokenURI)
public
returns (uint256)
{
_tokenIds.increment();
uint256 newItemId = _tokenIds.current();
_mint(visitor, newItemId);
_setTokenURI(newItemId, tokenURI);
return newItemId;
}
}
/**
{
"name": "NFT Tallinn",
"description": "NFT Tallinn aims to connect NFT creators, collectors and other web3 industry pioneers.",
"image": "https://nfttallinn.ee/ticket-hfn84n.png",
"ticketType": "regular"
}
{
"name": "NFT Tallinn",
"description": "NFT Tallinn aims to connect NFT creators, collectors and other web3 industry pioneers.",
"image": "https://nfttallinn.ee/ticket-hfn84n.png",
"ticketType": "vip"
}
**/
enum TicketType {
Regular,
VIP
}
struct Ticket {
uint256 id;
TicketType ticketType;
}
contract NFTTallinn {
mapping(address => Ticket) private tickets;
NFTTallinnTicket private nftTallinnTicket;
constructor(NFTTallinnTicket _nftTallinnTicket) {
nftTallinnTicket = _nftTallinnTicket;
}
function createTicket(address _address, TicketType ticketType) external {
uint256 ticketId = nftTallinnTicket.creatTicket(_address, "http://nft.tallinn");
tickets[_address] = Ticket({
id: ticketId,
ticketType: ticketType
});
}
function getMyTickets() external view returns (Ticket memory) {
// check if ticket exists
return tickets[msg.sender];
}
function checkEntrance(address _address, uint256 ticketId) external view returns(bool) {
return nftTallinnTicket.ownerOf(ticketId) == _address;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment