diff --git a/public/images/vrf/v2-5-migration.png b/public/images/vrf/v2-5-migration.png new file mode 100644 index 00000000000..a3cf15f6f83 Binary files /dev/null and b/public/images/vrf/v2-5-migration.png differ diff --git a/public/images/vrf/vrf-diagram.png b/public/images/vrf/vrf-diagram.png new file mode 100644 index 00000000000..3dab8335a98 Binary files /dev/null and b/public/images/vrf/vrf-diagram.png differ diff --git a/src/config/sidebar.ts b/src/config/sidebar.ts index b5718e5d2e8..ec0b373c072 100644 --- a/src/config/sidebar.ts +++ b/src/config/sidebar.ts @@ -741,18 +741,8 @@ export const SIDEBAR: Partial> = { section: "Chainlink VRF v2.5", contents: [ { - title: "V2.5 Overview", + title: "Introduction to VRF", url: "vrf", - children: [ - { - title: "Subscription overview", - url: "vrf/v2-5/overview/subscription", - }, - { - title: "Direct funding overview", - url: "vrf/v2-5/overview/direct-funding", - }, - ], }, { title: "Migration from V2", @@ -774,75 +764,52 @@ export const SIDEBAR: Partial> = { title: "V2.5 Billing", url: "vrf/v2-5/billing", }, - { - title: "Create and manage V2.5 subscriptions", - url: "vrf/v2-5/subscription/create-manage", - }, { title: "Release Notes", url: "vrf/release-notes", }, - { - title: "Arbitrum gas estimation with VRF", - url: "vrf/v2-5/arbitrum-cost-estimation", - }, ], }, { - section: "V2 Subscription Method", + section: "Learn VRF V2.5", contents: [ { - title: "Introduction", - url: "vrf/v2/subscription", - }, - { - title: "Get a Random Number", - url: "vrf/v2/subscription/examples/get-a-random-number", - }, - { - title: "Programmatic Subscription", - url: "vrf/v2/subscription/examples/programmatic-subscription", - }, - { - title: "Test Locally Using a Mock Contract", - url: "vrf/v2/subscription/examples/test-locally", + title: "Introduction to subscription", + url: "vrf/v2-5/overview/subscription", }, { - title: "Subscription Manager UI", - url: "vrf/v2/subscription/ui", + title: "Introduction to direct funding", + url: "vrf/v2-5/overview/direct-funding", }, { - title: "Supported Networks", - url: "vrf/v2/subscription/supported-networks", - }, - { - title: "Migrating from VRF v1", - url: "vrf/v2/subscription/migration-from-v1", + title: "Arbitrum gas estimation with VRF", + url: "vrf/v2-5/arbitrum-cost-estimation", }, ], }, { - section: "V2 Direct Funding Method", + section: "Build with VRF 2.5", contents: [ { - title: "Introduction", - url: "vrf/v2/direct-funding", - }, - { - title: "Get a Random Number", - url: "vrf/v2/direct-funding/examples/get-a-random-number", + title: "Create and manage V2.5 subscriptions", + url: "vrf/v2-5/subscription/create-manage", }, { - title: "Test Locally Using a Mock Contract", - url: "vrf/v2/direct-funding/examples/test-locally", + title: "Migrate from VRF v1", + url: "vrf/v2-5/migration-from-v1", }, + ], + }, + { + section: "All VRF V2 documentation", + contents: [ { - title: "Supported Networks", - url: "vrf/v2/direct-funding/supported-networks", + title: "VRF V2 Subscription", + url: "vrf/v2/subscription", }, { - title: "Migrating from VRF v1", - url: "vrf/v2/direct-funding/migration-from-v1", + title: "VRF V2 Direct Funding", + url: "vrf/v2/direct-funding", }, ], }, @@ -1435,17 +1402,53 @@ export const SIDEBAR: Partial> = { ], legacy: [ { - section: "VRF v1 [DEPRECATED]", + section: "V2 Subscription Method", contents: [ - { title: "Introduction to Chainlink VRF", url: "vrf/v1/introduction" }, + { + title: "Introduction", + url: "vrf/v2/subscription", + }, { title: "Get a Random Number", - url: "vrf/v1/examples/get-a-random-number", + url: "vrf/v2/subscription/examples/get-a-random-number", + }, + { + title: "Programmatic Subscription", + url: "vrf/v2/subscription/examples/programmatic-subscription", + }, + { + title: "Test Locally Using a Mock Contract", + url: "vrf/v2/subscription/examples/test-locally", + }, + { + title: "Subscription Manager UI", + url: "vrf/v2/subscription/ui", + }, + { + title: "Supported Networks", + url: "vrf/v2/subscription/supported-networks", + }, + ], + }, + { + section: "V2 Direct Funding Method", + contents: [ + { + title: "Introduction", + url: "vrf/v2/direct-funding", + }, + { + title: "Get a Random Number", + url: "vrf/v2/direct-funding/examples/get-a-random-number", + }, + { + title: "Test Locally Using a Mock Contract", + url: "vrf/v2/direct-funding/examples/test-locally", + }, + { + title: "Supported Networks", + url: "vrf/v2/direct-funding/supported-networks", }, - { title: "Security Considerations", url: "vrf/v1/security" }, - { title: "Best Practices", url: "vrf/v1/best-practices" }, - { title: "Supported Networks", url: "vrf/v1/supported-networks" }, - { title: "API Reference", url: "vrf/v1/api-reference" }, ], }, { diff --git a/src/content/vrf/index.mdx b/src/content/vrf/index.mdx index 606a2b227f0..e69e5f2c31c 100644 --- a/src/content/vrf/index.mdx +++ b/src/content/vrf/index.mdx @@ -11,7 +11,7 @@ metadata: --- import VrfCommon from "@features/vrf/v2-5/VrfCommon.astro" -import { Aside } from "@components" +import { Aside, ClickToZoom } from "@components" @@ -28,13 +28,16 @@ Use Chainlink VRF to build reliable smart contracts for any applications that re - Random assignment of duties and resources. For example, randomly assigning judges to cases. - Choosing a representative sample for consensus mechanisms. -VRF v2.5 includes [all the original benefits of v2](https://blog.chain.link/vrf-v2-mainnet-launch/) and the following additional benefits: +[VRF v2.5](https://blog.chain.link/introducing-vrf-v2-5/) includes [all the original benefits of v2](https://blog.chain.link/vrf-v2-mainnet-launch/) and the following additional benefits: - Easier upgrades to future versions. - The option to pay for requests in either LINK or native tokens. +- Gas optimization Learn how to [migrate to VRF v2.5](/vrf/v2-5/migration-from-v2). + + For help with your specific use case, [contact us](https://chain.link/contact) to connect with one of our Solutions Architects. You can also ask questions about Chainlink VRF on [Stack Overflow](https://stackoverflow.com/questions/ask?tags=chainlink). ## Two methods to request randomness diff --git a/src/content/vrf/v2-5/migration-from-v1.mdx b/src/content/vrf/v2-5/migration-from-v1.mdx new file mode 100644 index 00000000000..3ed26c9c199 --- /dev/null +++ b/src/content/vrf/v2-5/migration-from-v1.mdx @@ -0,0 +1,173 @@ +--- +section: vrf +date: Last Modified +title: "Migrate from VRF v1" +--- + +import { Aside } from "@components" +import { Tabs, TabsContent } from "@components/Tabs" + +## Comparison between VRF v1 and VRF v2.5 + +For a more similar payment experience to V1, use the direct funding method. +Otherwise, you can fund a subscription to prepay for VRF requests. In both cases, VRF V2.5 allows you the option to pay in either native tokens or LINK. + +{/* prettier-ignore */} + +Subscription +Direct funding + +Chainlink VRF v2.5 includes several improvements and changes to the way you fund and request randomness for your smart contracts. + +- **Subscription management:** Chainlink VRF v2.5 introduces a [Subscription Manager](https://vrf.chain.link) application that allows smart contract applications to pre-fund multiple requests for randomness using either a LINK token balance or a native token balance. This reduces the gas fees for VRF requests by eliminating the need to transfer tokens for each individual request. You transfer tokens to the subscription balance only when it requires additional funding. + +- **Variable Callback Gas Limit:** Chainlink VRF v2.5 lets you adjust the callback gas limit when your smart contract application receives verifiable randomness. Consuming contracts can execute more complex logic in the callback request function that receives the random values. Tasks involving the delivered randomness are handled during the response process. The new gas limits are higher than the VRF V1 limit, and vary depending on the underlying blockchain you use. See the gas limits on the [VRF V2.5 Supported Networks](/vrf/v2-5/supported-networks) page. + +- **More configuration capability:** You can define how many block confirmations must pass before verifiable randomness is generated and delivered onchain when your application makes a request transaction. The range is from 3 to 200 blocks. VRF V1 always waited 10 blocks on Ethereum before delivering onchain randomness. Select a value that protects your application from block re-organizations while still providing sufficiently low latency from request to response. See the [Security Considerations](/vrf/v2-5/security) page to learn more. + +- **Multiple Random Outputs in a Single Request:** The [VRF Coordinator contracts](/vrf/v2-5/supported-networks) in VRF v2.5 allow you to request multiple random numbers (multi-word) in a single onchain transaction, which reduces gas costs. The fulfillment is also a single transaction, which reduces the latency of responses. + +- **Unified Billing - Delegate Subscription Balance to Multiple Addresses:** Chainlink VRF v2.5 allows up to 100 smart contract addresses to fund their requests for verifiable randomness from a single subscription, which is managed by the subscription owner. Your subscription has balances for LINK and for native tokens. + + + + +The main similarity between VRF v1 and the VRF v2.5 Direct funding method is that consuming contracts must be funded to pay for requests. However, Chainlink VRF v2.5 includes several improvements: + +- **Native token billing:** Chainlink VRF v2.5 lets you fund your consuming contract with either LINK or native tokens to pay for VRF requests. + +- **Variable Callback Gas Limit:** Chainlink VRF v2.5 lets you adjust the callback gas limit when your smart contract application receives verifiable randomness. Consuming contracts can execute more complex logic in the callback request function that receives the random values. Tasks involving the delivered randomness are handled during the response process. The new gas limits are higher than the VRF V1 limit, and vary depending on the underlying blockchain that you use. See the gas limits on the [Supported networks](/vrf/v2-5/supported-networks) page. + +- **More configuration capability:** You can define how many block confirmations must pass before verifiable randomness is generated and delivered onchain when your application makes a request transaction. The range is from 3 to 200 blocks. VRF V1 always waited 10 blocks on Ethereum before delivering onchain randomness. Select a value that protects your application from block re-organizations while still providing sufficiently low latency from request to response. See the [Security Considerations](/vrf/v2-5/security) page to learn more. + +- **Multiple Random Outputs in a Single Request:** The [VRF Wrapper contracts](/vrf/v2-5/supported-networks) in VRF v2.5 allow you to request multiple random numbers (multi-word) in a single onchain transaction, which reduces gas costs. The fulfillment is also a single transaction, which reduces the latency of responses. + + + + +## Updating your applications to use VRF v2 + +{/* prettier-ignore */} + +Subscription +Direct funding + +To modify your existing smart contract code to work with VRF v2.5, complete the following changes. See the [Migration from V2](/vrf/v2-5/migration-from-v2#compare-example-code) guide for an example. + +1. Set up and fund a subscription in the Subscription Manager at [vrf.chain.link](https://vrf.chain.link). + {/* prettier-ignore */} + + + +1. Import the [`VRFConsumerBaseV2Plus`](https://github.com/smartcontractkit/chainlink/blob/develop/contracts/src/v0.8/vrf/dev/VRFConsumerBaseV2Plus.sol) contract and remove the v1 `VRFConsumerBase.sol` import. This contract includes the `fulfillRandomWords` function. + +1. Import the VRF v2.5 coordinator, [`VRFCoordinatorV2_5`](https://github.com/smartcontractkit/chainlink/blob/develop/contracts/src/v0.8/vrf/dev/VRFCoordinatorV2_5.sol). This interface includes the new `requestRandomWords` function. + +1. Add a `VRFConsumerBaseV2Plus` constructor, passing in the LINK token address for the network you're using. + +1. Change `requestRandomness` function calls to `requestRandomWords`. The `requestRandomWords` function requires several additional parameters. Make sure to include the `extraArgs` part of the `VRFV2PlusClient.RandomWordsRequest` mapping, and use `nativePayment` to specify whether or not you want to pay for VRF requests using native tokens: + + {/* prettier-ignore */} + + LINK + Native tokens + + {/* prettier-ignore */} + ```solidity + uint256 requestId = s_vrfCoordinator.requestRandomWords( + VRFV2PlusClient.RandomWordsRequest({ + keyHash: keyHash, + subId: s_vrfSubscriptionId, + requestConfirmations: requestConfirmations, + callbackGasLimit: callbackGasLimit, + numWords: numWords, + extraArgs: VRFV2PlusClient._argsToBytes(VRFV2PlusClient.ExtraArgsV1({nativePayment: false})) + }) + ); + ``` + + + {/* prettier-ignore */} + ```solidity + uint256 requestId = s_vrfCoordinator.requestRandomWords( + VRFV2PlusClient.RandomWordsRequest({ + keyHash: keyHash, + subId: s_vrfSubscriptionId, + requestConfirmations: requestConfirmations, + callbackGasLimit: callbackGasLimit, + numWords: numWords, + extraArgs: VRFV2PlusClient._argsToBytes(VRFV2PlusClient.ExtraArgsV1({nativePayment: true})) + }) + ); + ``` + + + +1. Change `fulfillRandomness` function calls to `fulfillRandomWords`. Update the call to handle the returned `uint256[]` array instead of the single `uint256` variable. + + + + +To modify your existing smart contract code to work with VRF v2, complete the following changes. See the [Migration from V2](/vrf/v2-5/migration-from-v2#compare-example-code) guide for an example. + + + +1. Import and inherit the new [`VRFV2PlusWrapperConsumerBase`](https://github.com/smartcontractkit/chainlink/blob/master/contracts/src/v0.8/vrf/dev/VRFV2PlusWrapperConsumerBase.sol) and remove the v1 `VRFConsumerBase.sol` import. This contract includes the `fulfillRandomWords` function. + +1. Add a `VRFV2WrapperConsumerBase` constructor, passing in the VRF wrapper address for the network you're using. + +1. You can still call the `requestRandomness` function. However, the v2.5 `requestRandomness` function requires several different parameters (`callbackGasLimit` , `requestConfirmations` , `numWords` and `extraArgs`). See the [Supported networks](/vrf/v2-5/supported-networks) page to adjust them for your own needs. + + Use `nativePayment` to specify whether or not you want to pay for VRF requests using native tokens: + + {/* prettier-ignore */} + + LINK + Native tokens + + + {/* prettier-ignore */} + ```solidity + bytes memory extraArgs = VRFV2PlusClient._argsToBytes( + VRFV2PlusClient.ExtraArgsV1({nativePayment: false}) + ); + (uint256 reqId, uint256 reqPrice) = requestRandomness( + callbackGasLimit, + requestConfirmations, + numWords, + extraArgs + ); + ``` + + + + + {/* prettier-ignore */} + ```solidity + bytes memory extraArgs = VRFV2PlusClient._argsToBytes( + VRFV2PlusClient.ExtraArgsV1({nativePayment: true}) + ); + (uint256 reqId, uint256 reqPrice) = requestRandomness( + callbackGasLimit, + requestConfirmations, + numWords, + extraArgs + ); + ``` + + + +1. Change `fulfillRandomness` function calls to `fulfillRandomWords`. Update the call to handle the returned `uint256[]` array instead of the single `uint256` variable. + + + diff --git a/src/content/vrf/v2-5/migration-from-v2.mdx b/src/content/vrf/v2-5/migration-from-v2.mdx index 8598fdc9c5a..a3e6109ee31 100644 --- a/src/content/vrf/v2-5/migration-from-v2.mdx +++ b/src/content/vrf/v2-5/migration-from-v2.mdx @@ -5,7 +5,7 @@ title: "Migrating from VRF v2" --- import VrfCommon from "@features/vrf/v2-5/VrfCommon.astro" -import { Aside, CodeSample } from "@components" +import { Aside, ClickToZoom, CodeSample } from "@components" import { Tabs, TabsContent } from "@components/Tabs" @@ -14,7 +14,7 @@ import { Tabs, TabsContent } from "@components/Tabs" Chainlink VRF v2.5 includes [all the same key benefits as VRF v2](https://blog.chain.link/vrf-v2-mainnet-launch/), along with the following additional benefits and changes: -- Easier upgrades to future versions by using the new `setCoordinator` function +- Easier upgrades to future versions by using the new `setCoordinator` function, or by using a simplified UI migration from V2.5 to future versions - The option to pay for requests in either LINK or native tokens - New, flexible request format in `requestRandomWords` to make any future upgrades easier @@ -113,7 +113,7 @@ To modify your existing smart contract code to work with VRF v2.5, complete the 1. Add a `VRFConsumerBaseV2Plus` constructor, passing in the LINK token address for the network you're using. -1. Update your `requestRandomWords` function calls to reflect the new request structure for VRF v2.5. Make sure to include the new `extraArgs` part of the `VRFV2PlusClient.RandomWordsRequest` mapping, and specify whether or not you want to pay for VRF requests using native tokens: +1. Update your `requestRandomWords` function calls to reflect the new request structure for VRF v2.5. Make sure to include the new `extraArgs` part of the `VRFV2PlusClient.RandomWordsRequest` mapping, and use `nativePayment` to specify whether or not you want to pay for VRF requests using native tokens: {/* prettier-ignore */} @@ -528,3 +528,9 @@ ConfirmedOwner + +## Future minor version upgrades + +After you complete your initial migration from V2, any future upgrades to minor versions of VRF V2.5 follow a simplified process where your subscription, along with its balances, metadata, and consumers, is transferred to the VRF coordinator for the new minor version: + + diff --git a/src/content/vrf/v2/best-practices.mdx b/src/content/vrf/v2/best-practices.mdx index bff85fa5ab0..7b8d5e04e93 100644 --- a/src/content/vrf/v2/best-practices.mdx +++ b/src/content/vrf/v2/best-practices.mdx @@ -1,5 +1,5 @@ --- -section: vrf +section: legacy date: Last Modified title: "VRF Best Practices" metadata: diff --git a/src/content/vrf/v2/direct-funding/examples/get-a-random-number.mdx b/src/content/vrf/v2/direct-funding/examples/get-a-random-number.mdx index ee5c76feb18..8796ddc0ffc 100644 --- a/src/content/vrf/v2/direct-funding/examples/get-a-random-number.mdx +++ b/src/content/vrf/v2/direct-funding/examples/get-a-random-number.mdx @@ -1,5 +1,5 @@ --- -section: vrf +section: legacy date: Last Modified title: "Get a Random Number" whatsnext: diff --git a/src/content/vrf/v2/direct-funding/examples/test-locally.mdx b/src/content/vrf/v2/direct-funding/examples/test-locally.mdx index 2e31aa016b3..7c5c4f91a6a 100644 --- a/src/content/vrf/v2/direct-funding/examples/test-locally.mdx +++ b/src/content/vrf/v2/direct-funding/examples/test-locally.mdx @@ -1,5 +1,5 @@ --- -section: vrf +section: legacy title: "Local testing using a Mock contract" metadata: description: "Example contract for generating random words using the VRF v2 direct funding method on your local blockchain using a mock contract." diff --git a/src/content/vrf/v2/direct-funding/index.mdx b/src/content/vrf/v2/direct-funding/index.mdx index 0910a2cb2d7..6b0593f4449 100644 --- a/src/content/vrf/v2/direct-funding/index.mdx +++ b/src/content/vrf/v2/direct-funding/index.mdx @@ -1,5 +1,5 @@ --- -section: vrf +section: legacy date: Last Modified title: "Direct Funding Method" isIndex: true diff --git a/src/content/vrf/v2/direct-funding/migration-from-v1.mdx b/src/content/vrf/v2/direct-funding/migration-from-v1.mdx deleted file mode 100644 index 0bd2c654bec..00000000000 --- a/src/content/vrf/v2/direct-funding/migration-from-v1.mdx +++ /dev/null @@ -1,31 +0,0 @@ ---- -section: vrf -date: Last Modified -title: "Migrating from VRF v1" ---- - -import VrfCommon from "@features/vrf/v2/common/VrfCommon.astro" - - - -## Comparison between VRF v1 and VRF v2 (Direct funding method) - -The main similarity between VRF v1 and VRF v2 Direct funding method is that consuming contracts must be funded with LINK to pay for requests. However, Chainlink VRF v2 includes several improvements. - -- **Variable Callback Gas Limit:** Chainlink VRF v2 lets you adjust the callback gas limit when your smart contract application receives verifiable randomness. Consuming contracts can execute more complex logic in the callback request function that receives the random values. Tasks involving the delivered randomness are handled during the response process. The new gas limits are higher than the VRF V1 limit, and vary depending on the underlying blockchain that you use. See the gas limits on the [Supported networks](/vrf/v2/direct-funding/supported-networks) page. - -- **More configuration capability:** You can define how many block confirmations must pass before verifiable randomness is generated and delivered onchain when your application makes a request transaction. The range is from 3 to 200 blocks. VRF V1 always waited 10 blocks on Ethereum before delivering onchain randomness. Select a value that protects your application from block re-organizations while still providing sufficiently low latency from request to response. See the [Security Considerations](/vrf/v2/security) page to learn more. - -- **Multiple Random Outputs in a Single Request:** The [VRF Wrapper contracts](/vrf/v2/direct-funding/supported-networks) in VRF v2 allow you to request multiple random numbers (multi-word) in a single onchain transaction, which reduces gas costs. The fulfillment is also a single transaction, which reduces the latency of responses. - -## Updating your applications to use VRF v2 - -To modify your existing smart contract code to work with VRF v2, complete the following changes. See the [Get a Random Number](/vrf/v2/direct-funding/examples/get-a-random-number) guide for an example. - -1. Import and inherit the new [`VRFV2WrapperConsumerBase.sol` contract](https://github.com/smartcontractkit/chainlink/blob/master/contracts/src/v0.8/vrf/VRFV2WrapperConsumerBase.sol) and remove the v1 `VRFConsumerBase.sol` import. This contract includes the `fulfillRandomWords` function. - -1. Add a `VRFV2WrapperConsumerBase` constructor as shown in the [Get a Random Number](/vrf/v2/direct-funding/examples/get-a-random-number) example and use the correct VRF v2 Direct funding configuration. - -1. You can still call the `requestRandomness` function. However, the v2 `requestRandomness` function requires several different parameters (`callbackGasLimit` , `requestConfirmations` , `numWords`). See the [Supported networks](/vrf/v2/direct-funding/supported-networks) page to adjust them for your own needs. - -1. Change `fulfillRandomness` function calls to `fulfillRandomWords`. Update the call to handle the returned `uint256[]` array instead of the single `uint256` variable. diff --git a/src/content/vrf/v2/direct-funding/supported-networks.mdx b/src/content/vrf/v2/direct-funding/supported-networks.mdx index 971ba2fb668..2fae107b96d 100644 --- a/src/content/vrf/v2/direct-funding/supported-networks.mdx +++ b/src/content/vrf/v2/direct-funding/supported-networks.mdx @@ -1,5 +1,5 @@ --- -section: vrf +section: legacy date: Last Modified title: "Supported Networks - Direct Funding Method" metadata: diff --git a/src/content/vrf/v2/estimating-costs.mdx b/src/content/vrf/v2/estimating-costs.mdx index 0cdd84a79ce..3ed37362d0a 100644 --- a/src/content/vrf/v2/estimating-costs.mdx +++ b/src/content/vrf/v2/estimating-costs.mdx @@ -1,5 +1,5 @@ --- -section: vrf +section: legacy date: Last Modified title: "VRF Billing" whatsnext: diff --git a/src/content/vrf/v2/getting-started.mdx b/src/content/vrf/v2/getting-started.mdx index 2a4ed87449a..65b8e06de21 100644 --- a/src/content/vrf/v2/getting-started.mdx +++ b/src/content/vrf/v2/getting-started.mdx @@ -1,5 +1,5 @@ --- -section: vrf +section: legacy date: Last Modified title: "Getting Started with Chainlink VRF" excerpt: "Using Chainlink VRF" diff --git a/src/content/vrf/v2/security.mdx b/src/content/vrf/v2/security.mdx index c3c4d0aa01b..61c071932b7 100644 --- a/src/content/vrf/v2/security.mdx +++ b/src/content/vrf/v2/security.mdx @@ -1,5 +1,5 @@ --- -section: vrf +section: legacy date: Last Modified title: "VRF Security Considerations" --- @@ -59,4 +59,4 @@ If you implement the [subscription method](/vrf/v2/subscription), use `VRFConsum ## Use `VRFv2WrapperConsumer.sol` in your contract, to interact with the VRF service -If you implement the [direct funding method](/vrf/v2/direct-funding), use `VRFv2WrapperConsumer`. It includes a check to ensure the randomness is fulfilled by the `VRFV2Wrapper`. For this reason, it is a best practice to inherit from `VRFv2WrapperConsumer`. Similarly, don't override `rawFulfillRandomWords`. \ No newline at end of file +If you implement the [direct funding method](/vrf/v2/direct-funding), use `VRFv2WrapperConsumer`. It includes a check to ensure the randomness is fulfilled by the `VRFV2Wrapper`. For this reason, it is a best practice to inherit from `VRFv2WrapperConsumer`. Similarly, don't override `rawFulfillRandomWords`. diff --git a/src/content/vrf/v2/subscription/examples/get-a-random-number.mdx b/src/content/vrf/v2/subscription/examples/get-a-random-number.mdx index 9f00b624e65..673e0f8a31f 100644 --- a/src/content/vrf/v2/subscription/examples/get-a-random-number.mdx +++ b/src/content/vrf/v2/subscription/examples/get-a-random-number.mdx @@ -1,5 +1,5 @@ --- -section: vrf +section: legacy date: Last Modified title: "Get a Random Number" whatsnext: @@ -8,7 +8,6 @@ whatsnext: "Subscription Manager UI": "/vrf/v2/subscription/ui", "Security Considerations": "/vrf/v2/security", "Best Practices": "/vrf/v2/best-practices", - "Migrating from VRF v1 to v2": "/vrf/v2/subscription/migration-from-v1", "Supported Networks": "/vrf/v2/subscription/supported-networks", } metadata: diff --git a/src/content/vrf/v2/subscription/examples/programmatic-subscription.mdx b/src/content/vrf/v2/subscription/examples/programmatic-subscription.mdx index 7d502e91727..7443643d68b 100644 --- a/src/content/vrf/v2/subscription/examples/programmatic-subscription.mdx +++ b/src/content/vrf/v2/subscription/examples/programmatic-subscription.mdx @@ -1,5 +1,5 @@ --- -section: vrf +section: legacy date: Last Modified title: "Programmatic Subscription" whatsnext: @@ -7,7 +7,6 @@ whatsnext: "Subscription Manager UI": "/vrf/v2/subscription/ui", "Security Considerations": "/vrf/v2/security", "Best Practices": "/vrf/v2/best-practices", - "Migrating from VRF v1 to v2": "/vrf/v2/subscription/migration-from-v1", "Supported Networks": "/vrf/v2/subscription/supported-networks", } metadata: diff --git a/src/content/vrf/v2/subscription/examples/test-locally.mdx b/src/content/vrf/v2/subscription/examples/test-locally.mdx index 3ba0b16d50c..53ac5b68daa 100644 --- a/src/content/vrf/v2/subscription/examples/test-locally.mdx +++ b/src/content/vrf/v2/subscription/examples/test-locally.mdx @@ -1,5 +1,5 @@ --- -section: vrf +section: legacy title: "Local testing using a Mock contract" metadata: description: "Example contract for generating random words using the VRF v2 subscription method on your local blockchain using a mock contract." diff --git a/src/content/vrf/v2/subscription/index.mdx b/src/content/vrf/v2/subscription/index.mdx index 6aa1358befb..eb3564f3c13 100644 --- a/src/content/vrf/v2/subscription/index.mdx +++ b/src/content/vrf/v2/subscription/index.mdx @@ -1,5 +1,5 @@ --- -section: vrf +section: legacy date: Last Modified title: "Subscription Method" isIndex: true diff --git a/src/content/vrf/v2/subscription/migration-from-v1.mdx b/src/content/vrf/v2/subscription/migration-from-v1.mdx deleted file mode 100644 index eadb1cbd8ec..00000000000 --- a/src/content/vrf/v2/subscription/migration-from-v1.mdx +++ /dev/null @@ -1,49 +0,0 @@ ---- -section: vrf -date: Last Modified -title: "Migrating from VRF v1" ---- - -import VrfCommon from "@features/vrf/v2/common/VrfCommon.astro" -import { CodeSample } from "@components" - - - -## Comparing VRF v1 to the VRF v2 subscription method - -Chainlink VRF v2 includes several improvements and changes to the way you fund and request randomness for your smart contracts. - -- **Subscription management:** Chainlink VRF v2 introduces a [Subscription Manager](/vrf/v2/subscription/ui) application that allows smart contract applications to pre-fund multiple requests for randomness using a single LINK token balance. This reduces the gas fees for VRF requests by eliminating the need to transfer LINK tokens for each individual request. You transfer LINK tokens to the subscription balance only when it requires additional funding. Read the [Subscription Manager](/vrf/v2/subscription/ui) page to learn more. - -- **Variable Callback Gas Limit:** Chainlink VRF v2 lets you adjust the callback gas limit when your smart contract application receives verifiable randomness. Consuming contracts can execute more complex logic in the callback request function that receives the random values. Tasks involving the delivered randomness are handled during the response process. The new gas limits are higher than the VRF V1 limit, and vary depending on the underlying blockchain you use. See the gas limits on the [VRF Supported Networks](/vrf/v2/subscription/supported-networks) page. - -- **More configuration capability:** You can define how many block confirmations must pass before verifiable randomness is generated and delivered onchain when your application makes a request transaction. The range is from 3 to 200 blocks. VRF V1 always waited 10 blocks on Ethereum before delivering onchain randomness. Select a value that protects your application from block re-organizations while still providing sufficiently low latency from request to response. See the [Security Considerations](/vrf/v2/security) page to learn more. - -- **Multiple Random Outputs in a Single Request:** The [VRF Coordinator contracts](/vrf/v2/subscription/supported-networks) in VRF v2 allow you to request multiple random numbers (multi-word) in a single onchain transaction, which reduces gas costs. The fulfillment is also a single transaction, which reduces the latency of responses. - -- **Unified Billing - Delegate Subscription Balance to Multiple Addresses:** Chainlink VRF v2 allows up to 100 smart contract addresses to fund their requests for verifiable randomness from a single LINK subscription balance, which is managed by the subscription owner. - -Read the [Chainlink VRF v2 blog post](https://blog.chain.link/vrf-v2-mainnet-launch/) for a detailed explanation about the benefits and use cases for VRF v2. - -## Updating your applications to use VRF v2 - - - -To modify your existing smart contract code to work with VRF v2, complete the following changes. See the [Get a Random Number](/vrf/v2/subscription/examples/get-a-random-number) guide for an example. - -1. Set up and fund a subscription in the Subscription Manager at [vrf.chain.link](https://vrf.chain.link). - {/* prettier-ignore */} - - - -1. Import the new [`VRFConsumerBaseV2.sol` contract](https://github.com/smartcontractkit/chainlink/blob/master/contracts/src/v0.8/vrf/VRFConsumerBaseV2.sol) and remove the v1 `VRFConsumerBase.sol` import. This contract includes the `fulfillRandomWords` function. - -1. Import the [`VRFCoordinatorV2Interface.sol` interface](https://github.com/smartcontractkit/chainlink/blob/master/contracts/src/v0.8/vrf/interfaces/VRFCoordinatorV2Interface.sol). This interface includes the new `requestRandomWords` function. - -1. Add a `VRFConsumerBaseV2` constructor as shown in the [Get a Random Number](/vrf/v2/subscription/examples/get-a-random-number) example. - -1. Change `requestRandomness` function calls to `requestRandomWords`. The `requestRandomWords` function requires several additional parameters. - -1. Change `fulfillRandomness` function calls to `fulfillRandomWords`. Update the call to handle the returned `uint256[]` array instead of the single `uint256` variable. diff --git a/src/content/vrf/v2/subscription/supported-networks.mdx b/src/content/vrf/v2/subscription/supported-networks.mdx index 56648544629..fe1a75d37bd 100644 --- a/src/content/vrf/v2/subscription/supported-networks.mdx +++ b/src/content/vrf/v2/subscription/supported-networks.mdx @@ -1,5 +1,5 @@ --- -section: vrf +section: legacy date: Last Modified title: "Supported Networks - Subscription Method" metadata: diff --git a/src/content/vrf/v2/subscription/ui.mdx b/src/content/vrf/v2/subscription/ui.mdx index a30072eb215..a8d319989b2 100644 --- a/src/content/vrf/v2/subscription/ui.mdx +++ b/src/content/vrf/v2/subscription/ui.mdx @@ -1,5 +1,5 @@ --- -section: vrf +section: legacy date: Last Modified title: "Subscription Manager User Interface" whatsnext: diff --git a/src/features/redirects/redirects.json b/src/features/redirects/redirects.json index 0b0585d5c9c..4fa039d82d1 100644 --- a/src/features/redirects/redirects.json +++ b/src/features/redirects/redirects.json @@ -347,34 +347,69 @@ }, { "source": "docs/vrf/v1/api-reference", - "destination": "vrf/v1/api-reference", + "destination": "vrf", "statusCode": 301 }, { "source": "docs/vrf/v1/best-practices", - "destination": "vrf/v1/best-practices", + "destination": "vrf/v2-5/best-practices", "statusCode": 301 }, { "source": "docs/vrf/v1/examples/get-a-random-number", - "destination": "vrf/v1/examples/get-a-random-number", + "destination": "vrf/v2-5/migration-from-v1", "statusCode": 301 }, { "source": "docs/vrf/v1/introduction", - "destination": "vrf/v1/introduction", + "destination": "vrf/v2-5/introduction", "statusCode": 301 }, { "source": "docs/vrf/v1/security", - "destination": "vrf/v1/security", + "destination": "vrf/v2-5/security", "statusCode": 301 }, { "source": "docs/vrf/v1/supported-networks", - "destination": "vrf/v1/supported-networks", + "destination": "vrf/v2-5/supported-networks", "statusCode": 301 }, + { + "source": "vrf/v1/introduction", + "destination": "vrf", + "statuscode": 301 + }, + { + "source": "vrf/v1/examples/get-a-random-number", + "destination": "vrf/v2-5/migration-from-v1", + "statuscode": 301 + }, + { + "source": "vrf/v1/security", + "destination": "vrf/v2-5/security", + "statuscode": 301 + }, + { + "source": "vrf/v1/best-practices", + "destination": "vrf/v2-5/best-practices", + "statuscode": 301 + }, + { + "source": "/vrf/v2/direct-funding/migration-from-v1", + "destination": "vrf/v2-5/migration-from-v1", + "statuscode": 301 + }, + { + "source": "/vrf/v2/subscription/migration-from-v1", + "destination": "vrf/v2-5/migration-from-v1", + "statuscode": 301 + }, + { + "source": "vrf/v1/supported-networks", + "destination": "vrf/v2-5/migration-from-v1", + "statuscode": 301 + }, { "source": "docs/vrf/v2/best-practices", "destination": "vrf/v2/best-practices", @@ -392,7 +427,7 @@ }, { "source": "docs/vrf/v2/direct-funding/migration-from-v1", - "destination": "vrf/v2/direct-funding/migration-from-v1", + "destination": "vrf/v2-5/migration-from-v1", "statusCode": 301 }, { @@ -432,7 +467,7 @@ }, { "source": "docs/vrf/v2/subscription/migration-from-v1", - "destination": "vrf/v2/subscription/migration-from-v1", + "destination": "vrf/v2-5/migration-from-v1", "statusCode": 301 }, { @@ -1127,22 +1162,22 @@ }, { "source": "docs/chainlink-vrf-best-practices", - "destination": "vrf/v2/best-practices", + "destination": "vrf/v2-5/best-practices", "statuscode": 301 }, { "source": "docs/vrf-security-considerations", - "destination": "vrf/v2/security", + "destination": "vrf/v2-5/security", "statuscode": 301 }, { "source": "docs/vrf-contracts", - "destination": "vrf/v2/subscription/supported-networks", + "destination": "vrf/v2-5/supported-networks", "statuscode": 301 }, { "source": "docs/chainlink-vrf/migration-vrf-v1-v2", - "destination": "vrf/v2/subscription/migration-from-v1", + "destination": "vrf/v2-5/migration-from-v1", "statuscode": 301 }, {