Ethereum & Smart Contracts
Ethereum bukan sekadar cryptocurrency — ini adalah programmable blockchain. Kamu bisa menulis kode (smart contract) yang berjalan di atas blockchain, dieksekusi oleh ribuan node secara bersamaan.
Ethereum Virtual Machine (EVM)
EVM adalah "komputer global" yang menjalankan smart contract. Setiap node Ethereum menjalankan EVM yang sama, memastikan semua orang mendapat hasil yang sama (deterministic).
// Smart contract di-compile menjadi EVM bytecode
// Solidity → compile → bytecode → deploy ke blockchain
// Setiap node menjalankan bytecode yang sama
// Contoh flow:
// 1. Developer menulis Solidity
// 2. Compiler menghasilkan bytecode + ABI
// 3. Bytecode di-deploy ke address tertentu
// 4. Siapa pun bisa memanggil fungsi via ABI
Tipe Akun di Ethereum
| Aspek | EOA (Externally Owned Account) | Contract Account |
|---|---|---|
| Dikendalikan oleh | Private key (manusia) | Kode (smart contract) |
| Bisa inisiasi transaksi? | Ya | Tidak (hanya merespon) |
| Punya kode? | Tidak | Ya (immutable) |
| Contoh | Wallet MetaMask kamu | Uniswap Router contract |
Gas: Biaya Komputasi
Setiap operasi di EVM membutuhkan gas. Gas mencegah infinite loops dan spam. Kamu membayar gas dalam ETH.
// Gas calculation:
// Total biaya = gas_used × gas_price
// Contoh (post EIP-1559):
// Base fee: 20 gwei
// Priority fee (tip): 2 gwei
// Gas used: 21000 (simple transfer)
// Total = 21000 × (20 + 2) gwei = 462000 gwei = 0.000462 ETH
// Gas limits per operasi:
// Simple ETH transfer: ~21,000 gas
// ERC-20 transfer: ~65,000 gas
// Uniswap swap: ~150,000 gas
// NFT mint: ~100,000 - 200,000 gas
Smart Contract = Kode yang Tidak Bisa Diubah
Setelah di-deploy, kode smart contract immutable (tidak bisa diubah). Inilah mengapa audit keamanan sangat penting sebelum deploy.
- Trustless — Tidak perlu percaya siapa pun, percaya kode
- Transparent — Siapa pun bisa membaca kode di blockchain
- Composable — Contract bisa memanggil contract lain (money legos)
Testnet vs Mainnet
- Mainnet — Jaringan utama Ethereum (real money)
- Sepolia — Testnet utama untuk development (free test ETH)
- Local — Hardhat/Anvil node untuk development cepat