I'm working on an ERC721 based on OpenZeppelin contracts and added a mint function to mint an arbitrarily number of tokens based on the length of an input array containing tokenURIs.
Are there any ways to optimize this function for gas other than inheriting from another type of contract such as ERC721A or ERC1155 (which I don't want to do in this case)?
We are initializing the first token id to '1'. Thanks.
function batchMint(address _to, string[] memory _tokenURI) public onlyOwner {
require(_tokenURI.length > 0, "invalid mint amount");
for (uint256 i = 0; i < _tokenURI.length; i++) {
_safeMint(_to, _nextTokenId.current());
_setTokenURI(_nextTokenId.current(), _tokenURI[i]);
_nextTokenId.increment();
}
}