闲社服务运行正常AI智能体自动化平台
s

配置Stylus合约

技能标识:setup-stylus-contracts

Set up a Stylus smart contract project with OpenZeppelin Contracts for Stylus on Arbitrum. Use when users need to: (1) install Rust toolchain and WASM target for Stylus, (2) create a new Cargo Stylus project, (3) add OpenZeppelin Stylus dependencies to Cargo.toml, or (4) understand Stylus import conventions and storage patterns for OpenZeppelin.

作者:admin | 来源记录:ClawHub
登记来源
ClawHub
版本
V 1.0.1
检测标记
后台标记通过
免费
免费获取
0
收藏
来源与检测标记为平台登记信息,并不代表已展示可复核的检测报告。使用前请核对版本、依赖和所需权限,建议先在隔离环境中运行。
概述
安装方式
版本历史

配置Stylus合约

Stylus 设置

Rust 与 Cargo Stylus 设置

安装 Rust 工具链和 WASM 目标:

bash
curl --proto =https --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup target add wasm32-unknown-unknown

安装 Cargo Stylus CLI:

bash
cargo install --force cargo-stylus

创建新的 Stylus 项目:

bash
cargo stylus new my_project

需要 Rust nightly 工具链。项目应包含一个 rust-toolchain.toml 文件,指定 nightly 频道、rust-src 组件和 wasm32-unknown-unknown 目标。请查看 rust-contracts-stylus 仓库 获取当前推荐的 nightly 日期。

添加 OpenZeppelin 依赖

在添加前,请从 crates.io/crates/openzeppelin-stylus 查询当前版本。添加到 Cargo.toml:

toml
[dependencies]
openzeppelin-stylus = =<版本号>

启用 export-abi 特性标志以生成 ABI:

toml
[features]
export-abi = [openzeppelin-stylus/export-abi]

该 crate 必须同时编译为库和 cdylib:

toml
[lib]
crate-type = [lib, cdylib]

导入约定

导入使用 openzeppelin_stylus(下划线)作为 crate 根目录:

rust
use openzeppelin_stylus::token::erc20::{Erc20, IErc20};
use openzeppelin_stylus::access::ownable::{Ownable, IOwnable};
use openzeppelin_stylus::utils::pausable::{Pausable, IPausable};
use openzeppelin_stylus::utils::introspection::erc165::IErc165;

合约在主结构体上使用 #[storage] 和 #[entrypoint],将 OpenZeppelin 组件作为字段嵌入:

rust
#[entrypoint]
#[storage]
struct MyToken {
erc20: Erc20,
ownable: Ownable,
}

公共方法使用 #[public] 和 #[implements(...)] 暴露。标准模式使用空的 impl 块进行分发注册,外加单独的 trait impl 块:

rust
#[public]
#[implements(IErc20, IOwnable)]
impl MyToken {}

#[public]
impl IErc20 for MyToken {
type Error = erc20::Error;
// 委托给 self.erc20 ...
}

顶层模块:access、finance、proxy、token、utils。

构建与部署基础

验证合约编译为有效的 Stylus WASM:

bash
cargo stylus check

导出 Solidity ABI:

bash
cargo stylus export-abi

部署到 Arbitrum Stylus 端点:

bash
cargo stylus deploy --endpoint= --private-key-path=<密钥文件路径>

私钥安全: 切勿在命令行中使用 --private-key 传入原始密钥——它会在 shell 历史记录和进程列表中可见。始终使用 --private-key-path 配合具有严格权限(chmod 600)的文件,或使用硬件钱包/密钥库。

标签

skill ai

通过对话安装

以下为平台配置的接入选项,并非逐项实测通过。能否安装取决于客户端支持、技能来源和运行环境:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 setup-stylus-contracts-1776078136 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 setup-stylus-contracts-1776078136 技能

通过命令行安装

skillhub install setup-stylus-contracts-1776078136

下载

⬇ 下载 setup-stylus-contracts v1.0.1(免费)

文件大小: 2.12 KB | 发布时间: 2026-4-15 14:20

v1.0.1 最新 2026-4-15 14:20
Fix display name from probe to proper title
返回顶部