index

Panduan Project Solo

· 3min

Quick reference guide untuk build project Anda hari ini! 🚀


⚡ Quick Workflow

PlanningSetupCodeTestDeployDocument

Total time: 3-4 jam


1️⃣ Planning (10 menit)

Define Your Idea

Problem: [Apa masalahnya?]
Solution: [Smart contract solve gimana?]
Users: [Siapa yang pakai?]
Functions: [3-4 core functions]

Example:

Problem: Warung sulit track customer loyalty
Solution: Token reward system
Users: Pemilik warung & customers
Functions:
  1. initialize() - Setup system
  2. give_points() - Owner kasih poin
  3. check_points() - Customer cek saldo
  4. use_points() - Customer pakai poin

2️⃣ Setup (5 menit)

cd ~/stellar-workshop
stellar contract init my-project
cd my-project

Contract structure:

my-project/contracts/my-contract/src/
├── lib.rs    # Your code here
└── test.rs   # Your tests here

3️⃣ Code Patterns

Basic Template

#![no_std]
use soroban_sdk::{contract, contractimpl, symbol_short, Address, Env, Map, Symbol};

const OWNER: Symbol = symbol_short!("owner");

#[contract]
pub struct MyContract;

#[contractimpl]
impl MyContract {
    pub fn initialize(env: Env, owner: Address) {
        owner.require_auth();
        env.storage().instance().set(&OWNER, &owner);
    }

    // Your functions here
}

Storage Patterns

// Single value
env.storage().instance().set(&KEY, &value);
let value = env.storage().instance().get(&KEY).unwrap();

// Map storage
let mut map: Map<Address, i128> = Map::new(&env);
map.set(user, amount);
env.storage().instance().set(&MAP_KEY, &map);

// Read from map
let map: Map<Address, i128> = env.storage().instance().get(&MAP_KEY).unwrap();
let amount = map.get(user).unwrap_or(0);

Authorization

// Require auth
user.require_auth();

// Check owner
let owner: Address = env.storage().instance().get(&OWNER).unwrap();
if user != owner {
    panic!("Not authorized");
}

Time-based

let now = env.ledger().timestamp();
let deadline: u64 = env.storage().instance().get(&DEADLINE).unwrap();
if now > deadline {
    panic!("Expired");
}

4️⃣ Testing & Deploy (30 menit)

Test Template

#![cfg(test)]
use super::*;
use soroban_sdk::{testutils::Address as _, Address, Env};

#[test]
fn test_initialize() {
    let env = Env::default();
    let contract_id = env.register(MyContract, ());
    let client = MyContractClient::new(&env, &contract_id);
    let owner = Address::generate(&env);

    env.mock_all_auths();
    client.initialize(&owner);

    // Assert here
}

Commands

# Test
cargo test

# Build
stellar contract build

# Deploy
stellar contract deploy \
  --wasm target/wasm32v1-none/release/*.wasm \
  --source-account alice \
  --network testnet

# Invoke
stellar contract invoke \
  --id <CONTRACT_ID> \
  --source-account alice \
  --network testnet \
  -- function_name --param value

5️⃣ Documentation (15 menit)

README Template

# [Project Name]

## Problem

[What problem does this solve?]

## Solution

[How does your contract solve it?]

## Functions

- `initialize()` - Setup
- `your_function()` - Description

## Deploy

Contract ID: `<YOUR_ID>`
Network: Stellar Testnet

## Usage

[Include 1-2 command examples]

## Author

[Your Name] - Stellar Indonesia Workshop

Push to GitHub

git init
git add .
git commit -m "Stellar workshop project"
git remote add origin https://github.com/you/project.git
git push -u origin main

📝 Complete Example

Simple points reward system (100 lines):

#![no_std]
use soroban_sdk::{contract, contractimpl, symbol_short, Address, Env, Map, Symbol};

const OWNER: Symbol = symbol_short!("owner");
const POINTS: Symbol = symbol_short!("points");

#[contract]
pub struct PointsReward;

#[contractimpl]
impl PointsReward {
    pub fn initialize(env: Env, owner: Address) {
        owner.require_auth();
        env.storage().instance().set(&OWNER, &owner);
        let points: Map<Address, i128> = Map::new(&env);
        env.storage().instance().set(&POINTS, &points);
    }

    pub fn give_points(env: Env, user: Address, amount: i128) {
        let owner: Address = env.storage().instance().get(&OWNER).unwrap();
        owner.require_auth();

        let mut points: Map<Address, i128> =
            env.storage().instance().get(&POINTS).unwrap();
        let current = points.get(user.clone()).unwrap_or(0);
        points.set(user, current + amount);
        env.storage().instance().set(&POINTS, &points);
    }

    pub fn get_points(env: Env, user: Address) -> i128 {
        let points: Map<Address, i128> =
            env.storage().instance().get(&POINTS).unwrap();
        points.get(user).unwrap_or(0)
    }
}

⚡ Quick Commands

# Build & Test
stellar contract build
cargo test

# Deploy
stellar contract deploy \
  --wasm target/wasm32v1-none/release/*.wasm \
  --source-account alice \
  --network testnet

# Use contract
stellar contract invoke \
  --id <ID> \
  --source-account alice \
  --network testnet \
  -- function_name --param value

� Tips

DO:

  • Start simple
  • Test each function
  • Ask mentors

DON’T:

  • Over-complicate
  • Skip testing
  • Forget README

Ready to code! Check Project Ideas untuk inspiration! 🚀