Skip to content

Instantly share code, notes, and snippets.

@matthsena
Created May 26, 2022 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthsena/21362cde23d87c920feb2cc72a8d5512 to your computer and use it in GitHub Desktop.
Save matthsena/21362cde23d87c920feb2cc72a8d5512 to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
contract CreateNFT is ERC721URIStorage {
uint256 public maxSupply = 85;
uint256 public totalSupply = 0;
struct Invite {
uint256 unity;
address owner;
string imageURI;
}
Invite[] public invites;
constructor() ERC721("Taste Residencial", "TASTE") {}
function mint(uint256 _unity, address _address, string memory tokenURI) public payable {
uint256 supply = totalSupply;
require(supply <= maxSupply);
invites.push(
Invite(_unity, _address, tokenURI)
);
totalSupply = totalSupply + 1;
_mint(_address, _unity);
_setTokenURI(_unity, tokenURI);
}
function getTokens() public view returns (Invite[] memory) {
return invites;
}
function getTokenByUnity(uint256 _unity) public view returns (Invite memory) {
Invite memory currentInvite;
for (uint256 i = 0; i < totalSupply; i ++) {
if (invites[i].unity == _unity) {
currentInvite = invites[i];
break;
}
}
return currentInvite;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment