Skip to content

Commit 4fbaa8b

Browse files
Petia Latinovaivaylonikolov7imollov
authored
feat: upgrade contracts to vrf v2 (#128)
* use vrf v2 direct funding for RandomNumberConsumer * use vrf v2 subscription for RandomSVG * change auto fund amount to 5 LINK Co-authored-by: ivaylonikolov7 <ivnikolov721@gmail.com> Co-authored-by: imollov <ivomollov@gmail.com>
1 parent e8455f6 commit 4fbaa8b

15 files changed

+1193
-344
lines changed

README.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Built with:
3030

3131
In order to use the frontend portion of the demo application you will need
3232

33-
- A crypto wallet such as [Metamask](https://metamask.io/) or [Coinbase Wallet](https://www.coinbase.com/wallet)
33+
- A crypto wallet such as [Metamask](https://metamask.io/) or [Coinbase Wallet](https://www.coinbase.com/wallet)
3434
- Test $LINK for the relevant testnet. You can get some at the [Chainlink Faucets](https://faucets.chain.link/) page.
3535
- Test $ETH to pay for gas costs. You can get some at the [Chainlink Faucets](https://faucets.chain.link/) page.
3636

@@ -97,6 +97,10 @@ To deploy on a public network:
9797
yarn deploy --network goerli
9898
```
9999

100+
Before deploying `RandomSVG` contract on a public network, an ID of a prefunded VRF subscription must be set in [`helper-hardhat-config.ts`](/packages/hardhat/helper-hardhat-config.ts).
101+
102+
See how to [Create and Fund a Subscription](https://docs.chain.link/docs/vrf/v2/subscription/ui/).
103+
100104
## Auto-Funding
101105

102106
The Hardhat project will attempt to auto-fund any newly deployed contract that uses Any-API or VRF, which otherwise has to be done manually.
@@ -105,7 +109,7 @@ The amount in LINK to send as part of this process can be modified in this [Hard
105109

106110
| Parameter | Description | Default Value |
107111
| ---------- | :------------------------------------------------ | :------------ |
108-
| fundAmount | Amount of LINK to transfer when funding contracts | 1 LINK |
112+
| fundAmount | Amount of LINK to transfer when funding contracts | 5 LINK |
109113

110114
If you wish to deploy the smart contracts without performing the auto-funding, run the following command when doing your deployment:
111115

@@ -170,22 +174,22 @@ Once the `deploy` command is executed on any network the contracts config will b
170174

171175
#### Goerli
172176

173-
| Name | Address |
174-
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
175-
| `PriceConsumerV3` | [0x870Ad4995160C65A31478Fb438Dca267D6053EAF](https://goerli.etherscan.io/address/0x870Ad4995160C65A31478Fb438Dca267D6053EAF) |
176-
| `APIConsumer` | [0xe40D4f1fDf9f0312905bd938Dd396B9149e1F04b](https://goerli.etherscan.io/address/0xe40D4f1fDf9f0312905bd938Dd396B9149e1F04b) |
177-
| `RandomNumberConsumer` | [0xF498E392f010b6513781418BAfC2F540690F3E13](https://goerli.etherscan.io/address/0xF498E392f010b6513781418BAfC2F540690F3E13) |
178-
| `RandomSVG` | [0xF32b62E03cEeA101B30b0B90aD0038B97f635025](https://goerli.etherscan.io/address/0xF32b62E03cEeA101B30b0B90aD0038B97f635025) |
177+
| Name | Address |
178+
| ---------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
179+
| `PriceConsumerV3` | [0x46b73aca4AF8D060355beAb7f3C941B214ba0E1F](https://goerli.etherscan.io/address/0x46b73aca4AF8D060355beAb7f3C941B214ba0E1F) |
180+
| `APIConsumer` | [0xe40D4f1fDf9f0312905bd938Dd396B9149e1F04b](https://goerli.etherscan.io/address/0xe40D4f1fDf9f0312905bd938Dd396B9149e1F04b) |
181+
| `RandomNumberConsumer` | [0x35ea06342a82e091040CbF415cc899228DB4C936](https://goerli.etherscan.io/address/0x35ea06342a82e091040CbF415cc899228DB4C936) |
182+
| `RandomSVG` | [0xa652548CDAb898d9d885896f464Fd4a07F353aBc](https://goerli.etherscan.io/address/0xa652548CDAb898d9d885896f464Fd4a07F353aBc) |
179183

180184
#### Kovan (deprecated)
181185

182-
| Name | Address |
183-
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
184-
| `PriceConsumerV3` | [0x01E2C7cA6D6A82D059287Cb0bC43a39Cd0ff4B00](https://kovan.etherscan.io/address/0x01E2C7cA6D6A82D059287Cb0bC43a39Cd0ff4B00) |
185-
| `FeedRegistryConsumer` | [0xB9ebb63D4820c45a2Db09d71cefA24daBd047b50](https://kovan.etherscan.io/address/0xB9ebb63D4820c45a2Db09d71cefA24daBd047b50) |
186-
| `APIConsumer` | [0x14005AB90bc520E20Ffd7815Cae64372abb6b04d](https://kovan.etherscan.io/address/0x14005AB90bc520E20Ffd7815Cae64372abb6b04d) |
186+
| Name | Address |
187+
| ---------------------- | --------------------------------------------------------------------------------------------------------------------------- |
188+
| `PriceConsumerV3` | [0x01E2C7cA6D6A82D059287Cb0bC43a39Cd0ff4B00](https://kovan.etherscan.io/address/0x01E2C7cA6D6A82D059287Cb0bC43a39Cd0ff4B00) |
189+
| `FeedRegistryConsumer` | [0xB9ebb63D4820c45a2Db09d71cefA24daBd047b50](https://kovan.etherscan.io/address/0xB9ebb63D4820c45a2Db09d71cefA24daBd047b50) |
190+
| `APIConsumer` | [0x14005AB90bc520E20Ffd7815Cae64372abb6b04d](https://kovan.etherscan.io/address/0x14005AB90bc520E20Ffd7815Cae64372abb6b04d) |
187191
| `RandomNumberConsumer` | [0xF9556187bf86823Cf0D7081625F97391642Fc242](https://kovan.etherscan.io/address/0xF9556187bf86823Cf0D7081625F97391642Fc242) |
188-
| `RandomSVG` | [0xb4Bac68d9Fa99D2852E5dFb124be74de2E8c4F76](https://kovan.etherscan.io/address/0xb4Bac68d9Fa99D2852E5dFb124be74de2E8c4F76) |
192+
| `RandomSVG` | [0xb4Bac68d9Fa99D2852E5dFb124be74de2E8c4F76](https://kovan.etherscan.io/address/0xb4Bac68d9Fa99D2852E5dFb124be74de2E8c4F76) |
189193

190194
#### Rinkeby (deprecated)
191195

packages/frontend/components/vrf/RandomNumber.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useCallback, useEffect, useState } from 'react'
22
import { Text, Button, Code, Stack } from '@chakra-ui/react'
33
import { useContractFunction, useEthers } from '@usedapp/core'
4+
import { BigNumber } from 'ethers'
45
import { getRequestStatus, getContractError } from '../../lib/utils'
56
import { useContract } from '../../hooks/useContract'
67
import { Error } from '../Error'
@@ -10,7 +11,7 @@ import { RandomNumberConsumer } from '../../../types/typechain'
1011
export function RandomNumber(): JSX.Element {
1112
const { account, error } = useEthers()
1213

13-
const [requestId, setRequestId] = useState('')
14+
const [requestId, setRequestId] = useState<BigNumber>()
1415
const [randomNumber, setRandomNumber] = useState('')
1516

1617
const randomNumberConsumer = useContract<RandomNumberConsumer>(
@@ -20,7 +21,7 @@ export function RandomNumber(): JSX.Element {
2021
const { send, state, events } = useContractFunction(
2122
randomNumberConsumer,
2223
'getRandomNumber',
23-
{ transactionName: 'Randomness Request' }
24+
{ transactionName: 'Randomness Request', gasLimitBufferPercentage: 250 }
2425
)
2526

2627
const requestRandomNumber = async () => {
@@ -44,8 +45,8 @@ export function RandomNumber(): JSX.Element {
4445

4546
useEffect(() => {
4647
if (randomNumberConsumer && requestId) {
47-
randomNumberConsumer.on('FulfilledRandomness', (id: string) => {
48-
if (requestId === id) {
48+
randomNumberConsumer.on('FulfilledRandomness', (id: BigNumber) => {
49+
if (requestId.eq(id)) {
4950
readRandomNumber()
5051
randomNumberConsumer.removeAllListeners()
5152
}

0 commit comments

Comments
 (0)