Skip to content

Instantly share code, notes, and snippets.

@ngmachado
Created July 4, 2022 11:23
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 ngmachado/8295a0f75b988ba6e519c216ed79aa32 to your computer and use it in GitHub Desktop.
Save ngmachado/8295a0f75b988ba6e519c216ed79aa32 to your computer and use it in GitHub Desktop.
// 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 SuperfluidETHAmsterdam22 is ERC721, ERC721URIStorage, AccessControl {
using Counters for Counters.Counter;
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
Counters.Counter private _tokenIdCounter;
constructor() ERC721("SuperfluidETHAmsterdam22", "SAMS22") {
_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