1
+ // SPDX-License-Identifier: MIT LICENSE
2
+
3
+ import "@openzeppelin/contracts/access/Ownable.sol " ;
4
+ import "@openzeppelin/contracts/token/ERC20/IERC20.sol " ;
5
+ import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol " ;
6
+
7
+ pragma solidity ^ 0.8.0 ;
8
+
9
+ contract Collection is ERC721Enumerable , Ownable {
10
+
11
+ struct TokenInfo {
12
+ IERC20 paytoken;
13
+ uint256 costvalue;
14
+ }
15
+
16
+ TokenInfo[] public AllowedCrypto;
17
+
18
+ using Strings for uint256 ;
19
+ string public baseURI;
20
+ string public baseExtension = ".json " ;
21
+ uint256 cost = 15 ether ;
22
+ uint256 public maxSupply = 1000 ;
23
+ uint256 public maxMintAmount = 5 ;
24
+ bool public paused = false ;
25
+
26
+ constructor () ERC721 ("Net2Dev NFT Collection " , "N2D " ) {}
27
+
28
+ function addCurrency (
29
+ IERC20 _paytoken ,
30
+ uint256 _costvalue
31
+ ) public onlyOwner {
32
+ AllowedCrypto.push (
33
+ TokenInfo ({
34
+ paytoken: _paytoken,
35
+ costvalue: _costvalue
36
+ })
37
+ );
38
+ }
39
+
40
+ function _baseURI () internal view virtual override returns (string memory ) {
41
+ return "ipfs://EE5MmqVp5MmqVp7ZRMBBizicVh9ficVh9fjUofWicVh9f/ " ;
42
+
43
+ }
44
+
45
+ function mint (address _to , uint256 _mintAmount ) public payable {
46
+ uint256 supply = totalSupply ();
47
+ require (! paused);
48
+ require (_mintAmount > 0 );
49
+ require (_mintAmount <= maxMintAmount);
50
+ require (supply + _mintAmount <= maxSupply);
51
+
52
+ if (msg .sender != owner ()) {
53
+ require (msg .value == cost * _mintAmount, "Not enough balance to complete transaction. " );
54
+ }
55
+
56
+ for (uint256 i = 1 ; i <= _mintAmount; i++ ) {
57
+ _safeMint (_to, supply + i);
58
+ }
59
+ }
60
+
61
+
62
+ function mintpid (address _to , uint256 _mintAmount , uint256 _pid ) public payable {
63
+ TokenInfo storage tokens = AllowedCrypto[_pid];
64
+ IERC20 paytoken;
65
+ paytoken = tokens.paytoken;
66
+ uint256 cost;
67
+ cost = tokens.costvalue;
68
+ uint256 supply = totalSupply ();
69
+ require (! paused);
70
+ require (_mintAmount > 0 );
71
+ require (_mintAmount <= maxMintAmount);
72
+ require (supply + _mintAmount <= maxSupply);
73
+
74
+ if (msg .sender != owner ()) {
75
+ require (msg .value == cost * _mintAmount, "Not enough balance to complete transaction. " );
76
+ }
77
+
78
+ for (uint256 i = 1 ; i <= _mintAmount; i++ ) {
79
+ paytoken.transferFrom (msg .sender , address (this ), cost);
80
+ _safeMint (_to, supply + i);
81
+ }
82
+ }
83
+
84
+ function walletOfOwner (address _owner )
85
+ public
86
+ view
87
+ returns (uint256 [] memory )
88
+ {
89
+ uint256 ownerTokenCount = balanceOf (_owner);
90
+ uint256 [] memory tokenIds = new uint256 [](ownerTokenCount);
91
+ for (uint256 i; i < ownerTokenCount; i++ ) {
92
+ tokenIds[i] = tokenOfOwnerByIndex (_owner, i);
93
+ }
94
+ return tokenIds;
95
+ }
96
+
97
+
98
+ function tokenURI (uint256 tokenId )
99
+ public
100
+ view
101
+ virtual
102
+ override
103
+ returns (string memory ) {
104
+ require (
105
+ _exists (tokenId),
106
+ "ERC721Metadata: URI query for nonexistent token "
107
+ );
108
+
109
+ string memory currentBaseURI = _baseURI ();
110
+ return
111
+ bytes (currentBaseURI).length > 0
112
+ ? string (abi.encodePacked (currentBaseURI, tokenId.toString (), baseExtension))
113
+ : "" ;
114
+ }
115
+ // only owner
116
+
117
+ function setmaxMintAmount (uint256 _newmaxMintAmount ) public onlyOwner () {
118
+ maxMintAmount = _newmaxMintAmount;
119
+ }
120
+
121
+ function setBaseURI (string memory _newBaseURI ) public onlyOwner () {
122
+ baseURI = _newBaseURI;
123
+ }
124
+
125
+ function setBaseExtension (string memory _newBaseExtension ) public onlyOwner () {
126
+ baseExtension = _newBaseExtension;
127
+ }
128
+
129
+ function pause (bool _state ) public onlyOwner () {
130
+ paused = _state;
131
+ }
132
+
133
+ function getNFTCost (uint256 _pid ) public view virtual returns (uint256 ) {
134
+ TokenInfo storage tokens = AllowedCrypto[_pid];
135
+ uint256 cost;
136
+ cost = tokens.costvalue;
137
+ return cost;
138
+ }
139
+
140
+ function getCryptotoken (uint256 _pid ) public view virtual returns (IERC20 ) {
141
+ TokenInfo storage tokens = AllowedCrypto[_pid];
142
+ IERC20 paytoken;
143
+ paytoken = tokens.paytoken;
144
+ return paytoken;
145
+ }
146
+
147
+ function withdraw (uint256 _pid ) public payable onlyOwner () {
148
+ TokenInfo storage tokens = AllowedCrypto[_pid];
149
+ IERC20 paytoken;
150
+ paytoken = tokens.paytoken;
151
+ paytoken.transfer (msg .sender , paytoken.balanceOf (address (this )));
152
+ }
153
+ }
0 commit comments