$npx -y skills add OpenZeppelin/openzeppelin-skills --skill setup-stellar-contractsSet up a Stellar/Soroban smart contract project with OpenZeppelin Contracts for Stellar. Use when users need to: (1) install Stellar CLI and Rust toolchain for Soroban, (2) create a new Soroban project, (3) add OpenZeppelin Stellar dependencies to Cargo.toml, or (4) understand So
| 1 | # Stellar Setup |
| 2 | |
| 3 | ## Soroban/Stellar Development Setup |
| 4 | |
| 5 | Install the Rust toolchain (v1.84.0+) and the Soroban WASM target: |
| 6 | |
| 7 | ```bash |
| 8 | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh |
| 9 | rustup target add wasm32v1-none |
| 10 | ``` |
| 11 | |
| 12 | Install the Stellar CLI: |
| 13 | |
| 14 | ```bash |
| 15 | curl -fsSL https://github.com/stellar/stellar-cli/raw/main/install.sh | sh |
| 16 | ``` |
| 17 | |
| 18 | Create a new Soroban project: |
| 19 | |
| 20 | ```bash |
| 21 | stellar contract init my_project |
| 22 | ``` |
| 23 | |
| 24 | This creates a Cargo workspace with contracts in `contracts/*/`. |
| 25 | |
| 26 | ## OpenZeppelin Dependencies |
| 27 | |
| 28 | Look up the current version from the [stellar-contracts repo](https://github.com/OpenZeppelin/stellar-contracts) before adding. Pin exact versions with `=` as the library is under active development. |
| 29 | |
| 30 | Add OpenZeppelin crates to the **root** `Cargo.toml` under `[workspace.dependencies]`: |
| 31 | |
| 32 | ```toml |
| 33 | [workspace.dependencies] |
| 34 | stellar-tokens = "=<VERSION>" |
| 35 | stellar-access = "=<VERSION>" |
| 36 | stellar-contract-utils = "=<VERSION>" |
| 37 | stellar-macros = "=<VERSION>" |
| 38 | ``` |
| 39 | |
| 40 | Then reference them in the **per-contract** `contracts/*/Cargo.toml`: |
| 41 | |
| 42 | ```toml |
| 43 | [dependencies] |
| 44 | soroban-sdk = { workspace = true } |
| 45 | stellar-tokens = { workspace = true } |
| 46 | stellar-access = { workspace = true } |
| 47 | stellar-contract-utils = { workspace = true } |
| 48 | stellar-macros = { workspace = true } |
| 49 | ``` |
| 50 | |
| 51 | Available crates: `stellar-access`, `stellar-accounts`, `stellar-contract-utils`, `stellar-fee-abstraction`, `stellar-governance`, `stellar-macros`, `stellar-tokens`. |
| 52 | |
| 53 | > Only add the crates the contract actually uses. `stellar-macros` provides proc-macro attributes (for example, `#[when_not_paused]`, `#[only_owner]`, `#[derive(Upgradeable)]`) and is needed in most contracts. |
| 54 | |
| 55 | ## Code Patterns |
| 56 | |
| 57 | Imports use underscores as the crate root (Rust convention): |
| 58 | |
| 59 | ```rust |
| 60 | use stellar_tokens::fungible::{Base, FungibleToken}; |
| 61 | use stellar_tokens::fungible::burnable::FungibleBurnable; |
| 62 | use stellar_access::ownable::Ownable; |
| 63 | use stellar_contract_utils::pausable::Pausable; |
| 64 | use stellar_macros::when_not_paused; |
| 65 | ``` |
| 66 | |
| 67 | Contracts use `#[contract]` on the struct and `#[contractimpl]` on the impl block (from `soroban_sdk`): |
| 68 | |
| 69 | ```rust |
| 70 | use soroban_sdk::{contract, contractimpl, Env}; |
| 71 | |
| 72 | #[contract] |
| 73 | pub struct MyToken; |
| 74 | |
| 75 | #[contractimpl] |
| 76 | impl MyToken { |
| 77 | // Implement trait methods here |
| 78 | } |
| 79 | ``` |
| 80 | |
| 81 | Trait implementations are separate `impl` blocks per trait (e.g., `FungibleToken`, `Pausable`). Guard macros like `#[when_not_paused]` and `#[only_owner]` decorate individual functions. |
| 82 | |
| 83 | ## Platform Notes |
| 84 | |
| 85 | - **Read operations are free in Stellar.** Optimize for minimizing writes; reads and computation are cheap. Prefer clean, readable code over micro-optimizations. |
| 86 | - **Instance storage TTL extension is the developer's responsibility.** The OpenZeppelin library handles TTL extension for other storage entries, but contracts must extend their own `instance` storage entries to prevent expiration. |
| 87 | |
| 88 | ## Build & Test |
| 89 | |
| 90 | Build the contract to WASM: |
| 91 | |
| 92 | ```bash |
| 93 | stellar contract build |
| 94 | ``` |
| 95 | |
| 96 | This is a shortcut for `cargo build --target wasm32v1-none --release`. Output appears in `target/wasm32v1-none/release/`. |
| 97 | |
| 98 | Run tests: |
| 99 | |
| 100 | ```bash |
| 101 | cargo test |
| 102 | ``` |
| 103 | |
| 104 | > `soroban-sdk` testutils are automatically enabled for in-crate unit tests. |