write-contract
Skill này làm gì
Hướng dẫn này chỉ cách viết contract thông minh GenLayer sẵn sàng cho mạng thật. Nó giải thích yêu cầu ghim phiên bản runner, khi nào GenLayer là công cụ phù hợp, và các quy tắc về lưu trữ, xử lý lỗi và gọi giữa các contract.
Khi nào nên dùng
- ✓Khi bạn muốn agent viết một contract thông minh GenLayer mới.
- ✓Khi bạn muốn kiểm tra xem một tính năng có thật sự cần đồng thuận GenLayer không.
- ✓Khi bạn đang cập nhật một contract có sẵn để dùng trong môi trường production.
Liên kết skill
https://github.com/internet-court/internet-court-skill/blob/main/vendored/genlayer/write-contract/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Tôi muốn một contract GenLayer lưu đánh giá của người dùng và kiểm tra nó bằng một mô hình AI.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent viết contract với một phiên bản runner được ghim ở đầu, tuân theo các quy tắc lưu trữ và đồng thuận, rồi chạy linter trên kết quả. Trước khi đưa mã cho bạn, nó kiểm tra phần header và các quy tắc trong skill.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
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
Dependsrunner 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
Câu hỏi thường gặp
Vì sao contract phải ghim phiên bản runner?
Mạng GenLayer từ chối các bí danh runner như test, latest hoặc không có phiên bản, nên phải ghim một phiên bản cụ thể.
Khi nào tôi không nên dùng GenLayer?
Skill nói bỏ qua khi tính năng không cần đồng thuận về một câu hỏi mang tính chủ quan hoặc bên ngoài.
Agent có tự kiểm tra mã không?
Skill yêu cầu agent lint mọi contract bằng genvm-lint sau khi viết hoặc thay đổi.
Chi tiết
Mô tả gốc của tác giả
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.
Độ phổ biến
- Sao GitHub
- 7.0k
- Vị trí xếp hạng
- #13630
- Giấy phép
- —
- Cập nhật
- 26/10/2026
Bình luận
- …
Thêm skill từ kho mã này
internet-court
7.0kGiúp agent của bạn thanh toán, thuê hoặc giao dịch an toàn với một agent AI khác hoặc dịch vụ trả phí, và chỉ đến hướng dẫn chuyên sâu phù hợp.
genlayer-erc7710-connector
7.0kGiúp agent của bạn kết nối kết quả đánh giá AI với hệ thống quyền hạn, để một đánh giá xấu có thể hạn chế hoặc hủy quyền của agent.
genlayer-intelligent-contracts
7.0kGiúp agent của bạn xác định quy tắc, bằng chứng và đầu ra của một AI judge kiểm tra xem agent khác có làm đúng nhiệm vụ được ủy quyền hay không.
x402-erc7710
7.0kGiúp agent của bạn trả tiền cho dịch vụ web theo từng yêu cầu, và thiết lập chi tiêu định kỳ nằm trong ngân sách quyền hạn.
Skill tương tự
api-connector-builder
280kGiúp agent của bạn xây dựng kết nối API mới theo đúng mẫu đã có, dùng khi bạn cần thêm một tích hợp mà không tạo cách làm mới.
api-design
280kGiúp agent của bạn thiết kế REST API theo các thực hành tốt nhất, hữu ích để định nghĩa cách API giao tiếp, hiển thị lỗi và tổ chức dữ liệu.
backend-patterns
280kGiúp agent của bạn với các mẫu kiến trúc phía máy chủ và tối ưu cơ sở dữ liệu, hữu ích khi xây dựng hoặc rà soát code chạy trên máy chủ.