-
Notifications
You must be signed in to change notification settings - Fork 1
/
contract.sol
259 lines (196 loc) · 8.02 KB
/
contract.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
// SPDX-License-Identifier: MIT
// Developer - ReservedSnow(https://linktr.ee/reservedsnow)
/*
___. __________ .____________
\_ |__ ___.__. \______ \ ____ ______ ______________ __ ____ __| _/ _____/ ____ ______ _ __
| __ < | | | _// __ \ / ___// __ \_ __ \ \/ // __ \ / __ |\_____ \ / \ / _ \ \/ \/ /
| \_\ \___ | | | \ ___/ \___ \\ ___/| | \/\ /\ ___// /_/ |/ \ | ( <_> ) /
|___ / ____| |____|_ /\___ >____ >\___ >__| \_/ \___ >____ /_______ /___| /\____/ \/\_/
\/\/ \/ \/ \/ \/ \/ \/ \/ \/
*/
/**
!Disclaimer!
please review this code on your own before using any of
the following code for production.
ReservedSnow will not be liable in any way if for the use
of the code. That being said, the code has been tested
to the best of the developers' knowledge to work as intended.
If you find any problems please let the dev know in order to improve
the contract and fix vulnerabilities if there is one.
YOU ARE NOT ALLOWED TO SELL IT
*/
import 'operator-filter-registry/src/DefaultOperatorFilterer.sol';
import '@openzeppelin/contracts/security/ReentrancyGuard.sol';
import '@openzeppelin/contracts/access/Ownable.sol';
import '@openzeppelin/contracts/utils/Strings.sol';
import 'erc721a/contracts/ERC721A.sol';
pragma solidity >=0.8.17 <0.9.0;
contract SampleERC721a is ERC721A, Ownable, ReentrancyGuard, DefaultOperatorFilterer {
using Strings for uint256;
// ================== Variables Start =======================
// reveal uri - set it in contructor
string internal uri;
string public uriSuffix = ".json";
// hidden uri - replace it with yours
string public hiddenMetadataUri = "ipfs://CID/filename.json";
// prices - replace it with yours
uint256 public price = 0.002 ether;
// supply - replace it with yours
uint256 public supplyLimit = 10000;
// max per tx - replace it with yours
uint256 public maxMintAmountPerTx = 5;
// max per wallet - replace it with yours
uint256 public maxLimitPerWallet = 2;
// enabled
bool public publicSale = false;
// reveal
bool public revealed = false;
// mapping to keep track
mapping(address => uint256) public publicMintCount;
// total mint trackers
uint256 public publicMinted;
// ================== Variables End =======================
// ================== Constructor Start =======================
// Token NAME and SYMBOL - Replace it with yours
constructor(
string memory _uri
) ERC721A("NAME", "SYMBOL") {
seturi(_uri);
}
// ================== Constructor End =======================
// ================== Mint Functions Start =======================
function PublicMint(uint256 _mintAmount) public payable {
// Normal requirements
require(publicSale, 'The PublicSale is paused!');
require(_mintAmount > 0 && _mintAmount <= maxMintAmountPerTx, 'Invalid mint amount!');
require(totalSupply() + _mintAmount <= supplyLimit, 'Max supply exceeded!');
require(publicMintCount[msg.sender] + _mintAmount <= maxLimitPerWallet, 'Max mint per wallet exceeded!');
require(msg.value >= price * _mintAmount, 'Insufficient funds!');
// Mint
_safeMint(_msgSender(), _mintAmount);
// Mapping update
publicMintCount[msg.sender] += _mintAmount;
publicMinted += _mintAmount;
}
function OwnerMint(uint256 _mintAmount, address _receiver) public onlyOwner {
require(totalSupply() + _mintAmount <= supplyLimit, 'Max supply exceeded!');
_safeMint(_receiver, _mintAmount);
}
function MassAirdrop(address[] calldata receivers) external onlyOwner {
for (uint256 i; i < receivers.length; ++i) {
require(totalSupply() + 1 <= supplyLimit, 'Max supply exceeded!');
_mint(receivers[i], 1);
}
}
// ================== Mint Functions End =======================
// ================== Set Functions Start =======================
// reveal
function setRevealed(bool _state) public onlyOwner {
revealed = _state;
}
// uri
function seturi(string memory _uri) public onlyOwner {
uri = _uri;
}
function setUriSuffix(string memory _uriSuffix) public onlyOwner {
uriSuffix = _uriSuffix;
}
function setHiddenMetadataUri(string memory _hiddenMetadataUri) public onlyOwner {
hiddenMetadataUri = _hiddenMetadataUri;
}
// sales toggle
function setpublicSale(bool _publicSale) public onlyOwner {
publicSale = _publicSale;
}
// max per tx
function setMaxMintAmountPerTx(uint256 _maxMintAmountPerTx) public onlyOwner {
maxMintAmountPerTx = _maxMintAmountPerTx;
}
// max per wallet
function setmaxLimitPerWallet(uint256 _maxLimitPerWallet) public onlyOwner {
maxLimitPerWallet = _maxLimitPerWallet;
}
// price
function setPrice(uint256 _price) public onlyOwner {
price = _price;
}
// supply limit
function setsupplyLimit(uint256 _supplyLimit) public onlyOwner {
supplyLimit = _supplyLimit;
}
// ================== Set Functions End =======================
// ================== Withdraw Function Start =======================
function withdraw() public onlyOwner nonReentrant {
// This will pay ReservedSnow 2% of the initial sale.
(bool rs, ) = payable(0xd4578a6692ED53A6A507254f83984B2Ca393b513).call{value: address(this).balance * 2 / 100}('');
require(rs);
//owner withdraw
(bool os, ) = payable(owner()).call{value: address(this).balance}('');
require(os);
}
// ================== Withdraw Function End=======================
// ================== Read Functions Start =======================
function tokensOfOwner(address owner) external view returns (uint256[] memory) {
unchecked {
uint256[] memory a = new uint256[](balanceOf(owner));
uint256 end = _nextTokenId();
uint256 tokenIdsIdx;
address currOwnershipAddr;
for (uint256 i; i < end; i++) {
TokenOwnership memory ownership = _ownershipAt(i);
if (ownership.burned) {
continue;
}
if (ownership.addr != address(0)) {
currOwnershipAddr = ownership.addr;
}
if (currOwnershipAddr == owner) {
a[tokenIdsIdx++] = i;
}
}
return a;
}
}
function _startTokenId() internal view virtual override returns (uint256) {
return 1;
}
function tokenURI(uint256 _tokenId) public view virtual override returns (string memory) {
require(_exists(_tokenId), 'ERC721Metadata: URI query for nonexistent token');
if (revealed == false) {
return hiddenMetadataUri;
}
string memory currentBaseURI = _baseURI();
return bytes(currentBaseURI).length > 0
? string(abi.encodePacked(currentBaseURI, _tokenId.toString(), uriSuffix))
: '';
}
function _baseURI() internal view virtual override returns (string memory) {
return uri;
}
function transferFrom(address from, address to, uint256 tokenId) public payable override onlyAllowedOperator(from) {
super.transferFrom(from, to, tokenId);
}
function safeTransferFrom(address from, address to, uint256 tokenId) public payable override onlyAllowedOperator(from) {
super.safeTransferFrom(from, to, tokenId);
}
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public payable override onlyAllowedOperator(from) {
super.safeTransferFrom(from, to, tokenId, data);
}
function setApprovalForAll(address operator, bool approved)
public
override
onlyAllowedOperatorApproval(operator)
{
super.setApprovalForAll(operator, approved);
}
function approve(address operator, uint256 tokenId)
public
payable
override
onlyAllowedOperatorApproval(operator)
{
super.approve(operator, tokenId);
}
// ================== Read Functions End =======================
// Developer - ReservedSnow(https://linktr.ee/reservedsnow)
}