Skip to content

Chainlink VRF V2 升级至 VRF V2.5 #816

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

eddiehsu66
Copy link
Contributor

@eddiehsu66 eddiehsu66 commented Oct 17, 2024

What type of PR is this (这是什么类型的PR)

  • Typo(勘误)
  • BUG(程序错误)
  • Improvement(提升)
  • Feature(新特性)

Which issue(s) this PR fixes(Optional) (这个PR 修复了什么问题 (可选择))

What this PR does / why we need it (这个PR 做了什么/ 我们为什么需要这个PR)

当前Chainlink官网不支持VRF V2,获取的subId从uint64变为了uint256,需要进行迁移

@XdpCs
Copy link
Collaborator

XdpCs commented Nov 2, 2024

@eddiehsu66 pr需要引用解决的相关问题 我已经帮你引用上了 下次希望能够引用一下解决的问题 你的代码这几天 我会去本地测试的 谢谢你的贡献

@XdpCs
Copy link
Collaborator

XdpCs commented Nov 4, 2024

#607 是需要支持预言机本地化 如果可以的话 能否在这个pr中支持

@eddiehsu66
Copy link
Contributor Author

okok,我重新看一下文档整理一下

#607 是需要支持预言机本地化 如果可以的话 能否在这个pr中支持

@XdpCs
Copy link
Collaborator

XdpCs commented Nov 7, 2024

okok,我重新看一下文档整理一下

#607 是需要支持预言机本地化 如果可以的话 能否在这个pr中支持

好 辛苦大佬

@eddiehsu66
Copy link
Contributor Author

#607 是需要支持预言机本地化 如果可以的话 能否在这个pr中支持

OKOK,已支持预言机本地化测试,已提交

@XdpCs
Copy link
Collaborator

XdpCs commented Nov 10, 2024

#607 是需要支持预言机本地化 如果可以的话 能否在这个pr中支持

OKOK,已支持预言机本地化测试,已提交

辛苦辛苦 争取下周 review完

@XdpCs XdpCs requested a review from Copilot July 6, 2025 14:11
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR upgrades the Chainlink VRF V2 integration to VRF V2.5, updating consumer contracts, type definitions, imports, and documentation accordingly.

  • Swapped out VRFConsumerBaseV2 for VRFConsumerBaseV2Plus and updated all import paths and constructor calls.
  • Changed subId from uint64 to uint256 and updated coordinator addresses and key hashes.
  • Refactored requestRandomWords calls to use VRFV2PlusClient.RandomWordsRequest with ExtraArgsV1, added a mock contract for local testing, and expanded the README with remix setup instructions.

Reviewed Changes

Copilot reviewed 4 out of 10 changed files in this pull request and generated 3 comments.

File Description
39_Random/readme.md Updated docs for VRF V2.5 usage, added local test guide, corrected addresses and sample calls
39_Random/VRFCoordinatorV2_5Mock.sol Introduced mock import for VRFCoordinatorV2_5Mock to enable local testing in remix
39_Random/RandomNumberConsumer.sol Migrated consumer contract to use VRFConsumerBaseV2Plus, updated types, imports, and request API
39_Random/Random.sol Migrated NFT contract to use VRFConsumerBaseV2Plus, updated types, imports, and request API
Comments suppressed due to low confidence (2)

39_Random/RandomNumberConsumer.sol:63

  • [nitpick] The parameter s_randomWords uses the s_ prefix (typically for storage); consider renaming to randomWords or similar for clarity and consistency with _requestId.
    function fulfillRandomWords(uint256 _requestId, uint256[] calldata s_randomWords) internal override {

39_Random/Random.sol:110

  • [nitpick] Similarly here, s_randomWords could be renamed to avoid the storage-prefix convention and match the _requestId style.
    function fulfillRandomWords(uint256 _requestId, uint256[] calldata s_randomWords) internal override{

@@ -353,6 +362,78 @@ contract Random is ERC721, VRFConsumerBaseV2{
当合约不使用后可以在`Chainlink VRF`上取消订阅,取出剩余的`LINK`代币
![取消订阅](./img/39-10.png)

## `remix`本地测试网验证

ChainLink也提供了在remix本地进行测试的方案。
Copy link
Preview

Copilot AI Jul 6, 2025

Choose a reason for hiding this comment

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

[nitpick] Consistently capitalize 'Chainlink' instead of 'ChainLink' to match product branding.

Suggested change
ChainLink也提供了在remix本地进行测试的方案
Chainlink也提供了在remix本地进行测试的方案

Copilot uses AI. Check for mistakes.


### 5. 发起随机数请求

点击左侧`mintRandomVRF`,发起随机数请求,可以通过查询`requesetid`来查看发起的请求ID。
Copy link
Preview

Copilot AI Jul 6, 2025

Choose a reason for hiding this comment

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

Typo in 'requesetid'—it should be 'requestId' to match the code examples.

Suggested change
点击左侧`mintRandomVRF`,发起随机数请求,可以通过查询`requesetid`来查看发起的请求ID。
点击左侧`mintRandomVRF`,发起随机数请求,可以通过查询`requestId`来查看发起的请求ID。

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(39. 链上随机数) 适配于Chainlink VRF v2.5的Random.sol
2 participants