/stellar-forge:smart-contractsfrom stellar-forge
Guides Stellar Soroban smart contract development in Rust: project setup, contract anatomy, storage/TTL, authorization, cross-contract calls, events, errors, upgrades, and testing strategies.
Ships in stellar-forge. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
| File | Contents |
|---|---|
contracts/hello-world/src/lib.rs | Minimal contract scaffold |
contracts/hello-world/src/test.rs | Unit + auth + event tests |
contracts/token/src/lib.rs | Full SEP-41 token |
contracts/token/src/test.rs | Token unit + integration tests |
#![cfg(test)]
extern crate std;
use soroban_sdk::{
testutils::{Address as _, Events},
Address, Env, String, Symbol,
};
Extract shared setup into a helper function:
fn setup() -> (Env, Address, Address, MyContractClient<'static>) {
let env = Env::default();
env.mock_all_auths();
let admin = Address::generate(&env);
let user = Address::generate(&env);
let contract_id = env.register(MyContract, (&admin, 1000u32));
let client = MyContractClient::new(&env, &contract_id);
(env, admin, user, client)
}
#[test]
fn test_initial_state() {
let (_, _, _, client) = setup();
assert_eq!(client.get_count(), 0);
}
Test that only authorized callers can invoke privileged functions:
#[test]
fn test_auth_required() {
let env = Env::default();
// Do NOT call mock_all_auths() — test auth failures
let admin = Address::generate(&env);
let attacker = Address::generate(&env);
let contract_id = env.register(MyContract, (&admin,));
let client = MyContractClient::new(&env, &contract_id);
let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
client.admin_only(&attacker); // attacker has no auth
}));
assert!(result.is_err());
}
#[test]
fn test_auth_passes() {
let env = Env::default();
env.mock_all_auths();
let admin = Address::generate(&env);
let contract_id = env.register(MyContract, (&admin,));
let client = MyContractClient::new(&env, &contract_id);
client.admin_only(&admin); // should not panic
}
#[test]
fn test_events_emitted() {
let env = Env::default();
env.mock_all_auths();
let admin = Address::generate(&env);
let contract_id = env.register(MyContract, (&admin,));
let client = MyContractClient::new(&env, &contract_id);
client.do_thing();
let events = env.events().all();
assert!(!events.is_empty());
let (event_contract, topics, data) = &events[0];
assert_eq!(*event_contract, contract_id);
// topics[0] is the event type symbol
assert_eq!(topics.get(0).unwrap(), Symbol::new(&env, "DONE"));
}
#[test]
#[should_panic(expected = "HostError")]
fn test_rejects_invalid_input() {
let env = Env::default();
env.mock_all_auths();
let (_, _, client) = setup();
client.try_v1(); // intentionally bad input
}
#[test]
fn test_storage_ttl() {
let env = Env::default();
env.mock_all_auths();
let (_, _, client) = setup();
let key = DataKey::Counter;
let ttl = env.storage().instance().get_ttl(&key);
assert!(ttl > 0);
// Extend TTL
client.touch();
let new_ttl = env.storage().instance().get_ttl(&key);
assert!(new_ttl >= ttl);
}
#[test]
fn test_cross_contract() {
let env = Env::default();
env.mock_all_auths();
let admin = Address::generate(&env);
let token_id = env.register(Token, (&admin, String::from_str(&env, "TKN"), Symbol::new(&env, "TKN"), 7u32));
let aggregator_id = env.register(Aggregator, (&admin,));
let token = TokenClient::new(&env, &token_id);
let aggregator = AggregatorClient::new(&env, &aggregator_id);
token.mint(&admin, &1000);
aggregator.deposit(&admin, &token_id, &500);
assert_eq!(token.balance(&admin), 500);
assert_eq!(token.balance(&aggregator_id), 500);
}
#[test]
fn test_rollback_on_failure() {
let env = Env::default();
env.mock_all_auths();
let (_, admin, client) = setup();
let snapshot = env.clone();
// Try an operation that should fail
let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
client.fail_operation(&admin);
}));
// Restore snapshot and verify state unchanged
let env = snapshot;
// env.restore() is not a direct API, use the snapshot approach
}
# Build
cd contracts/my-contract
cargo build --release --target wasm32v1-none
# Run all tests
cargo test
# Run a specific test
cargo test test_transfer
# Run tests with output
cargo test -- --nocapture
# Check WASM size
wasm-strip target/wasm32v1-none/release/my_contract.wasm -o my_contract.optimized.wasm
ls -lh my_contract.optimized.wasm
# Manual deploy
stellar contract deploy \
--wasm target/wasm32v1-none/release/my_contract.wasm \
--source-account deployer \
--network testnet
Deployment is gated on all tests passing. If any test fails, the agent aborts and reports which tests failed. Only green tests → deploy.
cargo test → FAIL → fix & retry
→ PASS → deploy
If no prior contract has been deployed on the target network, the contracts agent auto-deploys without prompting. This is the first-deploy rule:
data/deployments/testnet.jsonEvery deploy must record the contract ID in two places:
# data/deployments/<network>.json — deployment tracker
{
"network": "testnet",
"deployer": "deployer",
"contracts": [
{
"name": "my_contract",
"contract_id": "CA...",
"wasm_hash": "<sha256>",
"deployed_at": "2026-07-29T12:00:00Z"
}
]
}
# .env — for frontend/backend reference
NEXT_PUBLIC_MY_CONTRACT_CONTRACT_ID=CA...
./scripts/deploy-contract.sh \
target/wasm32v1-none/release/my_contract.wasm \
my_contract \
testnet
This script handles build check, deploy, tracker update, and .env update in one step.
cargo test before deployingmock_all_auths() alonecargo test passing 100%data/deployments/<network>.json and .envcargo test before cargo build --release to fail fast on test failuresexamples/hello-world/Cargo.lock (opens in a new tab)examples/hello-world/Cargo.toml (opens in a new tab)examples/hello-world/src/lib.rs (opens in a new tab)examples/hello-world/src/test.rs (opens in a new tab)examples/hello-world/test_snapshots/test/test_events_emitted.1.json (opens in a new tab)examples/hello-world/test_snapshots/test/test_increment.1.json (opens in a new tab)examples/hello-world/test_snapshots/test/test_increment_auth_required.1.json (opens in a new tab)examples/hello-world/test_snapshots/test/test_increment_multiple.1.json (opens in a new tab)examples/hello-world/test_snapshots/test/test_initial_state.1.json (opens in a new tab)examples/hello-world/test_snapshots/test/test_storage_ttl_extended_on_write.1.json (opens in a new tab)examples/token/Cargo.lock (opens in a new tab)examples/token/Cargo.toml (opens in a new tab)examples/token/src/lib.rs (opens in a new tab)examples/token/src/test.rs (opens in a new tab)examples/token/test_snapshots/test/test_approve.1.json (opens in a new tab)examples/token/test_snapshots/test/test_balance_defaults_to_zero.1.json (opens in a new tab)examples/token/test_snapshots/test/test_burn.1.json (opens in a new tab)examples/token/test_snapshots/test/test_burn_insufficient_balance.1.json (opens in a new tab)examples/token/test_snapshots/test/test_metadata.1.json (opens in a new tab)examples/token/test_snapshots/test/test_mint.1.json (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Claude Code refuses to install this plugin
.claude-plugin/plugin.json: commands: Invalid input, agents.0: Invalid string: must start with "./", agents.1: Invalid string: must start with "./", agents.2: Invalid string: must start with "./", agents.3: Invalid string: must start with "./", agents.4: Invalid string: must start with "./", agents.5: Invalid string: must start with "./", skills.0: Invalid string: must start with "./"
.claude-plugin/plugin.json: commands: Invalid input, agents.0: Invalid string: must start with "./", agents.1: Invalid string: must start with "./", agents.2: Invalid string: must start with "./", agents.3: Invalid string: must start with "./", agents.4: Invalid string: must start with "./", agents.5: Invalid string: must start with "./", skills.0: Invalid string: must start with "./"
Checked against Claude Code 2.1.332's install rules. The listing below is what the repository ships; Claude Code cannot install it as published.
23 skills in this plugin
/agentic-paymentsAgentic and machine-to-machine payments on Stellar. Covers x402 (HTTP 402 paid APIs) and MPP (Machine Payments Protocol) Charge/Channel modes./assetsStellar classic assets, trustlines, and Stellar Asset Contract (SAC) bridge to smart contracts. Covers issuance, distribution, authorization flags, clawback, regulated assets, and SEP-41 token interop. Use when tokenizing real-world assets, issuing stablecoins, managing trustlines, or bridging classic assets to Soroban contracts.
/brandkitPremium brand-kit image generation skill for creating high-end brand-guidelines boards, logo systems, identity decks, and visual-world presentations. Trained for minimalist, cinematic, editorial, dark-tech, luxury, cultural, security, gaming, developer-tool, and consumer-app brand systems. Optimized for intentional logo concepting, refined composition, sparse typography, strong symbolic meaning, premium mockups, art-directed imagery, and flexible grid layouts.Other plugins' skills for the same job