用途:在 Arbitrum 上搭建使用 OpenZeppelin Contracts for Stylus 的 Stylus 智能合约项目,适合需要初始化 Rust/Stylus 开发环境、添加 OpenZeppelin 依赖并完成编译与部署准备的场景。
环境准备:安装 Rust 工具链与 WASM 目标:curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh,然后 rustup target add wasm32-unknown-unknown;安装 Cargo Stylus CLI:cargo install --force cargo-stylus;创建项目:cargo stylus new my_project。需要 Rust nightly 工具链,项目应包含 rust-toolchain.toml,指定 nightly 通道、rust-src 组件与 wasm32-unknown-unknown 目标;当前推荐的 nightly 日期需查看 rust-contracts-stylus 仓库。
依赖配置:添加依赖前先到 crates.io/crates/openzeppelin-stylus 查询当前版本,在 Cargo.toml 中写 openzeppelin-stylus = "=<VERSION>";启用 export-abi 特性用于 ABI 生成;crate 需同时编译为库与 cdylib,即 crate-type = ["lib", "cdylib"]。
导入与写法:crate 根为 openzeppelin_stylus(下划线),如 use openzeppelin_stylus::token::erc20::{Erc20, IErc20};。主结构体使用 #[storage] 与 #[entrypoint],将 OpenZeppelin 组件作为字段嵌入;公开方法用 #[public] 与 #[implements(...)] 暴露,典型模式是空 impl 块做分发注册,另用 trait impl 块实现。顶层模块包括 access、finance、proxy、token、utils。
构建与部署:cargo stylus check 校验编译为有效 Stylus WASM;cargo stylus export-abi 导出 Solidity ABI;cargo stylus deploy --endpoint="<RPC_URL>" --private-key-path="<KEY_FILE>" 部署到 Arbitrum Stylus 端点。
限制:资料未提供具体版本号、费用、性能数据及完整示例代码,相关细节暂未提供。