Skip to content

Commit

Permalink
feat: upgrade contracts to vrf v2 (#128)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people committed Nov 3, 2022
1 parent e8455f6 commit 4fbaa8b
Show file tree
Hide file tree
Showing 15 changed files with 1,193 additions and 344 deletions.
32 changes: 18 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Built with:

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

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

Expand Down Expand Up @@ -97,6 +97,10 @@ To deploy on a public network:
yarn deploy --network goerli
```

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).

See how to [Create and Fund a Subscription](https://docs.chain.link/docs/vrf/v2/subscription/ui/).

## Auto-Funding

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.
Expand All @@ -105,7 +109,7 @@ The amount in LINK to send as part of this process can be modified in this [Hard

| Parameter | Description | Default Value |
| ---------- | :------------------------------------------------ | :------------ |
| fundAmount | Amount of LINK to transfer when funding contracts | 1 LINK |
| fundAmount | Amount of LINK to transfer when funding contracts | 5 LINK |

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

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

#### Goerli

| Name | Address |
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| `PriceConsumerV3` | [0x870Ad4995160C65A31478Fb438Dca267D6053EAF](https://goerli.etherscan.io/address/0x870Ad4995160C65A31478Fb438Dca267D6053EAF) |
| `APIConsumer` | [0xe40D4f1fDf9f0312905bd938Dd396B9149e1F04b](https://goerli.etherscan.io/address/0xe40D4f1fDf9f0312905bd938Dd396B9149e1F04b) |
| `RandomNumberConsumer` | [0xF498E392f010b6513781418BAfC2F540690F3E13](https://goerli.etherscan.io/address/0xF498E392f010b6513781418BAfC2F540690F3E13) |
| `RandomSVG` | [0xF32b62E03cEeA101B30b0B90aD0038B97f635025](https://goerli.etherscan.io/address/0xF32b62E03cEeA101B30b0B90aD0038B97f635025) |
| Name | Address |
| ---------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| `PriceConsumerV3` | [0x46b73aca4AF8D060355beAb7f3C941B214ba0E1F](https://goerli.etherscan.io/address/0x46b73aca4AF8D060355beAb7f3C941B214ba0E1F) |
| `APIConsumer` | [0xe40D4f1fDf9f0312905bd938Dd396B9149e1F04b](https://goerli.etherscan.io/address/0xe40D4f1fDf9f0312905bd938Dd396B9149e1F04b) |
| `RandomNumberConsumer` | [0x35ea06342a82e091040CbF415cc899228DB4C936](https://goerli.etherscan.io/address/0x35ea06342a82e091040CbF415cc899228DB4C936) |
| `RandomSVG` | [0xa652548CDAb898d9d885896f464Fd4a07F353aBc](https://goerli.etherscan.io/address/0xa652548CDAb898d9d885896f464Fd4a07F353aBc) |

#### Kovan (deprecated)

| Name | Address |
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| `PriceConsumerV3` | [0x01E2C7cA6D6A82D059287Cb0bC43a39Cd0ff4B00](https://kovan.etherscan.io/address/0x01E2C7cA6D6A82D059287Cb0bC43a39Cd0ff4B00) |
| `FeedRegistryConsumer` | [0xB9ebb63D4820c45a2Db09d71cefA24daBd047b50](https://kovan.etherscan.io/address/0xB9ebb63D4820c45a2Db09d71cefA24daBd047b50) |
| `APIConsumer` | [0x14005AB90bc520E20Ffd7815Cae64372abb6b04d](https://kovan.etherscan.io/address/0x14005AB90bc520E20Ffd7815Cae64372abb6b04d) |
| Name | Address |
| ---------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| `PriceConsumerV3` | [0x01E2C7cA6D6A82D059287Cb0bC43a39Cd0ff4B00](https://kovan.etherscan.io/address/0x01E2C7cA6D6A82D059287Cb0bC43a39Cd0ff4B00) |
| `FeedRegistryConsumer` | [0xB9ebb63D4820c45a2Db09d71cefA24daBd047b50](https://kovan.etherscan.io/address/0xB9ebb63D4820c45a2Db09d71cefA24daBd047b50) |
| `APIConsumer` | [0x14005AB90bc520E20Ffd7815Cae64372abb6b04d](https://kovan.etherscan.io/address/0x14005AB90bc520E20Ffd7815Cae64372abb6b04d) |
| `RandomNumberConsumer` | [0xF9556187bf86823Cf0D7081625F97391642Fc242](https://kovan.etherscan.io/address/0xF9556187bf86823Cf0D7081625F97391642Fc242) |
| `RandomSVG` | [0xb4Bac68d9Fa99D2852E5dFb124be74de2E8c4F76](https://kovan.etherscan.io/address/0xb4Bac68d9Fa99D2852E5dFb124be74de2E8c4F76) |
| `RandomSVG` | [0xb4Bac68d9Fa99D2852E5dFb124be74de2E8c4F76](https://kovan.etherscan.io/address/0xb4Bac68d9Fa99D2852E5dFb124be74de2E8c4F76) |

#### Rinkeby (deprecated)

Expand Down
9 changes: 5 additions & 4 deletions packages/frontend/components/vrf/RandomNumber.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useCallback, useEffect, useState } from 'react'
import { Text, Button, Code, Stack } from '@chakra-ui/react'
import { useContractFunction, useEthers } from '@usedapp/core'
import { BigNumber } from 'ethers'
import { getRequestStatus, getContractError } from '../../lib/utils'
import { useContract } from '../../hooks/useContract'
import { Error } from '../Error'
Expand All @@ -10,7 +11,7 @@ import { RandomNumberConsumer } from '../../../types/typechain'
export function RandomNumber(): JSX.Element {
const { account, error } = useEthers()

const [requestId, setRequestId] = useState('')
const [requestId, setRequestId] = useState<BigNumber>()
const [randomNumber, setRandomNumber] = useState('')

const randomNumberConsumer = useContract<RandomNumberConsumer>(
Expand All @@ -20,7 +21,7 @@ export function RandomNumber(): JSX.Element {
const { send, state, events } = useContractFunction(
randomNumberConsumer,
'getRandomNumber',
{ transactionName: 'Randomness Request' }
{ transactionName: 'Randomness Request', gasLimitBufferPercentage: 250 }
)

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

useEffect(() => {
if (randomNumberConsumer && requestId) {
randomNumberConsumer.on('FulfilledRandomness', (id: string) => {
if (requestId === id) {
randomNumberConsumer.on('FulfilledRandomness', (id: BigNumber) => {
if (requestId.eq(id)) {
readRandomNumber()
randomNumberConsumer.removeAllListeners()
}
Expand Down
Loading

2 comments on commit 4fbaa8b

@vercel
Copy link

@vercel vercel bot commented on 4fbaa8b Nov 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

chainlink-fullstack – ./

chainlink-fullstack-hackbg.vercel.app
chainlink-fullstack.vercel.app
chainlink-fullstack-git-main-hackbg.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 4fbaa8b Jan 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.