I am working on creating a contract that implements ERC1155 tokens. I want to be able to init a collection with different tiers. So let's say 3 tiers, tier1 will have 15 supply, tier2 50 supply and tier3 100 supply. What would be the best way to implement this between the following options:
1-Let users mint any nft they want (from any tier) with quantity they want until tiers reach their maxsupply. See code below
function mint(uint256[] memory _id, uint256[] memory _quantity) public payable {
require(saleStarted, "Owner need to confirm prices and start the sale");
require(alreadyMinted[msg.sender]==false, "You have already bought a ticket preivously");
require(_id.length == _quantity.length, "more items or quantity specified than the other");
uint256 sum = 0;
for(uint256 i = 0; i < _id.length; i++) {
require(mintedByTier[i] + _quantity[i] <= tierQuantity[i], "max supply excedeed");
sum += _id[i] * _quantity[i];
mintedByTier[i] += _quantity[i];
}
require(msg.value >= sum, "Not enough funds");
_mintBatch(msg.sender, _id, _quantity, " ");
}
2-Mint all tokens with the constructor when the smart contract is created. So the holder of all the ERC1155 tokens (at the start) will be the smart contract and then enable users to buy them from the smart contract and get them in their wallet. However I am not sure how to make the transfer between the smart contract and the buyer wallet address.
function purchase(uint256[] memory _id, uint256[] memory _quantity) public payable{
require(saleStarted, "Owner need to confirm prices and start the sale");
require(alreadyMinted[msg.sender]==false, "You have already bought a ticket preivously");
require(_id.length == _quantity.length, "more items or quantity specified than the other");
uint256 sum = 0;
for(uint256 i = 0; i < _id.length; i++) {
sum += _id[i] * _quantity[i];
}
safeBatchTransferFrom(address(this), msg.sender, _id, _quantity, " ");
}
My question is: what would be the best way to do it, like more secure and reliable.
Best regards
EDIT: I added code for the 2 different ways.