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:
- Memahami Foundry - Mengapa Foundry adalah toolkit modern untuk smart contract development
- Setup Development Environment - Install Foundry di Windows & Mac, setup project dari scratch
- Write Smart Contracts - Membuat contract dengan best practices menggunakan analogi dunia nyata
- Unit Testing - Menulis comprehensive tests dalam Solidity (bukan JavaScript!)
- Gas Optimization - Teknik optimasi gas fee dengan measurement yang akurat
- Deployment - Deploy ke testnet dengan script yang reusable
๐ Jadwal Workshopโ
| Waktu | Durasi | Aktivitas | Format |
|---|---|---|---|
| 08:30 - 09:00 | 30m | Registrasi & Setup Environment | Persiapan |
| 09:00 - 09:15 | 15m | Intro: Foundry vs Hardhat & Why Foundry? | Pembukaan |
| 09:15 - 10:45 | 90m | Module 1: Instalasi & First Project | Setup + Hands-on |
| 10:45 - 11:00 | 15m | Istirahat | Break |
| 11:00 - 12:30 | 90m | Module 2: Smart Contract Development | Hands-on |
| 12:30 - 13:30 | 60m | Istirahat Makan Siang | Lunch |
| 13:30 - 15:00 | 90m | Module 3: Unit Testing & Fuzzing | Hands-on |
| 15:00 - 15:15 | 15m | Istirahat | Break |
| 15:15 - 16:45 | 90m | Module 4: Gas Optimization & Deployment | Hands-on |
| 16:45 - 17:00 | 15m | Best Practices & Closing | Wrap-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โ
| Feature | Foundry | Hardhat |
|---|---|---|
| Language | Solidity (testing juga!) | JavaScript/TypeScript |
| Speed | โกโกโก SUPER FAST | ๐ข Slower |
| Testing | Solidity (.t.sol) | JavaScript/TypeScript |
| Fuzzing | โ Built-in | โ Perlu plugin |
| Gas Reports | โ Super akurat | โ ๏ธ Kurang detail |
| Learning Curve | Moderate (1 language) | Easy (JS familiar) |
| Dependencies | Rust binary (no npm!) | Node.js + 100+ packages |
| Use Case | Protocol dev, auditing | Quick 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:
- Lisk Sepolia Faucet: https://sepolia-faucet.lisk.com
- Gratis! Request 0.05 ETH per hari
Add to MetaMask:
- Buka MetaMask
- Klik Networks โ Add Network
- Add Network Manually
- Masukkan details di atas
- Save & Switch
๐ Ready to Start?โ
Mari kita mulai perjalanan menjadi Foundry expert!
Struktur workshop:
- ๐ง Install Foundry - Setup development environment
- ๐๏ธ Build Contract - Create SimpleBank dengan real-world logic
- ๐งช Write Tests - Comprehensive testing including fuzzing
- โก Optimize Gas - Reduce gas costs dengan proven techniques
- ๐ Deploy - Launch to testnet & verify
๐ Part 1: Instalasi Foundry โ
๐ Support & Resourcesโ
Jika mengalami masalah:
- Tanya instruktur di workshop
- Check Telegram group: Kelas Rutin Batch IV
- Foundry Discord: https://discord.gg/foundry
- GitHub Issues: https://github.com/foundry-rs/foundry
Learning Resources:
- Foundry Book - Official documentation
- Foundry Examples
- Solidity by Example
- Smart Contract Security Best Practices
Community:
- Foundry Discord (very active!)
- Ethereum Jakarta Telegram
- #FoundryFriday on Twitter
Let's forge ahead! โ๏ธ๐ฅ
#BuildWithFoundry | #EthereumJakarta | #Web3Indonesia