Blind Boxes will contain cards with levels vary from 1 to 5. You will get 1 S-NFT card for every blind box purchased. The level of the card will be determined by a ramdon function.
Copy function buyBoxes(uint256 boxesLength, uint256 tokenId)
external
payable
nonReentrant
{
require(boxesLength > 0, "Boxes length must > 0");
require(boxesLength <= 100, "Boxes length must <= 100");
require(getBoxesLeftSupply() >= boxesLength, "Not enough boxes supply");
uint256 price = boxesLength * boxTokenPrices[tokenId];
if (tokenId == 0) {
require(msg.value == price, "Price mismatch");
payable(receivingAddress).transfer(price);
} else {
IERC20 token = IERC20(tokenAddrs[tokenId]);
token.transferFrom(msg.sender, receivingAddress, price);
}
spawnHns(msg.sender, boxesLength);
userBoxesLength[msg.sender] += boxesLength;
userTokenBuyAmount[msg.sender][tokenId] += price;
totalBoxesLength += boxesLength;
totalTokenBuyAmount[tokenId] += price;
users.add(msg.sender);
}