setup-stellar-contracts by openzeppelin/openzeppelin-skills
npx skills add https://github.com/openzeppelin/openzeppelin-skills --skill setup-stellar-contracts安装 Rust 工具链(v1.84.0+)和 Soroban WASM 目标:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup target add wasm32v1-none
安装 Stellar CLI:
curl -fsSL https://github.com/stellar/stellar-cli/raw/main/install.sh | sh
创建一个新的 Soroban 项目:
stellar contract init my_project
这将在 contracts/*/ 目录下创建一个包含合约的 Cargo 工作空间。
在添加之前,请从 stellar-contracts 仓库 查找当前版本。由于该库正在积极开发中,请使用 = 固定确切的版本。
将 OpenZeppelin crate 添加到 根目录 的 Cargo.toml 文件中的 部分:
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
[workspace.dependencies][workspace.dependencies]
stellar-tokens = "=<VERSION>"
stellar-access = "=<VERSION>"
stellar-contract-utils = "=<VERSION>"
stellar-macros = "=<VERSION>"
然后在 每个合约 的 contracts/*/Cargo.toml 文件中引用它们:
[dependencies]
soroban-sdk = { workspace = true }
stellar-tokens = { workspace = true }
stellar-access = { workspace = true }
stellar-contract-utils = { workspace = true }
stellar-macros = { workspace = true }
可用的 crate:stellar-access, stellar-accounts, stellar-contract-utils, stellar-fee-abstraction, stellar-governance, stellar-macros, stellar-tokens。
只添加合约实际使用的 crate。
stellar-macros提供了过程宏属性(例如#[when_not_paused],#[only_owner],#[derive(Upgradeable)]),大多数合约都需要它。
导入使用下划线作为 crate 根(Rust 惯例):
use stellar_tokens::fungible::{Base, FungibleToken};
use stellar_tokens::fungible::burnable::FungibleBurnable;
use stellar_access::ownable::Ownable;
use stellar_contract_utils::pausable::Pausable;
use stellar_macros::when_not_paused;
合约在结构体上使用 #[contract],在 impl 块上使用 #[contractimpl](来自 soroban_sdk):
use soroban_sdk::{contract, contractimpl, Env};
#[contract]
pub struct MyToken;
#[contractimpl]
impl MyToken {
// 在此处实现 trait 方法
}
Trait 实现是每个 trait(例如 FungibleToken, Pausable)独立的 impl 块。守卫宏如 #[when_not_paused] 和 #[only_owner] 用于装饰单个函数。
instance 存储条目,以防止过期。将合约构建为 WASM:
stellar contract build
这是 cargo build --target wasm32v1-none --release 的快捷方式。输出文件位于 target/wasm32v1-none/release/ 目录。
运行测试:
cargo test
对于 crate 内的单元测试,
soroban-sdk的测试工具会自动启用。
每周安装次数
85
仓库
GitHub 星标数
159
首次出现
2026年3月5日
安全审计
安装于
opencode83
gemini-cli82
codex82
cline82
github-copilot82
kimi-cli82
Install the Rust toolchain (v1.84.0+) and the Soroban WASM target:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup target add wasm32v1-none
Install the Stellar CLI:
curl -fsSL https://github.com/stellar/stellar-cli/raw/main/install.sh | sh
Create a new Soroban project:
stellar contract init my_project
This creates a Cargo workspace with contracts in contracts/*/.
Look up the current version from the stellar-contracts repo before adding. Pin exact versions with = as the library is under active development.
Add OpenZeppelin crates to the root Cargo.toml under [workspace.dependencies]:
[workspace.dependencies]
stellar-tokens = "=<VERSION>"
stellar-access = "=<VERSION>"
stellar-contract-utils = "=<VERSION>"
stellar-macros = "=<VERSION>"
Then reference them in the per-contract contracts/*/Cargo.toml:
[dependencies]
soroban-sdk = { workspace = true }
stellar-tokens = { workspace = true }
stellar-access = { workspace = true }
stellar-contract-utils = { workspace = true }
stellar-macros = { workspace = true }
Available crates: stellar-access, stellar-accounts, stellar-contract-utils, stellar-fee-abstraction, stellar-governance, stellar-macros, stellar-tokens.
Only add the crates the contract actually uses.
stellar-macrosprovides proc-macro attributes (for example,#[when_not_paused],#[only_owner],#[derive(Upgradeable)]) and is needed in most contracts.
Imports use underscores as the crate root (Rust convention):
use stellar_tokens::fungible::{Base, FungibleToken};
use stellar_tokens::fungible::burnable::FungibleBurnable;
use stellar_access::ownable::Ownable;
use stellar_contract_utils::pausable::Pausable;
use stellar_macros::when_not_paused;
Contracts use #[contract] on the struct and #[contractimpl] on the impl block (from soroban_sdk):
use soroban_sdk::{contract, contractimpl, Env};
#[contract]
pub struct MyToken;
#[contractimpl]
impl MyToken {
// Implement trait methods here
}
Trait implementations are separate impl blocks per trait (e.g., FungibleToken, Pausable). Guard macros like #[when_not_paused] and #[only_owner] decorate individual functions.
instance storage entries to prevent expiration.Build the contract to WASM:
stellar contract build
This is a shortcut for cargo build --target wasm32v1-none --release. Output appears in target/wasm32v1-none/release/.
Run tests:
cargo test
soroban-sdktestutils are automatically enabled for in-crate unit tests.
Weekly Installs
85
Repository
GitHub Stars
159
First Seen
Mar 5, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
opencode83
gemini-cli82
codex82
cline82
github-copilot82
kimi-cli82
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
120,000 周安装