Skip to content

Instantly share code, notes, and snippets.

@yann300
Last active February 14, 2022 13:11
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 yann300/965e9f0de20a3be6a6732c046b28e99e to your computer and use it in GitHub Desktop.
Save yann300/965e9f0de20a3be6a6732c046b28e99e to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;
import "hardhat/console.sol";
import "@openzeppelin/contracts@4.4.2/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts@4.4.2/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts@4.4.2/token/ERC721/extensions/ERC721Burnable.sol";
import "@openzeppelin/contracts@4.4.2/access/Ownable.sol";
import "@openzeppelin/contracts@4.4.2/utils/Counters.sol";
contract Remix is ERC721, ERC721Enumerable, ERC721Burnable, Ownable {
using Counters for Counters.Counter;
Counters.Counter private _tokenIdCounter;
mapping (string => bool) types;
mapping (uint => TokenData) tokensData;
mapping (address => uint) allowedMinting;
struct TokenData {
string payload;
string tokenType;
}
constructor() ERC721("Remix", "R") {
types["Educator"] = true;
types["Release Manager"] = true;
types["Team Member"] = true;
types["User"] = true;
types["Beta Tester"] = true;
types["Contributor"] = true;
}
function addType (string calldata tokenType) public onlyOwner {
types[tokenType] = true;
}
function removeType (string calldata tokenType) public onlyOwner {
delete types[tokenType];
}
function safeMint(address to, string calldata tokenType, string calldata payload, bool grantMinting) public onlyOwner {
require(types[tokenType], "type should be declared");
require(bytes(payload).length != 0, "payload can't be empty");
uint256 tokenId = _tokenIdCounter.current();
_tokenIdCounter.increment();
_safeMint(to, tokenId);
tokensData[tokenId].payload = payload;
tokensData[tokenId].tokenType = tokenType;
if (grantMinting) {
allowedMinting[to]++;
}
}
function publicMint (address to) public {
require(allowedMinting[msg.sender] > 0, "no minting allowed");
allowedMinting[msg.sender]--;
uint256 tokenId = _tokenIdCounter.current();
_tokenIdCounter.increment();
_safeMint(to, tokenId);
// tokensData[tokenId].payload = "";
tokensData[tokenId].tokenType = "User";
}
// The following functions are overrides required by Solidity.
function _beforeTokenTransfer(address from, address to, uint256 tokenId)
internal
override(ERC721, ERC721Enumerable)
{
require(from == address(0), "token not transferable");
super._beforeTokenTransfer(from, to, tokenId);
}
function supportsInterface(bytes4 interfaceId)
public
view
override(ERC721, ERC721Enumerable)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment