This document provides practical examples of using the StarForge Template Marketplace feature.
First, initialize the template registry with example templates:
starforge template initOutput:
███████╗████████╗ █████╗ ██████╗ ███████╗ ██████╗ ██████╗ ██████╗ ███████╗
...
◆ Initialize Template Registry
─────────────────────────────────────────────────────────────────────────
Adding example templates to the marketplace...
✓ Added: uniswap-v2
✓ Added: lending-pool
✓ Added: governance
✓ Added: multisig-wallet
✓ Template registry initialized with 4 example templates
Browse templates:
starforge template list
starforge template search defi
List all templates:
starforge template listOutput:
◆ Template Marketplace — All Templates
─────────────────────────────────────────────────────────────────────────
4 template(s) available:
1. uniswap-v2 ✓
Uniswap V2 style automated market maker (AMM) DEX implementation
1.0.0 • Stellar Community • 0 downloads
Tags: defi, dex, amm, swap
2. lending-pool ✓
Decentralized lending and borrowing protocol with collateralization
1.0.0 • Stellar Community • 0 downloads
Tags: defi, lending, borrowing
3. governance ✓
DAO governance contract with proposal creation and voting mechanisms
1.0.0 • Stellar Community • 0 downloads
Tags: dao, governance, voting
4. multisig-wallet ✓
Multi-signature wallet with threshold-based transaction approval
1.0.0 • Stellar Community • 0 downloads
Tags: wallet, multisig, security
Search by keyword:
starforge template search defiSearch with tag filtering:
starforge template search dex --tags ammstarforge template show uniswap-v2Output:
◆ Template: uniswap-v2
─────────────────────────────────────────────────────────────────────────
uniswap-v2 ✓
Description : Uniswap V2 style automated market maker (AMM) DEX implementation
Version : 1.0.0
Author : Stellar Community
Downloads : 0
Tags : defi, dex, amm, swap
Created : 2025-01-01T00:00:00Z
Updated : 2025-01-01T00:00:00Z
Source : Git Repository
URL : https://github.com/stellar/soroban-examples
Branch : main
─────────────────────────────────────────────────────────────────────────
Use this template:
starforge new contract my-project --template uniswap-v2 --from marketplace
starforge new contract my-dex --template uniswap-v2 --from marketplaceOutput:
◆ Scaffolding from Marketplace: uniswap-v2
─────────────────────────────────────────────────────────────────────────
Template : uniswap-v2
Version : 1.0.0
Author : Stellar Community
Description : Uniswap V2 style automated market maker (AMM) DEX implementation
─────────────────────────────────────────────────────────────────────────
[1/3] Fetching template...
[2/3] Validating template structure...
[3/3] Copying template to project directory...
✓ Contract 'my-dex' scaffolded from marketplace!
Next steps:
cd my-dex
stellar contract build
starforge deploy --wasm target/wasm32-unknown-unknown/release/my_dex.wasm
# First, search for what you need
starforge new contract --search lending
# Then use the template you found
starforge new contract my-lending --template lending-pool --from marketplacestarforge template publish ./my-template \
--name my-counter \
--description "A simple counter contract" \
--author "John Doe" \
--tags "example,counter" \
--version "1.0.0"Output:
◆ Publish Template
[1/3] Validating template structure...
[2/3] Copying template to local registry...
[3/3] Updating registry...
✓ Template 'my-counter' published successfully!
─────────────────────────────────────────────────────────────────────────
Name : my-counter
Version : 1.0.0
Author : John Doe
Tags : example, counter
─────────────────────────────────────────────────────────────────────────
Others can now use your template:
starforge new contract my-project --template my-counter --from marketplace
If you don't provide all options, StarForge will prompt you:
starforge template publish ./my-templateInteractive prompts:
Template description: A simple counter contract
Author name: John Doe
- Create your contract:
starforge new contract template-base
cd template-base- Edit
Cargo.tomlto use placeholders:
[package]
name = "{{PROJECT_NAME}}"
version = "0.1.0"
edition = "2021"- Edit
src/lib.rsto use placeholders:
#[contract]
pub struct {{PROJECT_NAME_PASCAL}};
#[contractimpl]
impl {{PROJECT_NAME_PASCAL}} {
pub fn hello(env: Env, to: Symbol) -> Vec<Symbol> {
vec![&env, symbol_short!("Hello"), to]
}
}- Test your template:
cargo test
stellar contract build- Publish it:
cd ..
starforge template publish ./template-base \
--name my-hello-world \
--description "Custom hello world template" \
--author "Your Name" \
--tags "example,hello-world"You can also use templates from local directories without publishing:
# The template will be copied from the local path
starforge template publish ./my-local-templateRemove a template:
starforge template remove my-counter# Search for DeFi templates
starforge template search defi --tags dex
# View details of interesting template
starforge template show uniswap-v2
# Create your DEX project
starforge new contract my-stellar-dex --template uniswap-v2 --from marketplace
# Build and test
cd my-stellar-dex
stellar contract build
cargo test
# Deploy to testnet
starforge deploy \
--wasm target/wasm32-unknown-unknown/release/my_stellar_dex.wasm \
--network testnet# Find governance templates
starforge template search governance
# Use the governance template
starforge new contract my-dao --template governance --from marketplace
# Customize and deploy
cd my-dao
# Edit src/lib.rs to customize voting logic
stellar contract build
starforge deploy --wasm target/wasm32-unknown-unknown/release/my_dao.wasm# Create a new innovative contract
starforge new contract flash-loan-template
# Develop your contract
cd flash-loan-template
# ... implement flash loan logic ...
cargo test
stellar contract build
# Add placeholders for reusability
# Edit Cargo.toml and src/lib.rs to add {{PROJECT_NAME}} etc.
# Publish for others to use
cd ..
starforge template publish ./flash-loan-template \
--name flash-loan \
--description "Flash loan implementation for Soroban" \
--author "DeFi Innovator" \
--tags "defi,flash-loan,lending" \
--version "1.0.0"
# Share with the community
echo "New flash loan template available!"
echo "starforge new contract my-flash-loan --template flash-loan --from marketplace"- Always review code - Check the template source before using
- Prefer verified templates - Look for the ✓ badge
- Check version - Use the latest stable version
- Read documentation - Review the template's README
- Test thoroughly - Test in a safe environment first
- Use clear placeholders - Make it obvious what needs to be replaced
- Include documentation - Add a comprehensive README
- Add tests - Include working test cases
- Follow conventions - Use Soroban best practices
- Version properly - Use semantic versioning
- Tag appropriately - Use relevant, searchable tags
- Keep it simple - Focus on one clear use case
starforge template show my-template
# Error: Template 'my-template' not found in registrySolution: Check available templates with starforge template list
starforge template publish ./bad-template
# Error: Template must contain Cargo.tomlSolution: Ensure your template has the required files:
Cargo.tomlsrc/directorysrc/lib.rs
starforge new contract my-project --template some-template --from marketplace
# Error: Git clone failed: repository not foundSolution: Check the template's source URL with starforge template show some-template
- Explore the Template Marketplace Documentation
- Check out example templates
- Join the community to share your templates
- Contribute to the official template registry