-
Notifications
You must be signed in to change notification settings - Fork 514
Expand file tree
/
Copy pathrequest-random-number.js
More file actions
46 lines (43 loc) · 1.65 KB
/
request-random-number.js
File metadata and controls
46 lines (43 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
task(
"request-random-number",
"Requests a random number for a Chainlink VRF enabled smart contract using the Subscription method"
)
.addParam("contract", "The address of the VRF Consumer contract that you want to call")
.setAction(async (taskArgs) => {
const contractAddr = taskArgs.contract
const networkId = network.name
console.log(
"Requesting a random number using VRF consumer contract ",
contractAddr,
" on network ",
networkId
)
const RandomNumberConsumerV2 = await ethers.getContractFactory("RandomNumberConsumerV2")
// Get signer information
const accounts = await hre.ethers.getSigners()
const signer = accounts[0]
// Create connection to VRF Contract and call the requestRandomWords function
const vrfConsumerContractV2 = new ethers.Contract(
contractAddr,
RandomNumberConsumerV2.interface,
signer
)
const transaction = await vrfConsumerContractV2.requestRandomWords()
const requestId = await vrfConsumerContractV2.lastRequestId()
console.log(
"Contract ",
contractAddr,
" random number request successfully called. Transaction Hash: ",
transaction.hash,
" requestId: ",
requestId.toString()
)
console.log("Run the following to read the returned random number:")
console.log(
"yarn hardhat read-random-number --contract " +
contractAddr +
" --network " +
network.name
)
})
module.exports = {}