OpenZeppelin Contracts for Stylus
特性
-
✨ 从
openzeppelin-contracts
移植的安全至上的合约。 -
📦 用 Rust 编写,完全支持
no_std
。 -
🧪 通过单元测试和集成测试进行测试。
-
🚧 积极开发中。
快速开始
将依赖项添加到您的 Cargo.toml
中:
[dependencies]
openzeppelin-stylus = "=0.2.0"
启用 ABI 导出特性:
[features]
export-abi = ["openzeppelin-stylus/export-abi"]
使用示例
使用该库的最小 ERC-20 实现:
use openzeppelin_stylus::token::erc20::{self, Erc20, IErc20};
use stylus_sdk::{
alloy_primitives::{Address, U256},
prelude::*,
};
#[entrypoint]
#[storage]
struct Erc20Example {
erc20: Erc20,
}
#[public]
#[implements(IErc20<Error = erc20::Error>)]
impl Erc20Example {}
#[public]
impl IErc20 for Erc20Example {
// ERC-20 逻辑实现...
}
在 examples
目录中探索更多示例。
兼容性
该库旨在与 no_std
一起使用。为了保持您的合约兼容,请禁用拉取标准库的任何依赖项的默认特性:
[dependencies]
alloy-primitives = { version = "=0.8.20", default-features = false }
stylus-sdk = "=0.9.0"
安全
虽然该库正在积极开发中,但安全仍然是重中之重。有关过去的审计和安全报告,请参见 audits
目录。
许可证
在 MIT 许可证下发布。