diff --git a/_includes/sections/vrf-v2-common.md b/_includes/sections/vrf-v2-common.md new file mode 100644 index 00000000000..289cea213ce --- /dev/null +++ b/_includes/sections/vrf-v2-common.md @@ -0,0 +1,7 @@ +> 📘 You are viewing the VRF v2 guide. +> +> If you are using v1, see the [VRF v1 guide](/docs/vrf/v1/introduction/). + +> 🚧 Security Considerations +> +> Be sure to review your contracts with the [security considerations](/docs/vrf/v2/security/) in mind. diff --git a/docs/vrf/v2/best-practices.md b/docs/vrf/v2/best-practices.md index f80d9fd58bb..8929a2479cc 100644 --- a/docs/vrf/v2/best-practices.md +++ b/docs/vrf/v2/best-practices.md @@ -9,9 +9,7 @@ metadata: description: 'Best pracices for using Chainlink VRF.' --- -> 📘 You are viewing the VRF v2 guide. -> -> If you are using v1, see the [VRF v1 guide](/docs/vrf/v1/introduction/). +{% include 'sections/vrf-v2-common.md' %} These are example best practices for using Chainlink VRF. To explore more applications of VRF, refer to our [blog](https://blog.chain.link/). diff --git a/docs/vrf/v2/examples/get-a-random-number.md b/docs/vrf/v2/examples/get-a-random-number.md index a0cc887c6d4..5375a63fb31 100644 --- a/docs/vrf/v2/examples/get-a-random-number.md +++ b/docs/vrf/v2/examples/get-a-random-number.md @@ -16,9 +16,7 @@ metadata: description: 'How to generate a random number inside a smart contract using Chainlink VRF.' --- -> 📘 You are viewing the VRF v2 guide. -> -> If you are using v1, see the [VRF v1 guide](/docs/vrf/v1/introduction/). +{% include 'sections/vrf-v2-common.md' %} This guide explains how to get random values using a simple contract to request and receive random values from Chainlink VRF v2. For more advanced examples with programmatic subscription configuration, see the [Programmatic Subscription](/docs/vrf/v2/examples/programmatic-subscription/) page. To explore more applications of VRF, refer to our [blog](https://blog.chain.link/). diff --git a/docs/vrf/v2/examples/programmatic-subscription.md b/docs/vrf/v2/examples/programmatic-subscription.md index d4bd8f4085e..e5699e15d2a 100644 --- a/docs/vrf/v2/examples/programmatic-subscription.md +++ b/docs/vrf/v2/examples/programmatic-subscription.md @@ -15,9 +15,7 @@ metadata: description: 'Example contracts for generating a random number inside a smart contract using Chainlink VRF v2.' --- -> 📘 You are viewing the VRF v2 guide. -> -> If you are using v1, see the [VRF v1 guide](/docs/vrf/v1/introduction/). +{% include 'sections/vrf-v2-common.md' %} How you manage the subscription depends on your randomness needs. You can configure your subscriptions using the [Subscription Manager](https://vrf.chain.link), but these examples demonstrate how to create your subscription and add your consumer contracts programmatically. For these examples, the contract owns and manages the subscription. You can still view the subscriptions in the [Subscription Manager](https://vrf.chain.link). Any wallet can provide funding to those subscriptions. @@ -31,12 +29,16 @@ How you manage the subscription depends on your randomness needs. You can config Subscription configurations do not have to be static. You can change your subscription configuration dynamically by calling the following functions using the [VRFCoordinatorV2Interface](https://github.com/smartcontractkit/chainlink/blob/develop/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol): -- Change the list of approved subscription consumers with `addConsumer(uint64 subId, address consumer)` or `removeConsumer(uint64 subId, address consumer)`. -- Transfer the subscription ownership with `requestSubscriptionOwnerTransfer(uint64 subId, address newOwner)` and `acceptSubscriptionOwnerTransfer(uint64 subId)`. +- Change the list of approved subscription consumers with: + - `addConsumer(uint64 subId, address consumer)`. + - `removeConsumer(uint64 subId, address consumer)`. +- Transfer the subscription ownership with: + - `requestSubscriptionOwnerTransfer(uint64 subId, address newOwner)`. + - `acceptSubscriptionOwnerTransfer(uint64 subId)`. - View the subscription with `getSubscription(uint64 subId)`. - Cancel the subscription with `cancelSubscription(uint64 subId)`. -To send LINK to the subscription balance, use the LINK token interface with `LINKTOKEN.transferAndCall(address(COORDINATOR), amount, abi.encode(subId));`. Any wallet can fund a subscription. +To send LINK to the subscription balance, use the LINK token interface with `LINKTOKEN.transferAndCall(address(COORDINATOR), amount, abi.encode(subId))`. Any wallet can fund a subscription. See the example in the [Subscription manager contract](#subscription-manager-contract) section to learn how to create a contract that can change your subscription configuration. @@ -44,7 +46,7 @@ See the example in the [Subscription manager contract](#subscription-manager-con In this example, the contract operates as a subscription owner and can run functions to add consumer contracts to the subscription. The consumer contracts must include the `requestRandomWords()` function with the correct coordinator parameters and the correct subscription ID to request random values and use the subscription balance. The consumer contracts must also include the `fulfillRandomWords()` function to receive the random values. -Subscription owners and consumers do not have to be separate. This contract can also act as a consumer by running its own `requestRandomWords()` function, but it must add itself as an approved consumer. This example contract includes functions in the `constructor()` that creates the subscription and adds itself as a consumer automatically when you deploy it. +Subscription owners and consumers do not have to be separate. This contract not only allows adding consumers with `addConsumer(address consumerAddress)` but can also act as a consumer by running its own `requestRandomWords()` function. This example contract includes a `createNewSubscription()` function in the `constructor()` that creates the subscription and adds itself as a consumer automatically when you deploy it. ```solidity {% include 'samples/VRF/VRFv2SubscriptionManager.sol' %} @@ -67,22 +69,26 @@ To use this contract, compile and deploy it in Remix. 1. Run the `topUpSubscription()` function to send LINK from your contract to your subscription balance. For this example, specify a value of `3000000000000000000`, which is equivalent to three LINK. -1. Create and deploy a consumer contract that includes the following components: +1. Run the `requestRandomWords()` function. The request might take several minutes to process. Track pending request status in the [Subscription Manager](https://vrf.chain.link) app. - - The `requestRandomWords()` function and the required variables and your subscription ID - - The `fulfillRandomWords()` callback function +1. Note that you can also add and test consumer contracts using the same programmatic subscription. To do so: - You can use the example from the [Get a Random Number](/docs/vrf/v2/examples/get-a-random-number/#analyzing-the-contract) guide. + 1. Create and deploy a consumer contract that includes the following components: -1. After you deploy the consumer contract, add it to the subscription as an approved consumer using the `addConsumer()` function on your subscription manager contract. Specify the address of your consumer contract. + - The `requestRandomWords()` function and the required variables and your subscription ID. + - The `fulfillRandomWords()` callback function. -1. On the consumer contract, run the `requestRandomWords()` function to request and receive random values. The request might take several minutes to process. Track pending request status in the [Subscription Manager](https://vrf.chain.link) app. + You can use the example from the [Get a Random Number](/docs/vrf/v2/examples/get-a-random-number/#analyzing-the-contract) guide. - The consumer contract can continue to make requests until your subscription balance runs out. The subscription manager contract must maintain sufficient balance in the subscription so that the consumers can continue to operate. + 1. After you deploy the consumer contract, add it to the subscription as an approved consumer using the `addConsumer()` function on your subscription manager contract. Specify the address of your consumer contract. -1. When you are done with your contracts and the subscription, run the `cancelSubscription()` to close the subscription and send the remaining LINK to your wallet address. Specify the address of the receiving wallet. + 1. On the consumer contract, run the `requestRandomWords()` function to request and receive random values. The request might take several minutes to process. Track pending request status in the [Subscription Manager](https://vrf.chain.link) app. -If you need to remove consumer contracts from the subscription, use the `removeConsumer()` function. Specify the address of the consumer contract to be removed. + The consumer contract can continue to make requests until your subscription balance runs out. The subscription manager contract must maintain sufficient balance in the subscription so that the consumers can continue to operate. + + 1. If you need to remove consumer contracts from the subscription, use the `removeConsumer()` function. Specify the address of the consumer contract to be removed. + +1. When you are done with your contracts and the subscription, run the `cancelSubscription()` function to close the subscription and send the remaining LINK to your wallet address. Specify the address of the receiving wallet. ## Funding and requesting simultaneously @@ -93,7 +99,3 @@ You can fund a subscription and request randomness in a single transaction. This ``` Add this function to your contracts if you need to provide funding simultaneously with your requests. The `transferAndCall()` function sends LINK from your contract to the subscription, and the `requestRandomWords()` function requests the random words. Your contract still needs the `fulfillRandomWords()` callback function to receive the random values. - -> 🚧 Security Considerations -> -> Be sure to review your contract with the [security considerations](/docs/vrf/v2/security/) in mind. diff --git a/docs/vrf/v2/introduction.md b/docs/vrf/v2/introduction.md index 403799f8562..ba2bb6c69f7 100644 --- a/docs/vrf/v2/introduction.md +++ b/docs/vrf/v2/introduction.md @@ -4,7 +4,11 @@ section: ethereum date: Last Modified title: 'Introduction to Chainlink VRF' permalink: 'docs/vrf/v2/introduction/' -whatsnext: { 'Get a Random Number': '/docs/vrf/v2/examples/get-a-random-number/', 'Supported Networks': '/docs/vrf/v2/supported-networks/' } +whatsnext: + { + 'Get a Random Number': '/docs/vrf/v2/examples/get-a-random-number/', + 'Supported Networks': '/docs/vrf/v2/supported-networks/', + } metadata: title: 'Generate Random Numbers for Smart Contracts using Chainlink VRF' description: 'Learn how to securely generate random numbers for your smart contract with Chainlink VRF (an RNG). This guide uses Solidity code examples.' @@ -12,9 +16,7 @@ metadata: ![Chainlink](/files/a4c6c80-85d09b6-19facd8-banner.png) -> 📘 You are viewing the VRF v2 guide. -> -> If you are using v1, see the [VRF v1 guide](/docs/vrf/v1/introduction/). +{% include 'sections/vrf-v2-common.md' %} Chainlink VRF (Verifiable Random Function) is a provably fair and verifiable random number generator (RNG) that enables smart contracts to access random values without compromising security or usability. diff --git a/docs/vrf/v2/migration-from-v1.md b/docs/vrf/v2/migration-from-v1.md index c36e68e7a6f..64df5e199c6 100644 --- a/docs/vrf/v2/migration-from-v1.md +++ b/docs/vrf/v2/migration-from-v1.md @@ -6,9 +6,7 @@ title: 'Migrating to VRF v2' permalink: 'docs/vrf/v2/migration-from-v1/' --- -> 📘 You are viewing the VRF v2 guide. -> -> If you are using v1, see the [VRF v1 guide](/docs/vrf/v1/introduction/). +{% include 'sections/vrf-v2-common.md' %} ## Comparison between VRF v1 and VRF v2 diff --git a/docs/vrf/v2/security.md b/docs/vrf/v2/security.md index 90bcbfc924c..99a554f962d 100644 --- a/docs/vrf/v2/security.md +++ b/docs/vrf/v2/security.md @@ -6,9 +6,7 @@ title: 'VRF Security Considerations' permalink: 'docs/vrf/v2/security/' --- -> 📘 You are viewing the VRF v2 guide. -> -> If you are using v1, see the [VRF v1 guide](/docs/vrf/v1/introduction/). +{% include 'sections/vrf-v2-common.md' %} Gaining access to high quality randomness on-chain requires a solution like Chainlink's VRF, but it also requires you to understand some of the ways that miners or validators can potentially manipulate randomness generation. Here are some of the top security considerations you should review in your project. diff --git a/docs/vrf/v2/supported-networks.md b/docs/vrf/v2/supported-networks.md index 56225512977..9d18c96040f 100644 --- a/docs/vrf/v2/supported-networks.md +++ b/docs/vrf/v2/supported-networks.md @@ -11,9 +11,7 @@ metadata: 0: '/files/OpenGraph_V3.png' --- -> 📘 You are viewing the VRF v2 guide. -> -> If you are using v1, see the [VRF v1 guide](/docs/vrf/v1/introduction/). +{% include 'sections/vrf-v2-common.md' %} Chainlink VRF allows you to integrate provably fair and verifiably random data in your smart contract. @@ -243,13 +241,13 @@ The Rinkeby network is [officially deprecated](https://ethereum.org/en/developer > > Testnet LINK is available from [facuets.chain.link](https://faucets.chain.link/klaytn-testnet). Use the [KLAY Faucet](https://baobab.wallet.klaytn.foundation/faucet) to obtain testnet KLAY. -| Item | Value | -| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| Item | Value | +| --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | LINK Token | `0x04c5046A1f4E3fFf094c26dFCAA75eF293932f18` | -| VRF Coordinator | [`0x771143FcB645128b07E41D79D82BE707ad8bDa1C`](https://baobab.scope.klaytn.com/address/0x771143FcB645128b07E41D79D82BE707ad8bDa1C) | -| 750 gwei Key Hash | `0x9be50e2346ee6abe000e6d3a34245e1d232c669703efc44660a413854427027c` | -| Premium | 0.005 LINK | -| Max Gas Limit | 2,500,000 | -| Minimum Confirmations | 1 | -| Maximum Confirmations | 200 | -| Maximum Random Values | 500 | +| VRF Coordinator | [`0x771143FcB645128b07E41D79D82BE707ad8bDa1C`](https://baobab.scope.klaytn.com/address/0x771143FcB645128b07E41D79D82BE707ad8bDa1C) | +| 750 gwei Key Hash | `0x9be50e2346ee6abe000e6d3a34245e1d232c669703efc44660a413854427027c` | +| Premium | 0.005 LINK | +| Max Gas Limit | 2,500,000 | +| Minimum Confirmations | 1 | +| Maximum Confirmations | 200 | +| Maximum Random Values | 500 |