chainlink-vrf-skill
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseChainlink VRF Skill
Chainlink VRF技能
Overview
概述
Route VRF requests to the simplest valid path. Generate working VRF v2.5 code on first attempt when possible. Detect legacy V1/V2 patterns and refuse to emit them — offer migration guidance instead.
将VRF请求引导至最简单的有效路径。尽可能在首次尝试时生成可运行的VRF v2.5代码。检测旧版V1/V2模式并拒绝生成相关代码,转而提供迁移指导。
Progressive Disclosure
渐进式披露
- Keep this file as the default guide.
- Read references/subscription.md only when the user wants to build a subscription-based consumer, manage a subscription, use , call
VRFConsumerBaseV2Plus, or handle therequestRandomWordscallback.fulfillRandomWords - Read references/direct-funding.md only when the user wants direct funding (no subscription), uses , or asks about a one-off randomness request.
VRFV2PlusWrapperConsumerBase - Read references/migration-from-v2.md when you detect V1 or V2 patterns in user-supplied code (,
VRFConsumerBaseV2, positionalVRFConsumerBase,requestRandomWordssubscription IDs,uint64, orVRFV2WrapperConsumerBaserandomWords in a subscription consumer) or when the user asks how to migrate.memory - Read references/billing.md only when the user asks about costs, LINK vs native payment, subscription funding, or premium percentages.
- Read references/supported-networks.md only when the user needs coordinator addresses, wrapper addresses, LINK token addresses, or key hashes for a specific network.
- Read references/security-and-best-practices.md only when the agent is developing consumer contracts with this skill and when the user asks about security, bias resistance, gas limit sizing, request cancellation, or production readiness.
- Read references/official-sources.md only when the answer depends on live data the reference files do not contain.
- Do not load reference files speculatively.
- 将本文件作为默认指南。
- 仅当用户希望构建基于订阅的消费者合约、管理订阅、使用、调用
VRFConsumerBaseV2Plus或处理requestRandomWords回调时,才阅读references/subscription.md。fulfillRandomWords - 仅当用户希望使用直接充值(无需订阅)、使用或询问一次性随机数请求相关问题时,才阅读references/direct-funding.md。
VRFV2PlusWrapperConsumerBase - 当在用户提供的代码中检测到V1或V2模式(、
VRFConsumerBaseV2、位置参数式VRFConsumerBase、requestRandomWords类型订阅ID、uint64或订阅消费者中使用VRFV2WrapperConsumerBase类型的randomWords),或用户询问迁移方法时,阅读references/migration-from-v2.md。memory - 仅当用户询问成本、LINK与原生代币支付对比、订阅充值或溢价比例相关问题时,才阅读references/billing.md。
- 仅当用户需要特定网络的协调器地址、包装器地址、LINK代币地址或keyHash时,才阅读references/supported-networks.md。
- 仅当开发者使用本技能开发消费者合约,且用户询问安全性、抗偏性、gas限制设置、请求取消或生产就绪性相关问题时,才阅读references/security-and-best-practices.md。
- 仅当答案依赖于参考文件未包含的实时数据时,才阅读references/official-sources.md。
- 请勿推测性加载参考文件。
Routing
路由规则
- Subscription (default): Use for recurring randomness, games, lotteries, any contract that requests randomness more than once. Route to .
subscription.md - Direct funding: Use for one-off requests or when the user explicitly does not want a subscription. Route to .
direct-funding.md - Migration: Detect legacy patterns (see Progressive Disclosure rule 4). Refuse to generate V2 code; load and offer a v2.5 upgrade.
migration-from-v2.md - Network lookup: When an address or key hash is needed, load . Never invent coordinator or wrapper addresses.
supported-networks.md - Ask one focused question if the method (subscription vs direct) or target network is unclear and the answer would materially change the code.
- Proceed without asking for read-only work: explanations, code generation, debugging.
- 订阅模式(默认):用于周期性随机数需求、游戏、彩票等需要多次请求随机数的合约。引导至。
subscription.md - 直接充值模式:用于一次性请求或用户明确表示不使用订阅的场景。引导至。
direct-funding.md - 迁移场景:检测到旧版模式(见渐进式披露规则4)。拒绝生成V2代码;加载并提供v2.5升级方案。
migration-from-v2.md - 网络信息查询:当需要地址或keyHash时,加载。切勿自行编造协调器或包装器地址。
supported-networks.md - 如果使用方式(订阅vs直接充值)或目标网络不明确,且该信息会对生成的代码产生实质性影响,请提出一个明确的问题确认。
- 对于只读工作(如解释、代码生成、调试),无需询问即可直接进行。
Legacy Pattern Guard
旧版模式防护
VRF V1 and V2 code will not compile against current v2.5 coordinators. Detect and refuse these patterns:
| V2 Pattern | Why it breaks in v2.5 |
|---|---|
| Replaced by |
| V1 — entirely incompatible |
Positional | Must use |
| Sub IDs are now |
| No LINK address in v2.5 wrapper constructor |
| |
| Use |
When any of these are detected in user code: (1) name the incompatibility explicitly, (2) load , (3) produce v2.5 code only.
migration-from-v2.mdVRF V1和V2代码无法在当前v2.5协调器环境下编译。检测到以下模式时需拒绝生成:
| V2模式 | 在v2.5中失效的原因 |
|---|---|
| 已被 |
| V1版本——完全不兼容 |
位置参数式 | 必须使用 |
| 订阅ID现在为 |
| v2.5包装器构造函数中不再需要LINK地址 |
订阅场景的fulfill方法中使用 | |
| 使用基类中的 |
当在用户代码中检测到上述任意模式时:(1)明确指出不兼容点;(2)加载;(3)仅生成v2.5版本代码。
migration-from-v2.mdSafety Defaults
安全默认规则
These are non-negotiable in generated code.
- Never invent coordinator, wrapper, or LINK token addresses. Always load or direct the user to the official addresses page.
supported-networks.md - Use for subscription consumers and
VRFConsumerBaseV2Plusfor direct-funding consumers (never V1/V2 base contracts).VRFV2PlusWrapperConsumerBase - For subscription consumers, always use struct with
VRFV2PlusClient.RandomWordsRequest(never positional args).extraArgs - Always use for subscription IDs (never
uint256).uint64 - Use the callback data location required by the base contract: for
calldata,VRFConsumerBaseV2Plusformemory.VRFV2PlusWrapperConsumerBase - Remind users that example code is unaudited and not for production use without a security review.
- Do not use ,
block.prevrandao, orblock.difficultyas a randomness fallback.blockhash
生成代码时必须遵守以下不可协商的规则。
- 切勿自行编造协调器、包装器或LINK代币地址。始终加载或引导用户查看官方地址页面。
supported-networks.md - 订阅消费者使用,直接充值消费者使用
VRFConsumerBaseV2Plus(绝不使用V1/V2基类合约)。VRFV2PlusWrapperConsumerBase - 对于订阅消费者,始终使用带的
extraArgs结构体(绝不使用位置参数)。VRFV2PlusClient.RandomWordsRequest - 订阅ID始终使用类型(绝不使用
uint256)。uint64 - 使用基类要求的回调数据位置:使用
VRFConsumerBaseV2Plus,calldata使用VRFV2PlusWrapperConsumerBase。memory - 提醒用户示例代码未经过审计,未经安全审查不得用于生产环境。
- 不得使用、
block.prevrandao或block.difficulty作为随机数备选方案。blockhash
Documentation Access
文档访问规则
This skill references official VRF documentation URLs throughout its reference files.
- If WebFetch, a browser tool, or an MCP server that can retrieve documentation is available, use it to fetch the referenced URL before answering.
- If no documentation-fetching tool is available, do not silently improvise VRF patterns from training data alone. Instead:
- Use the embedded reference content in this skill's reference files as the floor for guidance.
- Tell the user that live documentation could not be verified.
- Provide the specific URL so the user can check it directly.
- For contract-first workflows where correctness matters most, prefer the concrete examples in references/subscription.md or references/direct-funding.md over generating patterns from memory.
本技能在其参考文件中引用了官方VRF文档URL。
- 如果有WebFetch、浏览器工具或可检索文档的MCP服务器可用,在回答前先获取引用的URL内容。
- 如果没有文档获取工具,切勿仅凭训练数据随意编造VRF模式。应:
- 将本技能参考文件中的嵌入式内容作为指导基础。
- 告知用户无法验证实时文档。
- 提供具体URL供用户自行查看。
- 对于正确性优先的合约优先工作流,优先使用references/subscription.md或references/direct-funding.md中的具体示例,而非凭记忆生成模式。
Working Rules
工作规则
- Generate working code from knowledge and reference files first. Fetch only when a specific detail is missing.
- Treat 0-1 fetches as normal, 2-3 as the ceiling. Most questions need no fetches because the reference files contain the implementation guidance.
- When a fetch is needed, apply the cascade: WebFetch first; if it returns <1000 chars of useful content, fall back to ; if both fail, the Context7 MCP server (
curl -s -L -A "Mozilla/5.0 ..." "<url>") is a useful fallback for fetching current Chainlink documentation. If no documentation-fetching tool is available, do not silently improvise, instead tell the user that live documentation could not be verified and provide the specific URL so the user can check it directly.@upstash/context7-mcp - Keep answers proportional — a simple "request a random number" question gets a code block and brief explanation, not a full tutorial.
- Generate code only when code is actually needed.
- If the user asks to write, build, create, or show a VRF contract or snippet without naming a repository path or file to edit, answer inline with code. Do not ask for filesystem write approval unless the user explicitly asks you to modify files.
- Keep unsupported or out-of-scope features (off-chain VRF, non-EVM VRF) out of the answer rather than speculating.
- 优先根据已有知识和参考文件生成可运行代码。仅当缺少特定细节时才进行获取操作。
- 0-1次获取操作属于正常范围,最多不超过2-3次。大多数问题无需获取,因为参考文件已包含实现指导。
- 当需要获取时,按以下顺序尝试:首先使用WebFetch;如果返回的有用内容不足1000字符,则回退到;如果两者都失败,Context7 MCP服务器(
curl -s -L -A "Mozilla/5.0 ..." "<url>")是获取最新Chainlink文档的有效备选方案。如果没有文档获取工具,切勿随意编造,应告知用户无法验证实时文档并提供具体URL供用户自行查看。@upstash/context7-mcp - 回答应与问题匹配——对于简单的“请求随机数”问题,只需提供代码块和简要说明,无需完整教程。
- 仅在确实需要时才生成代码。
- 如果用户要求编写、构建、创建或展示VRF合约或代码片段,但未指定仓库路径或要编辑的文件,则直接在回答中提供代码。除非用户明确要求修改文件,否则无需请求文件系统写入权限。
- 对于不支持或超出范围的功能(链下VRF、非EVM VRF),应在回答中忽略,而非进行推测。