Docs/Examples/Nft Reveal

NFTReveal (VRF Trait Reveal)

Assigns rarity tiers to all minted NFTs at reveal time using a single VRF seed.


Overview

NFTReveal is a two-phase NFT contract: mint, then reveal. During the mint phase users pay mintPrice to receive a token with no assigned traits. After revealTime passes, AutoLoop fires once and uses ECVRF to seed trait assignment for every minted token in a single transaction.

PropertyValue
Base contractAutoLoopVRFCompatible
VRF usageTrait assignment seed
Gas per tick~35k + 12k per token
Sourceautoloop/src/agents/NFTReveal.sol
Tests21 passing (unit + fuzz)

Why AutoLoop + VRF Are Structurally Required

The trigger holder can front-run the reveal. With a deterministic reveal, whoever triggers the reveal can pre-compute all trait assignments before calling. They could selectively reveal only when they hold rare tokens, or sell tokens at inflated prices based on advance knowledge. AutoLoop fires at a neutral block and ECVRF ensures the seed is unpredictable until the transaction lands.

Mechanics

  • Mint phase: mint() assigns ownership of nextTokenId and takes mintPrice ETH
  • Reveal condition: shouldProgressLoop() returns true when block.timestamp >= revealTime, nextTokenId > 0, and not yet revealed
  • One-shot reveal: progressLoop() sets revealed = true, stores the VRF seed in revealSeed, then loops over all minted tokens assigning tiers based on keccak256(seed, tokenId) % 10000 matched against rarityTiersBps[]
  • Tiers: defined at construction as an array of BPS values summing to 10000 (e.g. [5000, 3000, 1500, 500] for Common/Uncommon/Rare/Legendary)
  • tokenTier(id): returns 0 (unrevealed) or 1..N after reveal

Revenue Model

  • 2% protocol fee on each mint payment
  • AutoLoop gas fee on reveal tick

Deploy

# Example: 1000 supply, 0.01 ETH mint, reveal in 7 days, 4 tiers
forge create src/agents/NFTReveal.sol:NFTReveal \
  --constructor-args 1000 10000000000000000 $(($(date +%s) + 604800)) "[5000,3000,1500,500]" '["Common","Uncommon","Rare","Legendary"]' \
  --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast

Args: maxSupply, mintPrice (wei), revealTime (unix timestamp), rarityTiersBps[], rarityTierNames[].

Dashboard

View NFTReveal on the AutoLoop Dashboard.