-
Notifications
You must be signed in to change notification settings - Fork 0
/
ERC721General.sol
124 lines (109 loc) · 3.87 KB
/
ERC721General.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
pragma solidity >=0.8.7;
pragma experimental ABIEncoderV2;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
contract Reddio721General is ERC721Enumerable, ERC721URIStorage, AccessControl {
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");
string _baseTokenURI;
bool _publicMint;
constructor(string memory name_, string memory symbol_, address owner , bool publicMint, string memory baseURI)
ERC721(name_, symbol_)
{
_setupRole(ADMIN_ROLE, owner);
_setupRole(MINTER_ROLE, owner);
_publicMint = publicMint;
_baseTokenURI = baseURI;
}
/**
* @dev Function to mint tokens.
* @param to The address that will receive the minted tokens.
* @param tokenId The token id to mint.
* @param uri The token URI of the minted token.
* @return A boolean that indicates if the operation was successful.
*/
function mintWithTokenURI(
address to,
uint256 tokenId,
string memory uri
) public returns (bool) {
if (!_publicMint) {
require(
hasRole(MINTER_ROLE, _msgSender()),
"ReddioGeneral721: must have minter role to mint"
);
}
_safeMint(to, tokenId);
_setTokenURI(tokenId, uri);
return true;
}
function _baseURI() internal view virtual override returns (string memory) {
return _baseTokenURI;
}
function setBaseURI(string memory baseURI) public {
require(
hasRole(ADMIN_ROLE, _msgSender()),
"ReddioGeneral721: must have admin role"
);
_baseTokenURI = baseURI;
}
/**
* @dev Function to mint tokens. This helper function allows to mint multiple NFTs in 1 transaction.
* @param to The address that will receive the minted tokens.
* @param tokenId The token id to mint.
* @param uri The token URI of the minted token.
* @return A boolean that indicates if the operation was successful.
*/
function mintMultiple(
address[] memory to,
uint256[] memory tokenId,
string[] memory uri
) public returns (bool) {
if (!_publicMint) {
require(
hasRole(MINTER_ROLE, _msgSender()),
"ReddioGeneral721: must have minter role to mint"
);
}
for (uint256 i = 0; i < to.length; i++) {
_safeMint(to[i], tokenId[i]);
_setTokenURI(tokenId[i], uri[i]);
}
return true;
}
function safeTransfer(address to, uint256 tokenId, bytes calldata data) public virtual {
super._safeTransfer(_msgSender(), to, tokenId, data);
}
function safeTransfer(address to, uint256 tokenId) public virtual {
super._safeTransfer(_msgSender(), to, tokenId, "");
}
function _beforeTokenTransfer(address from, address to, uint256 tokenId)
internal
override(ERC721, ERC721Enumerable)
{
super._beforeTokenTransfer(from, 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, ERC721Enumerable, AccessControl)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
}