@@ -6,7 +6,7 @@ import "@openzeppelin/contracts/access/Ownable.sol";
66import "@openzeppelin/contracts/utils/Strings.sol " ;
77import "@openzeppelin/contracts/utils/Base64.sol " ;
88import "@openzeppelin/contracts/utils/math/SafeMath.sol " ;
9- import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable .sol " ;
9+ import "@openzeppelin/contracts/token/ERC721/ERC721 .sol " ;
1010import "./INCT.sol " ;
1111
1212/**
@@ -17,9 +17,9 @@ import "./INCT.sol";
1717 * Authors: 0xSimo
1818 * Created: 01.07.2021
1919 * Last revision: 26.07.2021: set name change price already ready for a real example
20- * 22.03 .2022: on-chain metadata, gas optimizations, ERC721Enumerable
20+ * 22.07 .2022: gas optimizations
2121 */
22- contract UC1 is ERC721Enumerable , Ownable {
22+ contract UC1 is ERC721 , Ownable {
2323 using Strings for uint256 ;
2424 using SafeMath for uint256 ;
2525
@@ -29,6 +29,8 @@ contract UC1 is ERC721Enumerable, Ownable {
2929 uint256 public constant NAME_CHANGE_PRICE = 10 * (10 ** 18 );
3030 // The NFT minting price, this is just an example
3131 uint256 public constant NFT_MINT_PRICE = 0.1 ether ;
32+ // the (current) total supply
33+ uint256 public totalSupply;
3234
3335 // Mapping from token ID to name
3436 mapping (uint256 => string ) private _tokenName;
@@ -99,16 +101,16 @@ contract UC1 is ERC721Enumerable, Ownable {
99101 * @dev Mint 'numberOfNfts' new tokens
100102 */
101103 function mintNFT (uint256 numberOfNfts ) public payable {
102- require (totalSupply () < MAX_NFT_SUPPLY, "Sale has already ended " );
104+ require (totalSupply < MAX_NFT_SUPPLY, "Sale has already ended " );
103105 require (numberOfNfts > 0 , "numberOfNfts cannot be 0 " );
104106 require (numberOfNfts <= 20 , "You may not buy more than 20 NFTs at once " );
105- require (totalSupply () .add (numberOfNfts) <= MAX_NFT_SUPPLY, "Sale has already ended " );
107+ require (totalSupply.add (numberOfNfts) <= MAX_NFT_SUPPLY, "Sale has already ended " );
106108 require (NFT_MINT_PRICE.mul (numberOfNfts) == msg .value , "Ether value sent is not correct " );
107109
108110 for (uint i = 0 ; i < numberOfNfts; i++ ) {
109- uint256 mintIndex = totalSupply ();
110- if (mintIndex < MAX_NFT_SUPPLY) {
111- _safeMint ( _msgSender (), mintIndex);
111+ if (totalSupply < MAX_NFT_SUPPLY) {
112+ _mint ( _msgSender (), totalSupply);
113+ totalSupply += 1 ; // can be unchecked no overflow here
112114 }
113115 }
114116 }
0 commit comments