Hi, I'm very new to smart contract development - wondering if someone can have a look at my mint function - I Have edited a tutorials mint function to be passed an array of IDs instead of just incrementing the ID within the mint function.
Idea is that people can go to my site and choose which NFTs they want to buy
Thanks
function mint(uint256[] mintIDs_) public payable {
require(isPublicMintEnabled, 'minting not enabled');
require(msg.value == mintIDs_.length * mintPrice, 'wrong mint value');
for (i = 0, i < mintIDs_.length, i++) {
require(!_exists(mintIDs_[i]), 'One or more of the of your nfts have already sold')
}
require(totalSupply + mintIDs_.length <= maxSupply, 'sold out');
for (uint256 i = 0; i < mintIDs_.length; i++) {
uint256 newTokenId = mintIDs_[i]
totalSupply++;
_safeMint(msg.sender, newTokenId);
}
}
missing data location of the function parameter mintIDs_
check the first for loop - the statements should be divided by semicolons, not by commas
missing type of the i variable in the first for loop
missing semicolon after the 3rd require() condition
missing semicolon after newTokenId declaration
Apart from that, assuming that all variables not declared in this function (isPublicMintEnabled, mintPrice, ...) are visible in this scope, and have such values that won't make the require() conditions fail, you'll be able to successfully run the code.
Example:
Pass [1,2,3] as the mint() function param. Since we declared the value of mintPrice as 0, you don't need to set any ETH value of the transaction in this case.
pragma solidity ^0.8;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
contract MyCollection is ERC721("MyCollection", "MyC") {
bool isPublicMintEnabled = true;
uint256 mintPrice = 0;
uint256 totalSupply = 0;
uint256 maxSupply = type(uint256).max;
function mint(uint256[] calldata mintIDs_) public payable {
require(isPublicMintEnabled, 'minting not enabled');
require(msg.value == mintIDs_.length * mintPrice, 'wrong mint value');
for (uint256 i = 0; i < mintIDs_.length; i++) {
require(!_exists(mintIDs_[i]), 'One or more of the of your nfts have already sold');
}
require(totalSupply + mintIDs_.length <= maxSupply, 'sold out');
for (uint256 i = 0; i < mintIDs_.length; i++) {
uint256 newTokenId = mintIDs_[i];
totalSupply++;
_safeMint(msg.sender, newTokenId);
}
}
}