I have a scenario in which I need to generate some on-chain random attribute for an NFT after it's minted with the max supply being 10k tokens. In the testing I've done on Rinkeby, if I call Chainlink VRFv2 to request one new random number for each mint it's costing around .35 LINK (so ~$2.50 at time of writing), meaning after all 10k are minted I would have spent $25k in gas.
Instead of calling Chainlink during each mint, couldn't I pre-request the random numbers (e.g before the mint starts) and do something like the following?:
// Array to store all random numbers
uint256[] private allRandomNums;
// Call this before minting begins
function requestAllRandomNumbers() public onlyOwner {
COORDINATOR.requestRandomWords(
keyHash,
subscriptionId,
10, // confirmations
250000, // callback gas limit
10000 // numwords
);
}
function fulfillRandomWords(uint256 requestId, uint256[] memory randomWords) internal virtual override {
allRandomNums = randomWords;
}
function mint() public {
uint256 tokenId = totalSupply();
_mint(...);
uint256 randomNum = allRandomNums[tokenId];
// Set some attribute randomly using randomNum
}
Would this leave the door open for a reroll attack since the minting and attribute setting are all done within mint()
(ala Meebits)? Is there anything else I am overlooking?
Tagging you @PatrickAlphaC since you seem to be the go-to for Chainlink questions! Any insight would be greatly appreciated.