-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathERC721A With Free Mint.sol
184 lines (152 loc) · 5.58 KB
/
ERC721A With Free Mint.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
// SPDX-License-Identifier: GPL-3.0
//Developer : FazelPejmanfar , Twitter :@Pejmanfarfazel
/*
This a Free Contract, DO NOT SELL IT
*/
pragma solidity >=0.7.0 <0.9.0;
import "erc721a/contracts/ERC721A.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
contract Fazel is ERC721A, Ownable, ReentrancyGuard {
using Strings for uint256;
string public baseURI;
string public baseExtension = ".json";
string public notRevealedUri;
uint256 public cost = 0.05 ether;
uint256 public maxSupply = 5000;
uint256 public FreeSupply = 2500;
uint256 public MaxperWallet = 10;
uint256 public MaxperWalletFree = 3;
bool public paused = false;
bool public revealed = false;
constructor(
string memory _initBaseURI,
string memory _notRevealedUri
) ERC721A("Name", "Symbol") { // change the name and symbol for your collection
setBaseURI(_initBaseURI);
setNotRevealedURI(_notRevealedUri);
}
// internal
function _baseURI() internal view virtual override returns (string memory) {
return baseURI;
}
function _startTokenId() internal view virtual override returns (uint256) {
return 1;
}
// public
/// @dev Public mint
function mint(uint256 tokens) public payable nonReentrant {
require(!paused, "oops contract is paused");
require(tokens <= MaxperWallet, "max mint amount per tx exceeded");
require(totalSupply() + tokens <= maxSupply, "We Soldout");
require(_numberMinted(_msgSenderERC721A()) + tokens <= MaxperWallet, "Max NFT Per Wallet exceeded");
require(msg.value >= cost * tokens, "insufficient funds");
_safeMint(_msgSenderERC721A(), tokens);
}
/// @dev free mint
function freemint(uint256 tokens) public nonReentrant {
require(!paused, "oops contract is paused");
require(_numberMinted(_msgSenderERC721A()) + tokens <= MaxperWalletFree, "Max NFT Per Wallet exceeded");
require(tokens <= MaxperWalletFree, "max mint per Tx exceeded");
require(totalSupply() + tokens <= FreeSupply, "Whitelist MaxSupply exceeded");
_safeMint(_msgSenderERC721A(), tokens);
}
/// @dev use it for giveaway and team mint
function airdrop(uint256 _mintAmount, address destination) public onlyOwner nonReentrant {
require(totalSupply() + _mintAmount <= maxSupply, "max NFT limit exceeded");
_safeMint(destination, _mintAmount);
}
/// @notice returns metadata link of tokenid
function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
require(
_exists(tokenId),
"ERC721AMetadata: URI query for nonexistent token"
);
if(revealed == false) {
return notRevealedUri;
}
string memory currentBaseURI = _baseURI();
return bytes(currentBaseURI).length > 0
? string(abi.encodePacked(currentBaseURI, tokenId.toString(), baseExtension))
: "";
}
/// @notice return the number minted by an address
function numberMinted(address owner) public view returns (uint256) {
return _numberMinted(owner);
}
/// @notice return the tokens owned by an address
function tokensOfOwner(address owner) public view returns (uint256[] memory) {
unchecked {
uint256 tokenIdsIdx;
address currOwnershipAddr;
uint256 tokenIdsLength = balanceOf(owner);
uint256[] memory tokenIds = new uint256[](tokenIdsLength);
TokenOwnership memory ownership;
for (uint256 i = _startTokenId(); tokenIdsIdx != tokenIdsLength; ++i) {
ownership = _ownershipAt(i);
if (ownership.burned) {
continue;
}
if (ownership.addr != address(0)) {
currOwnershipAddr = ownership.addr;
}
if (currOwnershipAddr == owner) {
tokenIds[tokenIdsIdx++] = i;
}
}
return tokenIds;
}
}
//only owner
function reveal(bool _state) public onlyOwner {
revealed = _state;
}
/// @dev change the public max per wallet
function setMaxPerWallet(uint256 _limit) public onlyOwner {
MaxperWallet = _limit;
}
/// @dev change the free max per wallet
function setFreeMaxPerWallet(uint256 _limit) public onlyOwner {
MaxperWalletFree = _limit;
}
/// @dev change the public price(amount need to be in wei)
function setCost(uint256 _newCost) public onlyOwner {
cost = _newCost;
}
/// @dev cut the supply if we dont sold out
function setMaxsupply(uint256 _newsupply) public onlyOwner {
maxSupply = _newsupply;
}
/// @dev cut the free supply
function setFreesupply(uint256 _newsupply) public onlyOwner {
FreeSupply = _newsupply;
}
/// @dev set your baseuri
function setBaseURI(string memory _newBaseURI) public onlyOwner {
baseURI = _newBaseURI;
}
/// @dev set base extension(default is .json)
function setBaseExtension(string memory _newBaseExtension) public onlyOwner {
baseExtension = _newBaseExtension;
}
/// @dev set hidden uri
function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner {
notRevealedUri = _notRevealedURI;
}
/// @dev to pause and unpause your contract(use booleans true or false)
function pause(bool _state) public onlyOwner {
paused = _state;
}
/// @dev withdraw funds from contract
function withdraw() public payable onlyOwner nonReentrant {
uint256 balance = address(this).balance;
payable(_msgSenderERC721A()).transfer(balance);
}
}