Skip to main content

Module 1: Pengenalan Sui Blockchain

Durasi: 2 jam (10:00 - 12:00)
Target: Memahami arsitektur unik Sui dan perbedaannya

🎯 Tujuan Pembelajaran

Setelah modul ini, Anda akan mampu:

  • Menjelaskan arsitektur object-centric Sui vs blockchain tradisional
  • Memahami mekanisme konsensus dan eksekusi paralel
  • Menyiapkan lingkungan pengembangan yang lengkap
  • Melakukan deployment dan berinteraksi dengan smart contract pertama
  • Menggunakan Sui Explorer dan memahami struktur transaksi

🧠 Konsep Inti

Catatan: Jika Anda belum familiar dengan dasar-dasar blockchain, silakan baca Module 0: Pengenalan Blockchain & Web3 terlebih dahulu.

Apa yang Membuat Sui Berbeda?

Sui adalah blockchain Layer 1 generasi terbaru yang merevolusi cara kita berpikir tentang arsitektur blockchain:

🔄 Model Berpusat pada Objek

Blockchain Tradisional (Ethereum):
Akun A (Saldo: 100 ETH) → Akun B (Saldo: 50 ETH)

Blockchain Sui:
Objek 1 (Pemilik: Alice, Nilai: 100) → Objek 2 (Pemilik: Bob, Nilai: 50)

Perbedaan Utama:

FiturEthereumSui
Model DataBerbasis akunBerpusat pada objek
Penyimpanan StatePohon state globalKepemilikan objek individual
EksekusiPemrosesan berurutanParalel jika memungkinkan
BahasaSolidityMove
Finalitas12+ detikDi bawah 1 detik untuk tx sederhana
Throughput15 TPS120,000+ TPS secara teoritis

🚀 Mesin Eksekusi Paralel

// Transaksi A: Transfer Objek X dari Alice ke Bob
// Transaksi B: Transfer Objek Y dari Carol ke Dave
// ✅ Ini bisa dieksekusi secara paralel (objek berbeda)

// Transaksi A: Modifikasi Objek X
// Transaksi B: Juga modifikasi Objek X
// ❌ Ini harus dieksekusi secara berurutan (objek sama)

🏗️ Gambaran Arsitektur Sui

1. Layer Konsensus (Narwhal & Tusk)

  • Narwhal: Mempool throughput tinggi untuk pengurutan transaksi
  • Tusk: Konsensus tahan kesalahan Byzantine untuk finalisasi
  • Hasil: 120,000+ TPS dengan finalitas di bawah 1 detik

2. Mesin Eksekusi

  • Paralelisme berbasis objek: Objek independen = pemrosesan paralel
  • Pengurutan kausal: Transaksi dependen dieksekusi dalam urutan yang benar
  • Optimasi gas: Bayar hanya untuk komputasi yang benar-benar digunakan

3. Layer Penyimpanan

  • Object Store: Setiap objek disimpan dengan metadata (ID, versi, pemilik)
  • Versioning: Melacak mutasi objek dari waktu ke waktu
  • Pruning: Versi lama dapat dibersihkan

4. Runtime Move

  • Keamanan Resource: Tipe linear mencegah double-spending
  • Verifikasi Formal: Bukti matematis kebenaran
  • Gas Metering: Pengukuran biaya komputasi yang presisi

⚙️ Setup Lingkungan (30 menit)

Langkah 1: Install Sui CLI

macOS:

brew install sui

Windows (PowerShell):

winget install sui

Linux/Install Manual:

# Install Rust dulu
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Install Sui
cargo install --locked --git https://github.com/MystenLabs/sui.git --branch testnet sui

Langkah 2: Verifikasi Instalasi

sui --version
# Output: sui 1.x.x-xxxxxxx

Step 3: Initialize Sui Client

# Initialize client configuration  
sui client

# Check available environments
sui client envs

# Add testnet environment
sui client new-env --alias testnet --rpc https://fullnode.testnet.sui.io:443

# Switch to testnet (recommended for learning)
sui client switch --env testnet

# Generate new address
sui client new-address ed25519

# List your addresses
sui client addresses

Expected Output:

╭─────────────────────────────────────────────────────────────╮
│ Addresses │
├─────────────────────────────────────────────────────────────┤
│ alias │ address │
│ alice │ 0x742d...8c92 │
╰─────────────────────────────────────────────────────────────╯

Step 4: Setup Wallet & Get Testnet Tokens

Option A: Browser Wallet Setup (Sui Wallet)

  1. Install Sui Wallet browser extension
  2. Create new wallet atau import existing
  3. Switch to Testnet network
  4. Copy your wallet address

Option B: Browser Wallet Setup (Slush Wallet)

  1. Install Slush Wallet browser extension
  2. Create new wallet atau import existing
  3. Switch to Testnet network
  4. Copy your wallet address

Option C: Use CLI Address

  1. Use address generated di Step 3
  2. Export private key jika diperlukan:
sui keytool export <ADDRESS> --key-scheme ed25519

Import Browser Wallet ke CLI

Jika Anda menggunakan Slush atau Sui Wallet, Anda bisa import private key ke CLI:

From Slush Wallet:

  1. Open Slush Wallet → Settings → Security → Export Private Key
  2. Copy private key (format: 0x...)
  3. Import ke CLI:
# Import private key ke CLI
sui keytool import "<PRIVATE_KEY>" ed25519

# Set sebagai active address
sui client switch --address <ADDRESS>

# Verify import berhasil
sui client addresses

From Sui Wallet:

  1. Open Sui Wallet → Settings → Export Private Key
  2. Copy private key
  3. Import dengan command yang sama di atas

Get Test Tokens

# Request testnet tokens via CLI
sui client faucet

# Alternative: visit faucet website
# https://faucet.sui.io/
# Paste your address dan request tokens

Verify Balance:

# Check balance via CLI
sui client balance

# Check specific address
sui client balance <ADDRESS>

Step 5: VS Code Setup

  1. Install VS Code
  2. Install Sui Move Extension:
    • Open VS Code
    • Go to Extensions (Ctrl+Shift+X)
    • Search "Sui Move"
    • Install official extension

💡 Understanding Sui Objects

Object Structure Deep Dive

Every object di Sui memiliki:

struct Object {
id: UID, // Globally unique identifier
version: u64, // Increments with each mutation
owner: Owner, // Who can access this object
type: TypeName, // Defined by Move struct
}

Object Ownership Types

1. Owned Objects

// Only specific address can access
transfer::transfer(coin, recipient_address);

2. Shared Objects

// Anyone can access (e.g., liquidity pools)
transfer::share_object(pool);

3. Immutable Objects

// Cannot be modified (e.g., published packages)
transfer::freeze_object(metadata);

Object Lifecycle Example

// 1. Create object
let coin = coin::mint(&mut treasury, 1000, ctx);
// Object ID: 0xabc123, Version: 0, Owner: Treasury

// 2. Transfer object
transfer::public_transfer(coin, @alice);
// Object ID: 0xabc123, Version: 1, Owner: Alice

// 3. Modify object
coin::burn(&mut treasury, coin);
// Object ID: 0xabc123, Version: 2, Status: Destroyed

✅ Exercise 1: First Contract Deployment (45 menit)

Step 1: Create New Project

# Create Move project
sui move new hello_sui
cd hello_sui

Step 2: Project Structure

hello_sui/
├── Move.toml # Project configuration
├── sources/ # Move source files
│ └── hello.move # Your smart contract
└── tests/ # Test files

Step 3: Configure Move.toml

[package]
name = "hello_sui"
version = "0.0.1"
edition = "2024.beta"

[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/testnet" }

[addresses]
hello_sui = "0x0"

Step 4: Write Hello World Contract

Create sources/hello.move:

module hello_sui::hello_world {
use std::string::{utf8, String};
use sui::event;

/// Greeting object that stores a message
public struct Greeting has key, store {
id: object::UID,
message: String,
creator: address,
}

/// Event emitted when greeting is created
public struct GreetingCreated has copy, drop {
greeting_id: address,
message: String,
creator: address,
}

/// Create a new greeting with custom message
#[allow(lint(self_transfer))]
public fun create_greeting(
message_bytes: vector<u8>,
ctx: &mut tx_context::TxContext
) {
let message = utf8(message_bytes);
let creator = tx_context::sender(ctx);

let greeting = Greeting {
id: object::new(ctx),
message,
creator,
};

let greeting_id = object::uid_to_address(&greeting.id);

// Emit event
event::emit(GreetingCreated {
greeting_id,
message,
creator,
});

// Transfer to creator
transfer::public_transfer(greeting, creator);
}

/// Get greeting message (read-only)
public fun get_message(greeting: &Greeting): String {
greeting.message
}

/// Get greeting creator
public fun get_creator(greeting: &Greeting): address {
greeting.creator
}

/// Update greeting message (only creator)
public fun update_message(
greeting: &mut Greeting,
new_message: vector<u8>,
ctx: &tx_context::TxContext
) {
assert!(greeting.creator == tx_context::sender(ctx), 0);
greeting.message = utf8(new_message);
}

#[test_only]
public fun create_greeting_for_testing(
message_bytes: vector<u8>,
ctx: &mut tx_context::TxContext
): Greeting {
let message = utf8(message_bytes);
Greeting {
id: object::new(ctx),
message,
creator: tx_context::sender(ctx),
}
}
}

Step 5: Build Contract

sui move build

Expected Success Output:

BUILDING hello_sui
BUILDING Sui
Build Successful

Step 6: Deploy to Testnet

sui client publish --gas-budget 20000000

Save Important Information:

  • Package ID: Your deployed module identifier
  • Transaction Digest: Proof of deployment
  • Gas Used: Deployment cost

Step 7: Interact with Contract

Create Greeting

# Call create_greeting function
sui client call \
--package <PACKAGE_ID> \
--module hello_world \
--function create_greeting \
--args 'Hello from Sui Workshop!' \
--gas-budget 10000000

Expected Output:

╭─────────────────────────────────────────────────────────────╮
│ Transaction Summary │
├─────────────────────────────────────────────────────────────┤
│ Transaction Digest: 5x8K...9mN2 │
│ Status: Success │
│ Gas Cost: 1,234,567 MIST │
╰─────────────────────────────────────────────────────────────╯

╭─────────────────────────────────────────────────────────────╮
│ Created Objects │
├─────────────────────────────────────────────────────────────┤
│ ObjectID: 0xabc123...def456 │
│ Version: 1 │
│ Owner: 0x742d035a21bf1c1c8b2d8c92 │
│ ObjectType: hello_sui::hello_world::Greeting │
╰─────────────────────────────────────────────────────────────╯

Check Greeting Object

# View greeting object details
sui client object <GREETING_OBJECT_ID>

# List all objects owned by your active address
sui client objects

# Filter only Greeting objects (replace <PACKAGE_ID>)
sui client objects --filter StructType --struct-type '<PACKAGE_ID>::hello_world::Greeting'

View Greeting Message

# Read-only call to get the message
sui client call \
--package <PACKAGE_ID> \
--module hello_world \
--function get_message \
--args <GREETING_OBJECT_ID> \
--gas-budget 1000000

Update Greeting Message

# Update message (hanya creator yang bisa)
# Only the creator can update; note two args: object id + new message
sui client call \
--package <PACKAGE_ID> \
--module hello_world \
--function update_message \
--args <GREETING_OBJECT_ID> 'Updated message from workshop!' \
--gas-budget 5000000

Create Multiple Greetings

# For a friend
sui client call \
--package <PACKAGE_ID> \
--module hello_world \
--function create_greeting \
--args 'Selamat belajar Sui blockchain!' \
--gas-budget 10000000

# In English
sui client call \
--package <PACKAGE_ID> \
--module hello_world \
--function create_greeting \
--args 'Welcome to Sui development!' \
--gas-budget 10000000

Check Transaction History

# Detail specific transaction
sui client transaction <TRANSACTION_DIGEST>

🔍 Exploring Sui Explorer (15 menit)

  1. Visit: https://suiscan.xyz/testnet
  2. Search your Transaction Digest
  3. Explore:
    • Transaction details
    • Objects created/modified
    • Events emitted
    • Gas usage breakdown

Understanding Transaction Structure

{
"digest": "0x742d...8c92",
"transaction": {
"data": {
"messageVersion": "v1",
"transaction": {
"kind": "ProgrammableTransaction",
"inputs": [...],
"transactions": [...]
}
}
},
"effects": {
"status": { "status": "success" },
"gasUsed": {...},
"created": [...],
"mutated": [...]
}
}

Key Components:

  • Inputs: Function arguments dan object references
  • Commands: Operations to execute
  • Effects: State changes yang terjadi
  • Gas: Computational cost breakdown

🎯 Module Wrap-up (15 menit)

Key Takeaways

  1. Sui's Unique Architecture:

    • Object-centric model enables parallel execution
    • Move language provides resource safety
    • Sub-second finality untuk simple transactions
  2. Development Workflow:

    • sui move newsui move buildsui client publish
    • Testnet untuk development, mainnet untuk production
    • CLI tools untuk interaction dan debugging
  3. Object Model Mastery:

    • Every state adalah object dengan UID
    • Ownership determines access control
    • Version tracking untuk consistency

Common Gotchas

Forgetting gas budget: Always specify sufficient gas
Wrong network: Make sure using testnet untuk learning
Missing dependencies: Verify Move.toml configuration
Address confusion: CLI vs wallet addresses

Quick Knowledge Check

  1. What makes Sui different from Ethereum?
  2. What are the three object ownership types?
  3. How do you deploy a Move contract?
  4. Where can you view transaction details?

🎯 Excellent! You've mastered Sui basics.

👉 Continue to Module 2: Move Language Basics →


Next up: Deep dive into Move programming language dan build more sophisticated contracts.