chainlink-vrf-skill

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Chainlink 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

渐进式披露

  1. Keep this file as the default guide.
  2. Read references/subscription.md only when the user wants to build a subscription-based consumer, manage a subscription, use
    VRFConsumerBaseV2Plus
    , call
    requestRandomWords
    , or handle the
    fulfillRandomWords
    callback.
  3. Read references/direct-funding.md only when the user wants direct funding (no subscription), uses
    VRFV2PlusWrapperConsumerBase
    , or asks about a one-off randomness request.
  4. Read references/migration-from-v2.md when you detect V1 or V2 patterns in user-supplied code (
    VRFConsumerBaseV2
    ,
    VRFConsumerBase
    , positional
    requestRandomWords
    ,
    uint64
    subscription IDs,
    VRFV2WrapperConsumerBase
    , or
    memory
    randomWords in a subscription consumer) or when the user asks how to migrate.
  5. Read references/billing.md only when the user asks about costs, LINK vs native payment, subscription funding, or premium percentages.
  6. Read references/supported-networks.md only when the user needs coordinator addresses, wrapper addresses, LINK token addresses, or key hashes for a specific network.
  7. 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.
  8. Read references/official-sources.md only when the answer depends on live data the reference files do not contain.
  9. Do not load reference files speculatively.
  1. 将本文件作为默认指南。
  2. 仅当用户希望构建基于订阅的消费者合约、管理订阅、使用
    VRFConsumerBaseV2Plus
    、调用
    requestRandomWords
    或处理
    fulfillRandomWords
    回调时,才阅读references/subscription.md
  3. 仅当用户希望使用直接充值(无需订阅)、使用
    VRFV2PlusWrapperConsumerBase
    或询问一次性随机数请求相关问题时,才阅读references/direct-funding.md
  4. 当在用户提供的代码中检测到V1或V2模式(
    VRFConsumerBaseV2
    VRFConsumerBase
    、位置参数式
    requestRandomWords
    uint64
    类型订阅ID、
    VRFV2WrapperConsumerBase
    或订阅消费者中使用
    memory
    类型的randomWords),或用户询问迁移方法时,阅读references/migration-from-v2.md
  5. 仅当用户询问成本、LINK与原生代币支付对比、订阅充值或溢价比例相关问题时,才阅读references/billing.md
  6. 仅当用户需要特定网络的协调器地址、包装器地址、LINK代币地址或keyHash时,才阅读references/supported-networks.md
  7. 仅当开发者使用本技能开发消费者合约,且用户询问安全性、抗偏性、gas限制设置、请求取消或生产就绪性相关问题时,才阅读references/security-and-best-practices.md
  8. 仅当答案依赖于参考文件未包含的实时数据时,才阅读references/official-sources.md
  9. 请勿推测性加载参考文件。

Routing

路由规则

  1. Subscription (default): Use for recurring randomness, games, lotteries, any contract that requests randomness more than once. Route to
    subscription.md
    .
  2. Direct funding: Use for one-off requests or when the user explicitly does not want a subscription. Route to
    direct-funding.md
    .
  3. Migration: Detect legacy patterns (see Progressive Disclosure rule 4). Refuse to generate V2 code; load
    migration-from-v2.md
    and offer a v2.5 upgrade.
  4. Network lookup: When an address or key hash is needed, load
    supported-networks.md
    . Never invent coordinator or wrapper addresses.
  5. Ask one focused question if the method (subscription vs direct) or target network is unclear and the answer would materially change the code.
  6. Proceed without asking for read-only work: explanations, code generation, debugging.
  1. 订阅模式(默认):用于周期性随机数需求、游戏、彩票等需要多次请求随机数的合约。引导至
    subscription.md
  2. 直接充值模式:用于一次性请求或用户明确表示不使用订阅的场景。引导至
    direct-funding.md
  3. 迁移场景:检测到旧版模式(见渐进式披露规则4)。拒绝生成V2代码;加载
    migration-from-v2.md
    并提供v2.5升级方案。
  4. 网络信息查询:当需要地址或keyHash时,加载
    supported-networks.md
    。切勿自行编造协调器或包装器地址。
  5. 如果使用方式(订阅vs直接充值)或目标网络不明确,且该信息会对生成的代码产生实质性影响,请提出一个明确的问题确认。
  6. 对于只读工作(如解释、代码生成、调试),无需询问即可直接进行。

Legacy Pattern Guard

旧版模式防护

VRF V1 and V2 code will not compile against current v2.5 coordinators. Detect and refuse these patterns:
V2 PatternWhy it breaks in v2.5
VRFConsumerBaseV2
base
Replaced by
VRFConsumerBaseV2Plus
VRFConsumerBase
base
V1 — entirely incompatible
Positional
requestRandomWords(keyHash, subId, ...)
Must use
VRFV2PlusClient.RandomWordsRequest
struct
uint64 s_subscriptionId
Sub IDs are now
uint256
VRFV2WrapperConsumerBase(linkAddress, wrapperAddress)
No LINK address in v2.5 wrapper constructor
uint256[] memory randomWords
in subscription fulfill
VRFConsumerBaseV2Plus
uses
calldata
; direct-funding wrapper consumers still use
memory
COORDINATOR
as a typed state variable
Use
s_vrfCoordinator
from the base class
When any of these are detected in user code: (1) name the incompatibility explicitly, (2) load
migration-from-v2.md
, (3) produce v2.5 code only.
VRF V1和V2代码无法在当前v2.5协调器环境下编译。检测到以下模式时需拒绝生成:
V2模式在v2.5中失效的原因
VRFConsumerBaseV2
基类
已被
VRFConsumerBaseV2Plus
取代
VRFConsumerBase
基类
V1版本——完全不兼容
位置参数式
requestRandomWords(keyHash, subId, ...)
必须使用
VRFV2PlusClient.RandomWordsRequest
结构体
uint64 s_subscriptionId
订阅ID现在为
uint256
类型
VRFV2WrapperConsumerBase(linkAddress, wrapperAddress)
v2.5包装器构造函数中不再需要LINK地址
订阅场景的fulfill方法中使用
uint256[] memory randomWords
VRFConsumerBaseV2Plus
使用
calldata
;直接充值模式的包装器消费者仍使用
memory
COORDINATOR
作为类型化状态变量
使用基类中的
s_vrfCoordinator
当在用户代码中检测到上述任意模式时:(1)明确指出不兼容点;(2)加载
migration-from-v2.md
;(3)仅生成v2.5版本代码。

Safety Defaults

安全默认规则

These are non-negotiable in generated code.
  1. Never invent coordinator, wrapper, or LINK token addresses. Always load
    supported-networks.md
    or direct the user to the official addresses page.
  2. Use
    VRFConsumerBaseV2Plus
    for subscription consumers and
    VRFV2PlusWrapperConsumerBase
    for direct-funding consumers (never V1/V2 base contracts).
  3. For subscription consumers, always use
    VRFV2PlusClient.RandomWordsRequest
    struct with
    extraArgs
    (never positional args).
  4. Always use
    uint256
    for subscription IDs (never
    uint64
    ).
  5. Use the callback data location required by the base contract:
    calldata
    for
    VRFConsumerBaseV2Plus
    ,
    memory
    for
    VRFV2PlusWrapperConsumerBase
    .
  6. Remind users that example code is unaudited and not for production use without a security review.
  7. Do not use
    block.prevrandao
    ,
    block.difficulty
    , or
    blockhash
    as a randomness fallback.
生成代码时必须遵守以下不可协商的规则。
  1. 切勿自行编造协调器、包装器或LINK代币地址。始终加载
    supported-networks.md
    或引导用户查看官方地址页面。
  2. 订阅消费者使用
    VRFConsumerBaseV2Plus
    ,直接充值消费者使用
    VRFV2PlusWrapperConsumerBase
    (绝不使用V1/V2基类合约)。
  3. 对于订阅消费者,始终使用带
    extraArgs
    VRFV2PlusClient.RandomWordsRequest
    结构体(绝不使用位置参数)。
  4. 订阅ID始终使用
    uint256
    类型(绝不使用
    uint64
    )。
  5. 使用基类要求的回调数据位置:
    VRFConsumerBaseV2Plus
    使用
    calldata
    VRFV2PlusWrapperConsumerBase
    使用
    memory
  6. 提醒用户示例代码未经过审计,未经安全审查不得用于生产环境。
  7. 不得使用
    block.prevrandao
    block.difficulty
    blockhash
    作为随机数备选方案。

Documentation Access

文档访问规则

This skill references official VRF documentation URLs throughout its reference files.
  1. If WebFetch, a browser tool, or an MCP server that can retrieve documentation is available, use it to fetch the referenced URL before answering.
  2. 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.
  3. 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。
  1. 如果有WebFetch、浏览器工具或可检索文档的MCP服务器可用,在回答前先获取引用的URL内容。
  2. 如果没有文档获取工具,切勿仅凭训练数据随意编造VRF模式。应:
    • 将本技能参考文件中的嵌入式内容作为指导基础。
    • 告知用户无法验证实时文档。
    • 提供具体URL供用户自行查看。
  3. 对于正确性优先的合约优先工作流,优先使用references/subscription.mdreferences/direct-funding.md中的具体示例,而非凭记忆生成模式。

Working Rules

工作规则

  1. Generate working code from knowledge and reference files first. Fetch only when a specific detail is missing.
  2. Treat 0-1 fetches as normal, 2-3 as the ceiling. Most questions need no fetches because the reference files contain the implementation guidance.
  3. When a fetch is needed, apply the cascade: WebFetch first; if it returns <1000 chars of useful content, fall back to
    curl -s -L -A "Mozilla/5.0 ..." "<url>"
    ; if both fail, the Context7 MCP server (
    @upstash/context7-mcp
    ) 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.
  4. Keep answers proportional — a simple "request a random number" question gets a code block and brief explanation, not a full tutorial.
  5. Generate code only when code is actually needed.
  6. 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.
  7. Keep unsupported or out-of-scope features (off-chain VRF, non-EVM VRF) out of the answer rather than speculating.
  1. 优先根据已有知识和参考文件生成可运行代码。仅当缺少特定细节时才进行获取操作。
  2. 0-1次获取操作属于正常范围,最多不超过2-3次。大多数问题无需获取,因为参考文件已包含实现指导。
  3. 当需要获取时,按以下顺序尝试:首先使用WebFetch;如果返回的有用内容不足1000字符,则回退到
    curl -s -L -A "Mozilla/5.0 ..." "<url>"
    ;如果两者都失败,Context7 MCP服务器(
    @upstash/context7-mcp
    )是获取最新Chainlink文档的有效备选方案。如果没有文档获取工具,切勿随意编造,应告知用户无法验证实时文档并提供具体URL供用户自行查看。
  4. 回答应与问题匹配——对于简单的“请求随机数”问题,只需提供代码块和简要说明,无需完整教程。
  5. 仅在确实需要时才生成代码。
  6. 如果用户要求编写、构建、创建或展示VRF合约或代码片段,但未指定仓库路径或要编辑的文件,则直接在回答中提供代码。除非用户明确要求修改文件,否则无需请求文件系统写入权限。
  7. 对于不支持或超出范围的功能(链下VRF、非EVM VRF),应在回答中忽略,而非进行推测。