Write, deploy, and interact with GenLayer Python smart contracts featuring LLM calls, web access, and blockchain-consensus-safe non-determinism.
数据来源:ClawHub。 在 ClawSkills 查看
选择你使用的 Agent
方法一:命令行安装(推荐)
推荐(无需提前安装 clawhub)
npx clawhub@latest --dir ~/.claude/skills install genlayer-dev或使用 clawhub CLI(需提前安装)
clawhub --dir ~/.claude/skills install genlayer-dev⚠️ 需要 Node.js 18+,没有 Node?请使用下方方法二直接下载 ZIP。 安装 Node.js →
方法二:手动下载安装(无需 Node)
下载 ZIP,解压后将文件夹放到以下路径,重启 Agent 即可:
安装路径
~/.claude/skills/genlayer-dev/💡解压后将文件夹放到上方路径,重启 Agent 即可生效
--- name: genlayer-dev-claw-skill version: 1.0.0 description: Build GenLayer Intelligent Contracts - Python smart contracts with LLM calls and web access. Use for writing/deploying contracts, SDK reference, CLI commands, equivalence principles, storage types. Triggers: write intelligent contract, genlayer contract, genvm, gl.Contract, deploy genlayer, genlayer CLI, genlayer SDK, DynArray, TreeMap, gl.nondet, gl.eq_principle, prompt_comparative, strict_eq, genlayer deploy, genlayer up. (For explaining GenLayer concepts, use genlayer-claw-skill instead.) ---
GenLayer enables Intelligent Contracts - Python smart contracts that can call LLMs, fetch web data, and handle non-deterministic operations while maintaining blockchain consensus.
# v0.1.0
# { "Depends": "py-genlayer:latest" }
from genlayer import *
class MyContract(gl.Contract):
value: str
def __init__(self, initial: str):
self.value = initial
@gl.public.view
def get_value(self) -> str:
return self.value
@gl.public.write
def set_value(self, new_value: str) -> None:
self.value = new_value
# v0.1.0
# { "Depends": "py-genlayer:latest" }
from genlayer import *
import json
class AIContract(gl.Contract):
result: str
def __init__(self):
self.result = ""
@gl.public.write
def analyze(self, text: str) -> None:
prompt = f"Analyze this text and respond with JSON: {text}"
def get_analysis():
return gl.nondet.exec_prompt(prompt)
# All validators must get the same result
self.result = gl.eq_principle.strict_eq(get_analysis)
@gl.public.view
def get_result(self) -> str:
return self.result
# v0.1.0
# { "Depends": "py-genlayer:latest" }
from genlayer import *
class WebContract(gl.Contract):
content: str
def __init__(self):
self.content = ""
@gl.public.write
def fetch(self, url: str) -> None:
url_copy = url # Capture for closure
def get_page():
return gl.nondet.web.render(url_copy, mode="text")
self.content = gl.eq_principle.strict_eq(get_page)
@gl.public.view
def get_content(self) -> str:
return self.content
# v0.1.0 (required)# { "Depends": "py-genlayer:latest" }from genlayer import *gl.Contract (only ONE per file)__init__ (not public)@gl.public.view or @gl.public.write| Decorator | Purpose | Can Modify State | |-----------|---------|------------------| | @gl.public.view | Read-only queries | No | | @gl.public.write | State mutations | Yes | | @gl.public.write.payable | Receive value + mutate | Yes |
Replace standard Python types with GenVM storage-compatible types:
| Python Type | GenVM Type | Usage | |-------------|------------|-------| | int | u32, u64, u256, i32, i64, etc. | Sized integers | | int (unbounded) | bigint | Arbitrary precision (avoid) | | list[T] | DynArray[T] | Dynamic arrays | | dict[K,V] | TreeMap[K,V] | Ordered maps | | str | str | Strings (unchanged) | | bool | bool | Booleans (unchanged) |
⚠️ int is NOT supported! Always use sized integers.
# Creating addresses
addr = Address("0x03FB09251eC05ee9Ca36c98644070B89111D4b3F")
# Get sender
sender = gl.message.sender_address
# Conversions
hex_str = addr.as_hex # "0x03FB..."
bytes_val = addr.as_bytes # bytes
from dataclasses import dataclass
@allow_storage
@dataclass
class UserData:
name: str
balance: u256
active: bool
class MyContract(gl.Contract):
users: TreeMap[Address, UserData]
LLMs and web fetches produce different results across validators. GenLayer solves this with the Equivalence Principle.
strict_eq)All validators must produce identical results.
def get_data():
return gl.nondet.web.render(url, mode="text")
result = gl.eq_principle.strict_eq(get_data)
Best for: Factual data, boolean results, exact matches.
prompt_comparative)LLM compares leader's result against validators' results using criteria.
def get_analysis():
return gl.nondet.exec_prompt(prompt)
result = gl.eq_principle.prompt_comparative(
get_analysis,
"The sentiment classification must match"
)
Best for: LLM tasks where semantic equivalence matters.
prompt_non_comparative)Validators verify the leader's result meets criteria (don't re-execute).
result = gl.eq_principle.prompt_non_comparative(
lambda: input_data, # What to process
task="Summarize the key points",
criteria="Summary must be under 100 words and factually accurate"
)
Best for: Expensive operations, subjective tasks.
result = gl.vm.run_nondet(
leader=lambda: expensive_computation(),
validator=lambda leader_result: verify(leader_result)
)
| Function | Purpose | |----------|---------| | gl.nondet.exec_prompt(prompt) | Execute LLM prompt | | gl.nondet.web.render(url, mode) | Fetch web page (mode="text" or "html") |
⚠️ Rules:
gl.storage.copy_to_memory()# Dynamic typing
other = gl.get_contract_at(Address("0x..."))
result = other.view().some_method()
# Static typing (better IDE support)
@gl.contract_interface
class TokenInterface:
class View:
def balance_of(self, owner: Address) -> u256: ...
class Write:
def transfer(self, to: Address, amount: u256) -> bool: ...
token = TokenInterface(Address("0x..."))
balance = token.view().balance_of(my_address)
other = gl.get_contract_at(addr)
other.emit(on='accepted').update_status("active")
other.emit(on='finalized').confirm_transaction()
child_addr = gl.deploy_contract(code=contract_code, salt=u256(1))
@gl.evm.contract_interface
class ERC20:
class View:
def balance_of(self, owner: Address) -> u256: ...
class Write:
def transfer(self, to: Address, amount: u256) -> bool: ...
token = ERC20(evm_address)
balance = token.view().balance_of(addr)
token.emit().transfer(recipient, u256(100)) # Messages only on finality
npm install -g genlayer
genlayer init # Download components
genlayer up # Start local network
# Direct deploy
genlayer deploy --contract my_contract.py
# With constructor args
genlayer deploy --contract my_contract.py --args "Hello" 42
# To testnet
genlayer network set testnet-asimov
genlayer deploy --contract my_contract.py
# Read (view methods)
genlayer call --address 0x... --function get_value
# Write
genlayer write --address 0x... --function set_value --args "new_value"
# Get schema
genlayer schema --address 0x...
# Check transaction
genlayer receipt --tx-hash 0x...
...
安装 Genlayer Dev Claw Skill 后,可以对 AI 说这些话来触发它
Help me get started with Genlayer Dev Claw Skill
Explains what Genlayer Dev Claw Skill does, walks through the setup, and runs a quick demo based on your current project
Use Genlayer Dev Claw Skill to write, deploy, and interact with GenLayer Python smart contracts fe...
Invokes Genlayer Dev Claw Skill with the right parameters and returns the result directly in the conversation
What can I do with Genlayer Dev Claw Skill in my developer & devops workflow?
Lists the top use cases for Genlayer Dev Claw Skill, with example commands for each scenario
将技能文件夹放到 ~/.claude/skills/genlayer-dev/ 目录(个人级,所有项目可用),或 .claude/skills/genlayer-dev/(项目级)。重启 AI 客户端后,用 /genlayer-dev 主动调用,或让 AI 根据上下文自动发现并使用。
Genlayer Dev Claw Skill 支持 Claude、Cursor、OpenClaw,可与这些 AI 平台无缝集成,扩展其能力。
Genlayer Dev Claw Skill 可免费安装使用。请查阅仓库了解许可证信息。
Write, deploy, and interact with GenLayer Python smart contracts featuring LLM calls, web access, and blockchain-consensus-safe non-determinism.
Genlayer Dev Claw Skill 属于「Developer & DevOps」分类,该分类的技能帮助 AI 智能体在此领域执行专业任务。
Automate my developer & devops tasks using Genlayer Dev Claw Skill
Identifies repetitive steps in your workflow and sets up Genlayer Dev Claw Skill to handle them automatically