How To Create Generative Art NFTs Using Chainlink VRF and IPFS

·

Non-Fungible Tokens (NFTs) are unique digital assets stored on blockchains, representing ownership of items like digital art, collectibles, or in-game assets. Unlike cryptocurrencies such as Bitcoin, each NFT is distinct and non-interchangeable. This guide will walk you through creating a generative art NFT collection featuring dog breeds, powered by verifiable randomness from Chainlink VRF and hosted on IPFS.


Step 1: Clone the Repository and Set Up Dependencies

Begin by cloning the Chainlink Smart Contract Examples repository:

git clone https://github.com/smartcontractkit/smart-contract-examples.git
cd smart-contract-examples/ultimate-nft-repo
yarn

Environment Variables

Configure these required variables in your project:


Step 2: Configure Chainlink VRF v2

  1. Visit the VRF subscription page, select Sepolia, and create a subscription.
  2. Fund the subscription with test LINK tokens from Chainlink’s faucet.
  3. Save your subscriptionId for the smart contract constructor.

Step 3: Develop the NFT Smart Contract

Key Components:

Contract Structure:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;

import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@chainlink/contracts/src/v0.8/VRFConsumerBaseV2.sol";

contract RandomIpfsNft is ERC721URIStorage, VRFConsumerBaseV2, Ownable {
    enum Breed { PUG, SHIBA_INU, ST_BERNARD }
    mapping(uint256 => Breed) private s_tokenIdToBreed;
    string[] internal s_dogTokenUris;
    // ... additional variables and functions
}

Key Functions:


Step 4: Deploy Images to IPFS

  1. Upload dog breed images to Pinata.
  2. Store the IPFS URLs in the contract’s s_dogTokenUris array.

Step 5: Deploy and Mint NFTs

  1. Deploy to Sepolia testnet using Hardhat or Remix.
  2. Add your contract as a VRF consumer under your subscription.
  3. Mint NFTs via Etherscan or a custom dApp interface.

👉 Explore NFT trading on OpenSea Sepolia


Step 6: Trade NFTs on OpenSea

After minting, view your collection on OpenSea’s Sepolia testnet.


FAQ Section

What is Chainlink VRF?

Chainlink Verifiable Random Function (VRF) provides tamper-proof randomness for smart contracts, ensuring fairness in generative art NFT traits.

How much does it cost to mint?

The minting fee is set in the constructor (e.g., 0.01 ETH). Adjustable by the contract owner.

Can I change the NFT artwork?

No, artwork is immutable once deployed to IPFS and linked to the token URI.


Summary

This tutorial covered:

👉 Learn more about Chainlink integrations

For further exploration, check the Chainlink documentation or experiment with other smart contract examples.