Skip to content

Latest commit

 

History

History

p14-chainlink-vrf

Chainlink VRF

This project demonstrates how to get a verifiable random number using Chainlink VRF as a tamper-proof random number generator (RNG). This random number can be used in any application which rely on unpredictable outcomes:

  • Blockchain games and NFTs
  • Random assignment of duties and resources (e.g. randomly assigning judges to cases)
  • Choosing a representative sample for consensus mechanisms

Steps

  1. Install dependencies using
yarn
  1. Create a .env in the project directory and write the following environment variables:
MNEMONIC = REPLACE_WITH_YOUR_MNEMONIC
RINKEBY_RPC = https://rinkeby.infura.io/v3/YOUR_INFURA_PROJECT_ID
  1. Deploy the smart contract contracts/MyRNG.sol using the script in scripts/deployMyRNG.ts. Make sure you have some Rinkeby test ETH in your account you are using to deploy the contract.
npx hardhat run scripts/deployMyRNG.ts --network rinkeby
  1. Request a random number from Chainlink VRF using the script given in scripts/getNewRandomNumber.ts.
npx hardhat run scripts/getNewRandomNumber.ts --network rinkeby
  1. Check for the random value by running the script in scripts/getCurrentNumber.ts. It may take some time for the new random value to appear. So, you may need to run this script multiple times until the new random value appears.
npx hardhat run scripts/getCurrentNumber.ts --network rinkeby

Deployed Contracts and Txns

  1. VRFCoordinator Address | Rinkeby
  2. LinkToken Address | Rinkeby
  3. MyRNG Contract | Rinkeby
  4. Txn For Requesting Random Number | Rinkeby
  5. Randomness Fullfillment Txn | Rinkeby