I have a bit of a tricky problem here.
So for my contract I have 2 factions and when a user mints he can decide what faction to mint and there are two separate unrevealed URIs (one for each faction). Im using ERC721A so I need to mint from 1 to 10000 in order so I can't just separate token 1-5000 as faction 1 and 5001-10000 as faction 2. I have this solution here but when a user batch mints 3 tokens I have to set 3 different mapping items for each token to map to the baseURI. Those 3 sets are taking up a decent amount of gas.
Code:
function mint(uint256 _count, uint8 factionId)
public
virtual
payable
{
if(tx.origin != msg.sender) revert NoContracts();
uint256 totalSupply = totalSupply();
//Add check to only let 3 max mints per wallet
if(factionId == 1){
if(faction1SupplyMinted + _count > 5001) revert MintExceedsMaxFaction1Supply();
for(uint256 i; i < _count; i++) {
unrevealedURIMapping[totalSupply + i] = 1;
}
_safeMint(msg.sender, _count);
faction1SupplyMinted += _count;
} else if(factionId == 2){
if(faction2SupplyMinted + _count > 5001) revert MintExceedsMaxFaction2Supply();
for(uint256 i; i < _count; i++) {
unrevealedURIMapping[totalSupply + i] = 2;
}
_safeMint(msg.sender, _count);
faction2SupplyMinted += _count;
} else {
revert("Faction ID is invalid");
}
}
Then when checking tokenURI I have this check if not revealed is true:
if(notRevealed) {
uint256 factionId = unrevealedURIMapping[_tokenId];
if (factionId == 1) {
return faction1UnrevealedURI;
} else if (factionId == 2) {
return faction2UnrevealedURI;
}
revert TokenNonExistent();
}
When running a gas test this is what happens when batchMinting more than 1 token:
Faction Minting
gas to mint 1: 123006
gas to mint 2: 147344
gas to mint 3: 171682
gas to mint 4: 196020
gas to mint 5: 220358
I have narrowed it down to each set on unrevealedURIMapping is causing a big increase in gas.
Do you have an idea on a better solution that using a mapping like this?
Any help is greatly appreciated!!
Cheers