Skip to main content

Sesi 6: Foundry Testing, Gas Optimization, Deployment

๐Ÿ“‹ Informasi Sesiโ€‹

Tanggal: Sabtu, TBD Waktu: 09:00 - 17:00 WIB (8 jam) Lokasi: Jura Kemanggisan Format: Workshop tatap muka (offline) Peserta: 40-80 pengembang Level: Intermediate - Smart Contract Development & Testing


๐ŸŽฏ Tujuan Pembelajaranโ€‹

Setelah menyelesaikan sesi ini, Anda akan mampu:

  1. Memahami Foundry - Mengapa Foundry adalah toolkit modern untuk smart contract development
  2. Setup Development Environment - Install Foundry di Windows & Mac, setup project dari scratch
  3. Write Smart Contracts - Membuat contract dengan best practices menggunakan analogi dunia nyata
  4. Unit Testing - Menulis comprehensive tests dalam Solidity (bukan JavaScript!)
  5. Gas Optimization - Teknik optimasi gas fee dengan measurement yang akurat
  6. Deployment - Deploy ke testnet dengan script yang reusable

๐Ÿ“… Jadwal Workshopโ€‹

WaktuDurasiAktivitasFormat
08:30 - 09:0030mRegistrasi & Setup EnvironmentPersiapan
09:00 - 09:1515mIntro: Foundry vs Hardhat & Why Foundry?Pembukaan
09:15 - 10:4590mModule 1: Instalasi & First ProjectSetup + Hands-on
10:45 - 11:0015mIstirahatBreak
11:00 - 12:3090mModule 2: Smart Contract DevelopmentHands-on
12:30 - 13:3060mIstirahat Makan SiangLunch
13:30 - 15:0090mModule 3: Unit Testing & FuzzingHands-on
15:00 - 15:1515mIstirahatBreak
15:15 - 16:4590mModule 4: Gas Optimization & DeploymentHands-on
16:45 - 17:0015mBest Practices & ClosingWrap-up

๐Ÿš€ Prerequisitesโ€‹

Yang Harus Sudah Dipahami:โ€‹

โœ… Solidity Basics:

  • Tipe data (uint, string, address, bool)
  • Struct, mapping, array
  • Functions, modifiers, events
  • Basic contract structure

โœ… Command Line:

  • Familiar dengan terminal/command prompt
  • Navigasi folder (cd, ls/dir)
  • Basic git commands

Tools yang Dibutuhkan:โ€‹

โœ… Development Tools:

  • VS Code atau code editor pilihan
  • Git untuk version control
  • Terminal/PowerShell (sudah built-in di OS)

โœ… Blockchain Tools:

  • MetaMask wallet extension
  • Lisk Sepolia ETH dari faucet untuk testing

๐Ÿ’ก TIDAK PERLU Node.js! - Foundry adalah Rust-based, tidak butuh npm/node!


๐Ÿ“š Struktur Dokumentasiโ€‹

Dokumentasi ini dibagi menjadi 4 bagian yang fokus pada SimpleBank smart contract dari awal sampai production:

๐Ÿ“– Part 1: Instalasi Foundryโ€‹

Module 1 (09:15 - 10:45)

  • Apa itu Foundry? Kenapa menggunakan Foundry?
  • Instalasi di Windows (PowerShell + WSL)
  • Instalasi di Mac (homebrew)
  • Setup VS Code extensions
  • Project pertama: forge init
  • Struktur project & basic commands

๐Ÿ“– Part 2: Membuat SimpleBank Smart Contractโ€‹

Module 2 (11:00 - 12:30)

  • Analogi dunia nyata: Membangun sistem Bank
  • Membuat SimpleBank contract dengan fitur:
    • Deposit ETH
    • Withdraw ETH
    • Transfer antar user
  • Implementasi events & custom errors
  • Security patterns (CEI, reentrancy protection)
  • Compile & verifikasi ukuran contract

๐Ÿ“– Part 3: Testing SimpleBank Contractโ€‹

Module 3 (13:30 - 15:00)

  • Filosofi testing: Mengapa test penting?
  • Menulis tests untuk SimpleBank:
    • Test deposit function
    • Test withdraw function
    • Test transfer function
  • Fuzz testing untuk edge cases
  • Mengukur test coverage
  • Testing best practices

๐Ÿ“– Part 4: Optimasi & Deployment SimpleBankโ€‹

Module 4 (15:15 - 16:45)

  • Gas optimization untuk SimpleBank
  • Membandingkan versi before/after optimization
  • Gas snapshot & comparison
  • Deploy SimpleBank ke Lisk Sepolia
  • Verifikasi contract di Blockscout
  • Production deployment checklist

๐ŸŽฏ Apa Itu Foundry?โ€‹

Analogi: Foundry vs Hardhatโ€‹

Bayangkan Anda sedang membangun rumah:

Hardhat (JavaScript-based):

๐Ÿ—๏ธ Seperti menggunakan arsitektur + kontraktor terpisah
- Arsitektur (Solidity) pakai bahasa berbeda dari kontraktor (JavaScript)
- Butuh interpreter untuk terjemahkan (Node.js)
- Testing pakai bahasa lain (Mocha/Chai)
- Lebih lambat karena ada translation layer

Foundry (All Solidity):

โšก Seperti arsitek yang juga kontraktor
- Semua pakai bahasa yang sama (Solidity)
- Tidak butuh interpreter (langsung Rust binary)
- Testing juga di Solidity (1 bahasa!)
- SUPER CEPAT karena native Rust

Kenapa Foundry Populer di 2024-2025?โ€‹

Speed:

  • โšก 10-100x lebih cepat dari Hardhat untuk testing
  • Compile dalam hitungan detik, bukan menit

Developer Experience:

  • ๐ŸŽฏ 1 bahasa untuk semua (Solidity)
  • Test ditulis di Solidity, tidak perlu switch context
  • Fuzzing built-in untuk find edge cases

Gas Optimization:

  • ๐Ÿ“Š Gas reports otomatis & akurat
  • Gas snapshot untuk track optimization
  • Forge inspect untuk analyze bytecode

Production Ready:

  • ๐Ÿ”ฅ Digunakan oleh protokol besar (Uniswap, Aave, Compound)
  • Battle-tested di billions of dollars TVL
  • Active development & community

๐Ÿ› ๏ธ Tech Stackโ€‹

Foundry Suite:โ€‹

  • forge - Build, test, deploy smart contracts
  • cast - Interact dengan contracts & RPC
  • anvil - Local Ethereum node (seperti Hardhat node)
  • chisel - Solidity REPL untuk coba code cepat

Development Tools:โ€‹

  • Solidity ^0.8.30 - Smart contract language
  • VS Code - Code editor
  • soldeer - Package manager (alternatif npm untuk Solidity)

Deployment:โ€‹

  • Lisk Sepolia Testnet - Testing deployment
  • Blockscout - Contract verification & block explorer

๐Ÿ’ก Foundry vs Hardhat: Quick Comparisonโ€‹

FeatureFoundryHardhat
LanguageSolidity (testing juga!)JavaScript/TypeScript
Speedโšกโšกโšก SUPER FAST๐Ÿข Slower
TestingSolidity (.t.sol)JavaScript/TypeScript
Fuzzingโœ… Built-inโŒ Perlu plugin
Gas Reportsโœ… Super akuratโš ๏ธ Kurang detail
Learning CurveModerate (1 language)Easy (JS familiar)
DependenciesRust binary (no npm!)Node.js + 100+ packages
Use CaseProtocol dev, auditingQuick prototypes, familiar JS devs

Kapan Pakai Foundry?

  • โœ… Building production protocols
  • โœ… Need accurate gas reports
  • โœ… Want fast test iterations
  • โœ… Security-critical contracts

Kapan Pakai Hardhat?

  • โœ… Frontend integration (JS ecosystem)
  • โœ… Quick hackathon projects
  • โœ… Team sudah familiar dengan JS
  • โœ… Need extensive plugin ecosystem

Ideal: Pakai Keduanya! ๐ŸŽฏ

  • Foundry untuk testing & optimization
  • Hardhat untuk deployment & frontend integration

๐Ÿ“– Cara Menggunakan Dokumentasiโ€‹

Alur Pembelajaran (Linear SimpleBank Journey):โ€‹

Part 1: Setup Foundation โ†’ Install Foundry & setup project

Part 2: Build SimpleBank โ†’ Menulis smart contract SimpleBank dengan:

  • Function deposit, withdraw, transfer
  • Events & custom errors
  • Security patterns

Part 3: Test SimpleBank โ†’ Menulis tests untuk SimpleBank:

  • Test semua functions
  • Fuzz testing untuk edge cases
  • Measure test coverage

Part 4: Optimize & Deploy โ†’ Mengoptimasi SimpleBank:

  • Gas optimization techniques
  • Deploy ke Lisk Sepolia
  • Verifikasi di Blockscout

Tips Belajar:โ€‹

  • โœ… Ikuti urutan Part 1 โ†’ 2 โ†’ 3 โ†’ 4 - Jangan skip atau loncat-loncat
  • โœ… Praktek setiap command - Jangan hanya baca, ketik sendiri!
  • โœ… Pahami error messages - Foundry memberikan error message yang jelas
  • โœ… Fokus pada SimpleBank - Satu contract dipelajari secara mendalam
  • โœ… Test sebelum optimize - Pastikan contract bekerja benar dulu

Troubleshooting:โ€‹

  • Error di Windows? Gunakan WSL atau Git Bash
  • forge: command not found? Restart terminal setelah instalasi
  • Test gagal? Baca error message dan trace dengan -vvvv
  • Gas tinggi? Lihat Part 4 untuk optimization techniques

๐ŸŽฎ Project Yang Akan Dibangunโ€‹

SimpleBank Contract - Bank sederhana dengan real-world features:

Core Features:โ€‹

  • ๐Ÿ’ฐ Deposit ETH - Simpan uang ke bank
  • ๐Ÿ’ธ Withdraw - Tarik uang (dengan validasi saldo)
  • ๐Ÿ”„ Transfer - Kirim uang ke user lain
  • ๐Ÿ“Š Balance Tracking - Track saldo setiap user
  • ๐Ÿ”’ Access Control - Only owner can certain actions
  • ๐Ÿ“ˆ Events - Log semua transaksi

Security Features:โ€‹

  • โœ… Reentrancy protection
  • โœ… Overflow protection (Solidity ^0.8.0)
  • โœ… Access control checks
  • โœ… Input validation

Testing Coverage:โ€‹

  • โœ… Happy path tests
  • โœ… Failure cases
  • โœ… Edge cases with fuzzing
  • โœ… Gas optimization tests

Analogi Dunia Nyata:โ€‹

SimpleBank = Bank digital seperti BCA/Mandiri mobile

Deposit = Transfer uang ke rekening
Withdraw = Tarik tunai di ATM
Transfer = Transfer antar rekening
Balance = Cek saldo
Events = Mutasi rekening

Bedanya: Semua on-chain & transparent! ๐Ÿ”—

๐ŸŽฏ Learning Outcomesโ€‹

Setelah selesai workshop ini, Anda akan:

โœ… Memahami:

  • Foundry architecture & workflow
  • Solidity testing best practices
  • Gas optimization techniques
  • Smart contract security patterns
  • Professional development workflow

โœ… Bisa Membuat:

  • Foundry project dari scratch
  • Comprehensive test suites dalam Solidity
  • Gas-optimized contracts
  • Deployment scripts yang reusable
  • Verified contracts di Blockscout

โœ… Siap Untuk:

  • Contribute to DeFi protocols
  • Smart contract auditing career
  • Build production-grade contracts
  • Participate in audit contests (Code4rena, Sherlock)

๐Ÿ“ Important Notesโ€‹

System Requirements:โ€‹

Windows:

  • Windows 10/11 (64-bit)
  • PowerShell atau WSL2 (recommended)
  • ~500MB disk space

Mac:

  • macOS 10.15 (Catalina) atau lebih baru
  • Homebrew package manager
  • ~500MB disk space

Linux:

  • Ubuntu 20.04+ atau equivalent
  • ~500MB disk space

Persiapan Sebelum Workshop:โ€‹

1 Hari Sebelum Workshop:

  • Install Git (jika belum punya)
  • Pastikan MetaMask sudah setup
  • Dapatkan Lisk Sepolia ETH dari faucet
  • Download VS Code (optional tapi recommended)

Pagi Hari Workshop:

  • Charge laptop full battery
  • Bawa charger (venue ada power outlet)
  • Bawa notebook untuk catatan
  • Install Foundry (atau ikuti step saat workshop)

Lisk Sepolia Network Info:โ€‹

Network Details:

Network Name: Lisk Sepolia Testnet
Chain ID: 4202
RPC URL: https://rpc.sepolia-api.lisk.com
Currency Symbol: ETH
Block Explorer: https://sepolia-blockscout.lisk.com

Faucet:

Add to MetaMask:

  1. Buka MetaMask
  2. Klik Networks โ†’ Add Network
  3. Add Network Manually
  4. Masukkan details di atas
  5. Save & Switch

๐Ÿš€ Ready to Start?โ€‹

Mari kita mulai perjalanan menjadi Foundry expert!

Struktur workshop:

  1. ๐Ÿ”ง Install Foundry - Setup development environment
  2. ๐Ÿ—๏ธ Build Contract - Create SimpleBank dengan real-world logic
  3. ๐Ÿงช Write Tests - Comprehensive testing including fuzzing
  4. โšก Optimize Gas - Reduce gas costs dengan proven techniques
  5. ๐Ÿš€ Deploy - Launch to testnet & verify

๐Ÿ“– Part 1: Instalasi Foundry โ†’


๐Ÿ“ž Support & Resourcesโ€‹

Jika mengalami masalah:

Learning Resources:

Community:

  • Foundry Discord (very active!)
  • Ethereum Jakarta Telegram
  • #FoundryFriday on Twitter

Let's forge ahead! โš’๏ธ๐Ÿ”ฅ

#BuildWithFoundry | #EthereumJakarta | #Web3Indonesia