smartcontractkit / hardhat-starter-kit

A repo for boilerplate code for testing, deploying, and shipping chainlink solidity code.
MIT License
1.21k stars 491 forks source link

How to Generate ChainLInk VRFConsumerBaseV2 with Hardhat and ethers #85

Closed paulayo93 closed 2 years ago

paulayo93 commented 2 years ago

Please I need help with generating a ChainLink VRFConsumerBaseV2 and testing it out on my local development

How to call the contract from frontend to generate randomness

The guide out there only covers for Chainlink V1

Sincerely appreciate your help

rgottleber commented 2 years ago

We are in the process of updating the starter kit to include VRF V2.

In the meantime, you can find a sample contract for generating random numbers via VRF V2 here https://docs.chain.link/docs/chainlink-vrf/ Once you have the contract deployed and working, interacting with it via ethers should be similar to other contracts.

something similar to this will request the random number from the front end.

async function randomNumber() {
  randomNumberContract = new ethers.Contract(randomNumber, VRFConsumerBaseV2.abi, signer);
  txn = await randomNumberContract.requestRandomWords();
  txn.wait();
  console.log(txn);
}