跳到正文
Skillpedia
API 与服务器(后端)7.0k · #13630

write-contract

它能做什么

本指南展示如何编写可用于真实网络的 GenLayer 智能合约。它说明必须固定运行器版本的要求、何时适合使用 GenLayer,以及存储、错误处理和跨合约调用的规则。

适用场景

  • ✓当你希望智能体编写一个新的 GenLayer 智能合约的时候。
  • ✓当你想判断某项功能是否真的需要 GenLayer 共识的时候。
  • ✓当你要为生产环境更新现有合约时。

技能链接

https://github.com/internet-court/internet-court-skill/blob/main/vendored/genlayer/write-contract/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/internet-court/internet-court-skill/blob/main/vendored/genlayer/write-contract/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“我想要一个能存储用户评价、并用 AI 模型进行检查的 GenLayer 合约。”

每周 5 个新技能,1 分钟读完。

工作原理

智能体会编写合约,并在顶部固定运行器版本,遵循存储和共识规则,然后对结果运行代码检查。在给你代码之前,它会检查文件头和该技能列出的规则。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Write Intelligent Contract

Guidance for writing GenLayer intelligent contracts that pass consensus, handle errors correctly, and survive production.

Critical: Pin the Runner Version

All GenLayer networks reject py-genlayer:test, py-genlayer:latest, and unversioned runner aliases. Every generated contract MUST start with a pinned runner dependency header.

# { "Depends": "py-genlayer:1jb45aa8ynh2a9c9xn3b7qqh8sm5q93hwfp7jqmwsfhh8jpz09h6" }

test and latest are local-development aliases for GenLayer runtime developers. They may work only in a specially configured local Studio environment with a GenLayer developer environment variable, but they do not work on GenLayer networks and must not appear in generated user contracts.

Before returning any contract code, verify:

  • The first line is a pinned Depends runner version hash.
  • There is no py-genlayer:test.
  • There is no py-genlayer:latest.
  • There is no unversioned py-genlayer.

Always lint with genvm-lint check after writing or modifying a contract.

When to Use GenLayer

Before writing code, decide whether the feature actually needs GenLayer consensus. Recent builder feedback shows many projects start by treating GenLayer as a generic AI backend; push them toward a clear on-chain consensus role.

Use GenLayer when the contract must coordinate or settle around a subjective, external, or AI-mediated judgment that multiple validators should verify independently:

  • Dispute resolution where evidence must be evaluated and the result affects escrow, payouts, reputation, or access.
  • Prediction/oracle-style markets where the contract needs an independently validated outcome from external evidence.
  • Compliance, moderation, or scoring workflows where the final decision must be reproducible enough for validator agreement but cannot be reduced to a simple deterministic API call.
  • Autonomous agents that need transparent settlement, appeals, and auditable state transitions rather than a private off-chain decision.

Prefer a normal backend, frontend, or off-chain LLM workflow when:

  • The frontend already computes the final answer and GenLayer would only rubber-stamp it.
  • The contract only stores user-provided data with no validator-verifiable judgment.
  • A deterministic smart contract, REST API, or database job can perform the work without AI consensus.
  • The data-fetching/prompting step is not tied to an on-chain state transition, escrow, payout, or appealable decision.

For every contract, write down the boundary before implementation:

  • Frontend/backend owns: UI, user auth, indexing, non-authoritative previews, cached market data, and convenience analytics.
  • GenLayer contract owns: the minimum state transition that needs consensus, the evidence inputs, the validator comparison rule, the final settlement effect, and any appeal/rotation path.
  • External sources own: raw facts or documents; do not treat them as trusted unless validators can re-fetch, normalize, and compare them.

If the boundary is unclear, create a one-page architecture note before coding: user action -> evidence source -> nondeterministic call -> equivalence principle -> state update -> user-visible settlement.

Contract Skeleton

# { "Depends": "py-genlayer:1jb45aa8ynh2a9c9xn3b7qqh8sm5q93hwfp7jqmwsfhh8jpz09h6" }

from genlayer import *

class MyContract(gl.Contract):
    # Storage fields — typed, persisted on-chain
    owner: Address
    items: TreeMap[str, Item]
    item_order: DynArray[str]

    def __init__(self, param: str):
        self.owner = gl.message.sender_account

    @gl.public.view
    def get_item(self, item_id: str) -> dict:
        return {"id": item_id, "value": self.items[item_id].value}

    @gl.public.write
    def set_item(self, item_id: str, value: str) -> None:
        if gl.message.sender_account != self.owner:
            raise gl.UserError("Only owner")
        self.items[item_id] = Item(value=value)
        self.item_order.append(item_id)

Runner Dependencies

The first line of a contract declares the GenVM Python runner. Always pin a specific runner version hash. All GenLayer networks reject test, latest, and unversioned runner aliases in generated contracts.

Single-file Python contracts

# { "Depends": "py-genlayer:1jb45aa8ynh2a9c9xn3b7qqh8sm5q93hwfp7jqmwsfhh8jpz09h6" }

Multi-file Python contract packages

Use py-genlayer-multi when the contract is packaged across multiple

常见问题

为什么合约必须固定运行器版本?

GenLayer 网络会拒绝 test、latest 以及未带版本的运行器别名,因此必须固定版本。

什么时候不应该使用 GenLayer?

该技能说明,当某项功能不需要对主观或外部问题达成共识时,应跳过它。

智能体会自动检查代码吗?

该技能要求智能体在编写或修改每个合约后,都用 genvm-lint 进行检查。

详情

作者的原始描述

Write production-quality GenLayer intelligent contracts. Always pins concrete GenVM runner version hashes and never uses local-only test/latest runner aliases. Covers equivalence principles, storage rules, LLM resilience, and cross-contract interaction.

repo: internet-court/internet-court-skill

热度

GitHub 星标
7.0k
排名
#13630
许可证
—
更新时间
2026/10/26

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能