Struktur Project Truffle
Penjelasan
Struktur project Truffle terdiri dari empat bagian utama: `contracts/` berisi source code Solidity, `migrations/` berisi file JavaScript bernomor yang mendefinisikan urutan deployment, `test/` berisi test (bisa JavaScript maupun Solidity), dan `truffle-config.js` sebagai pusat konfigurasi network, compiler, dan plugin. Hal yang membedakan Truffle dari toolchain lain adalah konsep migration sebagai warga kelas satu (first-class citizen) dalam struktur project — bukan sekadar script deployment biasa, melainkan sistem bernomor urut yang Truffle lacak status eksekusinya per network lewat contract Migrations.sol.
Contoh Konsep
// truffle-config.js
module.exports = {
networks: {
development: {
host: "127.0.0.1",
port: 7545,
network_id: "*",
},
},
compilers: {
solc: {
version: "0.8.20",
},
},
};
// Struktur folder:
// hello_truffle/
// ├── truffle-config.js
// ├── contracts/Migrations.sol
// ├── migrations/1_initial_migration.js
// └── test/
Praktikum
Buka truffle-config.js hasil init, lalu tambahkan konfigurasi versi compiler solc menjadi 0.8.20 dengan optimizer aktif 200 runs.
Ketik/edit bebas di sini untuk latihan — kode ini tidak dijalankan.
Tips
Port default Ganache GUI adalah 7545, sementara Ganache CLI (ganache-cli/ganache) defaultnya 8545 — samakan dengan port di truffle-config.js atau koneksi akan gagal.