This demo project demonstrates how to create randomly generated on-chain Emoji NFTs using Chainlink VRF and how to host that collection on OpenSea on Sepolia Testnet.
Be sure to have installed the following
- Get a RPC API Key from a node provider such as Alchemy, Infura, Moralis, or QuickNode. This example uses the Sepolia Ethereum test network.
- Clone the repo
git clone https://github.com/smartcontractkit/smart-contract-examples.git
- Enter the directory
cd smart-contract-examples/random-svg-nft
- Install packages
yarn- Compile contracts
yarn compile- Run tests
yarn testor
REPORT_GAS=true yarn test- Run test coverage
yarn coverage- Deploy contract to Sepolia
Go to Chainlink VRF Subscription Managment Page, connect your wallet, create new subscription and fund it. Make sure to have at least 1 Sepolia LINK in your wallet, you can obtain it from the Chainlink Faucet
Copy the .env.example file to a file named .env, and put your Private Key, RPC API Key, Etherscan API Key, and Subscription ID like this
ETHERSCAN_API_KEY=<YOUR ETHERSCAN API>
SEPOLIA_URL=https://eth-sepolia.alchemyapi.io/v2/<YOUR ALCHEMY KEY>
PRIVATE_KEY=<YOUR PRIVATE KEY>
SUBSCRIPTION_ID=<ID>After that run the deployment script which will
- deploy your smart contract to the Sepolia
- verify it on Etherscan
yarn deployLastly, navigate back to the Chainlink VRF Subscription Managment Page and add the address of deployed smart contract as subscription consumer.
If the verification process fails because the new contract hasn't been indexed yet on Etherscan, run the next command from your terminal
npx hardhat verify --network Sepolia <CONTRACT_ADDRESS> 0xd89b2bf150e3b9e13446986e571fb9cab24b13cea0a43ea20a6049a85cc807cc <SUBSCRIPTION_ID> 1000000 4 3Call mint() function of your contract. Soon after the successful transaction, your NFT will be available on OpenSea
