I’ve recently started exploring and learning Solidity and have been looking at contracts of some of the famous NFT projects.
One common pattern that I’ve found is that most of them set a ProvenanceHash
before mint and randomize the startingTokenIndex
after the mint is complete.
Here’s code snippet from one of them
function finalizeStartingIndex() public { require(starting_index == 0, "Starting index already set"); require(starting_index_block != 0, "Starting index block not set"); starting_index = uint256(blockhash(starting_index_block)) % max_token_supply; if (block.number.sub(starting_index_block) > 255) { starting_index = uint256(blockhash(block.number-1)) % max_token_supply; } if (starting_index == 0) { starting_index = starting_index.add(1); } }
I understand what a Provenance Hash is and the need to randomize the starting index, but I am having a hard time understanding how this actually works in the contract.
In the above snippet the starting_index
variable is set, but I could not find its usage anywhere within the contract apart from some guard conditions.
So how does it actually achieve the intended assignment of random tokenIds?
Shouldn’t it be used somewhere we actually store/return the ownership or tokenUri
or something? or am I missing some critical piece of information here?
Here’s the link to complete source code of the contract in question.