Last active
March 10, 2022 13:19
-
-
Save ngmachado/d94af055aae311af7e7b080b0f750d86 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
// SPDX-License-Identifier: MIT | |
pragma solidity 0.8.10; | |
import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; | |
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; | |
import "@openzeppelin/contracts/access/AccessControl.sol"; | |
import "@openzeppelin/contracts/utils/Counters.sol"; | |
contract SuperfluidEDEN2022 is ERC721, ERC721URIStorage, AccessControl { | |
using Counters for Counters.Counter; | |
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE"); | |
Counters.Counter private _tokenIdCounter; | |
constructor() ERC721("SuperfluidEDEN2022", "SDEN22") { | |
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender); | |
_grantRole(MINTER_ROLE, msg.sender); | |
_tokenIdCounter.increment(); | |
} | |
function safeMint(address to, string memory uri) public onlyRole(MINTER_ROLE) { | |
uint256 tokenId = _tokenIdCounter.current(); | |
_tokenIdCounter.increment(); | |
_safeMint(to, tokenId); | |
_setTokenURI(tokenId, uri); | |
} | |
function batchSafeMint(address to, string[] memory uris) public onlyRole(MINTER_ROLE) { | |
for(uint256 i = 0; i < uris.length; i++) { | |
safeMint(to, uris[i]); | |
} | |
} | |
function batchTransfer(address[] calldata to, uint256[] calldata tokenIds) public { | |
require(to.length == tokenIds.length, "wrong arrary size"); | |
for(uint256 i = 0; i < to.length; i++) { | |
safeTransferFrom(msg.sender, to[i], tokenIds[i]); | |
} | |
} | |
function safeTransfer(address to, uint256 tokenId) public { | |
safeTransferFrom(msg.sender, to, tokenId); | |
} | |
// The following functions are overrides required by Solidity. | |
function _burn(uint256 tokenId) internal override(ERC721, ERC721URIStorage) { | |
super._burn(tokenId); | |
} | |
function tokenURI(uint256 tokenId) | |
public | |
view | |
override(ERC721, ERC721URIStorage) | |
returns (string memory) | |
{ | |
return super.tokenURI(tokenId); | |
} | |
function supportsInterface(bytes4 interfaceId) | |
public | |
view | |
override(ERC721, AccessControl) | |
returns (bool) | |
{ | |
return super.supportsInterface(interfaceId); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment