Lesson 14: How come localhost has a subscriptionId? #2387
-
I am going through lesson 14 and noticed that helper file includes a subId for VRF coordinator but I thought that we had to simulate vrf when on localnetwork aka hardhat. Is that subscriptionId serving any purpose when assigned to local network? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
@DorianDaSilva Yes, I will be needed for the testnet when we deploy the script for random nft |
Beta Was this translation helpful? Give feedback.
-
We are using the Mock when we are on a local network (e.g. localhost), as so (an example to illustrate): if (chainId == 31337) {
// Create VRFV2 Subscription
const vrfCoordinatorV2Mock = await ethers.getContract("VRFCoordinatorV2Mock")
vrfCoordinatorV2Address = vrfCoordinatorV2Mock.address
const transactionResponse = await vrfCoordinatorV2Mock.createSubscription()
const transactionReceipt = await transactionResponse.wait()
subscriptionId = transactionReceipt.events[0].args.subId
// Fund the subscription
// Our mock makes it so we don't actually have to worry about sending fund
await vrfCoordinatorV2Mock.fundSubscription(subscriptionId, FUND_AMOUNT)
} |
Beta Was this translation helpful? Give feedback.
@DorianDaSilva Yes, I will be needed for the testnet when we deploy the script for random nft