Using Chainlink VRF in generative art collections is the standard approach for getting provably random source in smart contracts. By batching the reveal process, instead of making VRF calls for each NFT you can save cost up to 100x in a collection of 10,000 with batch size of 100.
This template uses the Chainlink Automation decentralized network to automate the reveal process so you don't have to stand up and maintain an in-house system for automation.
In this tutorial, you will use a demo user interface that helps you learn how to automate batch reveal of NFT mints, using Chainlink Automation and VRF. VRF is used to randomize the metadata for the NFTs, and Automation is used to set trigger conditions for when the NFT metadata is revealed via batch size and/or time interval parameters.
The demo includes:
- Setting up and funding a Chainlink VRF subscription
- Automatically generating a smart contract that will then be used by both VRF (as a consumer) and in Automation (as the target contract).
Before you start this tutorial, complete the following items:
- If you are new to smart contract development, learn how to Deploy Your First Smart Contract.
- Set up a cryptocurrency wallet
- To deploy this contract on testnets, ensure the deployer account has testnet ERC-677 LINK. Use the LINK faucet to retrieve testnet LINK.
2Configure your VRF subscription
At this stage, you will need to create a VRF subscription and fund it with LINK by visiting the Chainlink VRF Subscription Manager. Follow the steps outlined in the interface to create a subscription. You will receive a confirmation message upon successful creation.
Add funds to your subscription. Copy the resulting subscription ID to your clipboard. For this demo, you can add 20 LINK.
Navigate back to the demo app. Paste the VRF Subscription ID into the Subscription ID field and fill out the fields for Queue Size Trigger and Time Trigger (seconds).
Upon successful creation, you will see a confirmation page. Copy the address and navigate back to the VRF Subscription Manager.
- In the subscription manager, click Add Consumer and paste the address in the blank field. Click Add Consumer and wait until you receive confirmation. Your consumer should no be added to your subscription. Note: you may have to refresh the page to see the consumer.
3Create an Automation Upkeep
The next step is to register a new Upkeep using Chainlink Automation. Visit the Chainlink Automation App to get started. Click the button Register New Upkeep and connect your wallet.
You will be directed to a screen where you will choose your Trigger from a dropdown menu. Select Custom logic. Paste your address into the Target contract address field. Then, click Next.
You will be directed to a form to fill out more information on your upkeep. Fill out these details and set the gas limit to 200000 to ensure the Chainlink Automation network can perform the upkeep when the trigger conditions are met. Once all the information is filled in, click Register Upkeep. Wait until the upkeep has been registered and click View Upkeep. You'll be able to see all the details of your Upkeep.
4Trigger the upkeep
- Navigate back to the demo app page. Check off both boxes and click View Collection. Your screen will look similar to this:
Mint NFTs until the trigger condition is met. At that point, the demo app will display the message "Pending Batch Reveal". The Chainlink Automation upkeep will be triggered automatically. This will internally make a call to Chainlink VRF for randomness and assign the random traits to the tokens for the reveal.
If the reveal is a success, your screen will look similar to this. You have now completed the tutorial.