You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: basic/15-nft-blindbox-chainlink-vrf/README.md
+26-6
Original file line number
Diff line number
Diff line change
@@ -8,23 +8,25 @@ This sample code demonstrates how to use ChainLink for NFT blind box design.
8
8
The private key put in **.env** in the format "PRIVATE_KEY= XXXX ", from which the code automatically reads.
9
9
10
10
- Get Link test coins
11
-
Every time you go to ChainLink to request VRF random number, you need to consume Link coins. Therefore, you need to apply for Link test coins before the test. For the Goerli test network, go to [Request testnet LINK](https://faucets.chain.link/goerli?_ga=2.35440098.2104755910.1637393798-1377742816.1635817935) , Then "Netwrok" selects "Ethereum Goerli" and "Testnet Account Address "enters the account address corresponding to PRIVATE_KEY in the **.env** file
Every time you go to ChainLink to request VRF random number, you need to consume Link coins. Therefore, you need to apply for Link test coins before the test. For the Goerli test network, go to [Request testnet LINK](https://faucets.chain.link/goerli?_ga=2.35440098.2104755910.1637393798-1377742816.1635817935) , Then "Netwrok" selects "Ethereum Sepolia" , click "Connect wallet" connect with MeatMask", click "Send Request" for geting 25 Test Link
Login [ChainLink VRF Test network](https://vrf.chain.link/?_ga=2.225785050.1950508783.1645630272-1230768383.1643005305) , Click on "Create Subscription" to Create a SubscriptionID and you can see the created SubscriptionID under "My Subscriptions"
npx hardhat run scripts/deploy.js --network sepolia
46
54
```
55
+
For different test networks (non-sepolia), please refer to [Chain Link: supported-networks](https://docs.chain.link/vrf/v2/subscription/supported-networks), in ./contracts/RandomNumberVRF.sol Modify the values of vrfCoordinator, link, keyHash
56
+
57
+
- Add Consumer
58
+
```
59
+
Click to enter the already created Subscription, click "Add Consumer" to fill in the contract address returned by deploy in the previous step. After filling in, you need to wait for 10 seconds. At this time, refresh the page and you can see the configured consumer address.
npx hardhat run scripts/random-number-vrf.js --network sepolia
51
68
```
69
+
After the requestRandomWords request is sent, it takes a certain amount of time for the ChainLink callback fulfillRandomWords to generate random numbers, which prevents the Main program from ending. Therefore, it is necessary to set up a loop to detect whether the RequestFulfilled event is generated.
52
70
53
-
-Generate random Character
71
+
-Get randomword again
54
72
```
55
73
npx hardhat run scripts/transaction.js --network sepolia
56
74
```
75
+
RandomWords After the random number is generated, it is passed in through the contract. The requestID saved in ./scripts/deployment.json is used to obtain the random number obtained before. You can customize random number usage scenarios. This example is only used as a calling reference.
0 commit comments