-
Notifications
You must be signed in to change notification settings - Fork 12
/
ERC721-NFT-Collection-SmartContract-Web3-v1.sol
172 lines (142 loc) · 6.33 KB
/
ERC721-NFT-Collection-SmartContract-Web3-v1.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
// SPDX-License-Identifier: MIT LICENSE
/*
Follow/Subscribe Youtube, Github, IM, Tiktok
for more amazing content!!
@Net2Dev
███╗░░██╗███████╗████████╗██████╗░██████╗░███████╗██╗░░░██╗
████╗░██║██╔════╝╚══██╔══╝╚════██╗██╔══██╗██╔════╝██║░░░██║
██╔██╗██║█████╗░░░░░██║░░░░░███╔═╝██║░░██║█████╗░░╚██╗░██╔╝
██║╚████║██╔══╝░░░░░██║░░░██╔══╝░░██║░░██║██╔══╝░░░╚████╔╝░
██║░╚███║███████╗░░░██║░░░███████╗██████╔╝███████╗░░╚██╔╝░░
╚═╝░░╚══╝╚══════╝░░░╚═╝░░░╚══════╝╚═════╝░╚══════╝░░░╚═╝░░░
THIS CONTRACT IS AVAILABLE FOR EDUCATIONAL
PURPOSES ONLY. YOU ARE SOLELY REPONSIBLE
FOR ITS USE. I AM NOT RESPONSIBLE FOR ANY
OTHER USE. THIS IS TRAINING/EDUCATIONAL
MATERIAL. ONLY USE IT IF YOU AGREE TO THE
TERMS SPECIFIED ABOVE.
*/
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
pragma solidity ^0.8.0;
contract Collection is ERC721Enumerable, Ownable {
struct TokenInfo {
IERC20 paytoken;
uint256 costvalue;
}
TokenInfo[] public AllowedCrypto;
using Strings for uint256;
string public baseURI;
string public baseExtension = ".json";
uint256 cost = 15 ether;
uint256 public maxSupply = 1000;
uint256 public maxMintAmount = 5;
bool public paused = false;
constructor() ERC721("Net2Dev NFT Collection", "N2D") {}
function addCurrency(
IERC20 _paytoken,
uint256 _costvalue
) public onlyOwner {
AllowedCrypto.push(
TokenInfo({
paytoken: _paytoken,
costvalue: _costvalue
})
);
}
function _baseURI() internal view virtual override returns (string memory) {
return "ipfs://EE5MmqVp5MmqVp7ZRMBBizicVh9ficVh9fjUofWicVh9f/";
}
function mint(address _to, uint256 _mintAmount) public payable {
uint256 supply = totalSupply();
require(!paused);
require(_mintAmount > 0);
require(_mintAmount <= maxMintAmount);
require(supply + _mintAmount <= maxSupply);
if (msg.sender != owner()) {
require(msg.value == cost * _mintAmount, "Not enough balance to complete transaction.");
}
for (uint256 i = 1; i <= _mintAmount; i++) {
_safeMint(_to, supply + i);
}
}
function mintpid(address _to, uint256 _mintAmount, uint256 _pid) public payable {
TokenInfo storage tokens = AllowedCrypto[_pid];
IERC20 paytoken;
paytoken = tokens.paytoken;
uint256 cost;
cost = tokens.costvalue;
uint256 supply = totalSupply();
require(!paused);
require(_mintAmount > 0);
require(_mintAmount <= maxMintAmount);
require(supply + _mintAmount <= maxSupply);
if (msg.sender != owner()) {
require(msg.value == cost * _mintAmount, "Not enough balance to complete transaction.");
}
for (uint256 i = 1; i <= _mintAmount; i++) {
paytoken.transferFrom(msg.sender, address(this), cost);
_safeMint(_to, supply + i);
}
}
function walletOfOwner(address _owner)
public
view
returns (uint256[] memory)
{
uint256 ownerTokenCount = balanceOf(_owner);
uint256[] memory tokenIds = new uint256[](ownerTokenCount);
for (uint256 i; i < ownerTokenCount; i++) {
tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
}
return tokenIds;
}
function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory) {
require(
_exists(tokenId),
"ERC721Metadata: URI query for nonexistent token"
);
string memory currentBaseURI = _baseURI();
return
bytes(currentBaseURI).length > 0
? string(abi.encodePacked(currentBaseURI, tokenId.toString(), baseExtension))
: "";
}
// only owner
function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner() {
maxMintAmount = _newmaxMintAmount;
}
function setBaseURI(string memory _newBaseURI) public onlyOwner() {
baseURI = _newBaseURI;
}
function setBaseExtension(string memory _newBaseExtension) public onlyOwner() {
baseExtension = _newBaseExtension;
}
function pause(bool _state) public onlyOwner() {
paused = _state;
}
function getNFTCost(uint256 _pid) public view virtual returns(uint256) {
TokenInfo storage tokens = AllowedCrypto[_pid];
uint256 cost;
cost = tokens.costvalue;
return cost;
}
function getCryptotoken(uint256 _pid) public view virtual returns(IERC20) {
TokenInfo storage tokens = AllowedCrypto[_pid];
IERC20 paytoken;
paytoken = tokens.paytoken;
return paytoken;
}
function withdraw(uint256 _pid) public payable onlyOwner() {
TokenInfo storage tokens = AllowedCrypto[_pid];
IERC20 paytoken;
paytoken = tokens.paytoken;
paytoken.transfer(msg.sender, paytoken.balanceOf(address(this)));
}
}