重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
setup-stylus-contracts by openzeppelin/openzeppelin-skills
npx skills add https://github.com/openzeppelin/openzeppelin-skills --skill setup-stylus-contracts安装 Rust 工具链和 WASM 目标:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup target add wasm32-unknown-unknown
安装 Cargo Stylus 命令行工具:
cargo install --force cargo-stylus
创建一个新的 Stylus 项目:
cargo stylus new my_project
需要 Rust nightly 工具链。项目应包含一个
rust-toolchain.toml文件,指定 nightly 通道、rust-src组件和wasm32-unknown-unknown目标。请查看 rust-contracts-stylus 仓库 以获取当前推荐的 nightly 日期。
添加前,请从 crates.io/crates/openzeppelin-stylus 查找当前版本。添加到 :
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
Cargo.toml[dependencies]
openzeppelin-stylus = "=<VERSION>"
启用 export-abi 特性标志以生成 ABI:
[features]
export-abi = ["openzeppelin-stylus/export-abi"]
该 crate 必须同时编译为库和 cdylib:
[lib]
crate-type = ["lib", "cdylib"]
导入使用 openzeppelin_stylus(带下划线)作为 crate 根:
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 组件作为字段嵌入:
#[entrypoint]
#[storage]
struct MyToken {
erc20: Erc20,
ownable: Ownable,
}
公共方法通过 #[public] 和 #[implements(...)] 暴露。规范模式使用一个空的 impl 块进行分发注册,再加上单独的 trait 实现块:
#[public]
#[implements(IErc20<Error = erc20::Error>, IOwnable<Error = ownable::Error>)]
impl MyToken {}
#[public]
impl IErc20 for MyToken {
type Error = erc20::Error;
// 委托给 self.erc20 ...
}
顶级模块:access、finance、proxy、token、utils。
验证合约编译为有效的 Stylus WASM:
cargo stylus check
导出 Solidity ABI:
cargo stylus export-abi
部署到 Arbitrum Stylus 端点:
cargo stylus deploy --endpoint="<RPC_URL>" --private-key-path="<KEY_FILE>"
每周安装数
69
仓库
GitHub 星标数
159
首次出现
2026年3月5日
安全审计
已安装于
opencode67
github-copilot66
codex66
cline66
kimi-cli66
gemini-cli66
Install the Rust toolchain and WASM target:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup target add wasm32-unknown-unknown
Install the Cargo Stylus CLI:
cargo install --force cargo-stylus
Create a new Stylus project:
cargo stylus new my_project
A Rust nightly toolchain is required. The project should include a
rust-toolchain.tomlspecifying the nightly channel,rust-srccomponent, andwasm32-unknown-unknowntarget. Check the rust-contracts-stylus repo for the current recommended nightly date.
Look up the current version from crates.io/crates/openzeppelin-stylus before adding. Add to Cargo.toml:
[dependencies]
openzeppelin-stylus = "=<VERSION>"
Enable the export-abi feature flag for ABI generation:
[features]
export-abi = ["openzeppelin-stylus/export-abi"]
The crate must be compiled as both a library and a cdylib:
[lib]
crate-type = ["lib", "cdylib"]
Imports use openzeppelin_stylus (underscores) as the crate root:
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;
Contracts use #[storage] and #[entrypoint] on the main struct, embedding OpenZeppelin components as fields:
#[entrypoint]
#[storage]
struct MyToken {
erc20: Erc20,
ownable: Ownable,
}
Public methods are exposed with #[public] and #[implements(...)]. The canonical pattern uses an empty impl block for dispatch registration, plus separate trait impl blocks:
#[public]
#[implements(IErc20<Error = erc20::Error>, IOwnable<Error = ownable::Error>)]
impl MyToken {}
#[public]
impl IErc20 for MyToken {
type Error = erc20::Error;
// delegate to self.erc20 ...
}
Top-level modules: access, finance, proxy, token, utils.
Validate the contract compiles to valid Stylus WASM:
cargo stylus check
Export the Solidity ABI:
cargo stylus export-abi
Deploy to an Arbitrum Stylus endpoint:
cargo stylus deploy --endpoint="<RPC_URL>" --private-key-path="<KEY_FILE>"
Weekly Installs
69
Repository
GitHub Stars
159
First Seen
Mar 5, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
opencode67
github-copilot66
codex66
cline66
kimi-cli66
gemini-cli66
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
122,000 周安装