Pengantar Solidity
Dapatkan ikhtisar sintaks dan struktur Solidity serta deklarasi kontrak dasar, termasuk kata kunci pragma dan contract.
Pengantar Solidity adalah pelajaran Web3 & DApp Development Fundamentals gratis di CoddyKit. Ini adalah pelajaran 1 dari 3. Kamu bisa membaca pelajaran lengkapnya di bawah secara gratis — lalu praktikkan langsung di browser dengan editor kode bawaan dan tutor AI 24/7. Ini adalah bagian dari jalur belajar Web3 & DApp Development Fundamentals, dan progresmu tersinkronisasi di web dan aplikasi CoddyKit. Kursus Web3 & DApp Development Fundamentals mencakup 3 pelajaran total.
Bagian dari pelajaran ini belum diterjemahkan dan ditampilkan dalam bahasa Inggris.
Meet Solidity: Language of Smart Contracts
Welcome to Solidity! It's the primary language for writing smart contracts on blockchain platforms like Ethereum.
Think of smart contracts as self-executing agreements stored on a blockchain. Learning Solidity opens the door to building decentralized applications (DApps).
Why Solidity Matters
Solidity is a high-level, object-oriented language. It's specifically designed to implement business logic for DApps.
It enables you to create digital tokens, build decentralized finance (DeFi) protocols, and manage digital assets securely on a blockchain.
Your First Solidity File
Every Solidity smart contract lives in a file ending with the .sol extension.
- Just like a
.jsfile for JavaScript. - Or a
.pyfile for Python. - The first line of a Solidity file often defines the compiler version to be used.
The Pragma Directive
The pragma directive is crucial. It tells the Solidity compiler which version to use for your contract.
For example, pragma solidity ^0.8.0; means "use any compiler version from 0.8.0 up to, but not including, 0.9.0."
This ensures your contract compiles predictably and avoids unexpected behavior from future compiler changes.
Declaring a Contract
In Solidity, the fundamental building block for your smart contract is the contract keyword.
- It's similar to a "class" in object-oriented programming languages.
- Your entire smart contract's logic, including variables and functions, will live inside a
contractblock.
Our First Basic Contract
Let's put pragma and contract together. This is the most basic, yet complete, Solidity contract you can write.
It doesn't do much yet, but it's ready to be compiled and deployed!
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract MyFirstContract {
// This contract is currently empty!
}Comments in Solidity
Comments help explain your code to others and your future self. They are ignored by the compiler.
- Single-line comments start with
//. - Multi-line comments are enclosed by
/*and*/. - The
SPDX-License-Identifieris a special comment used to specify the contract's license.
Contract Name & Structure
Contract names usually start with an uppercase letter, following common programming conventions (e.g., MyFirstContract).
The code inside the curly braces {} defines the contract's logic. This is where you'll add state variables, functions, and events as you learn more.
Quick Check: Pragma Purpose
The pragma solidity ^0.8.0; line is essential for smart contract development. What is its primary role?
Recap: Your Solidity Journey Begins!
You've learned the very basics of Solidity!
- We covered the
.solfile extension. - The critical
pragmadirective for compiler versions. - The fundamental
contractkeyword. - How to add comments for code clarity.
Next, we'll dive deeper into variables and data types!
Pertanyaan yang Sering Diajukan
Apakah pelajaran “Pengantar Solidity” gratis?
Ya — teks lengkap “Pengantar Solidity” gratis dibaca di sini di web. Untuk praktiknya secara interaktif (editor kode bawaan dan tutor AI 24/7) dan buka sisa kursus Web3 & DApp Development Fundamentals, upgrade ke CoddyKit PRO. Kursus Web3 & DApp Development Fundamentals mencakup 3 pelajaran total.
Apa yang akan aku pelajari di “Pengantar Solidity”?
Dapatkan ikhtisar sintaks dan struktur Solidity serta deklarasi kontrak dasar, termasuk kata kunci pragma dan contract. Kamu berlatih Web3 & DApp Development Fundamentals dengan kode praktik yang langsung kamu jalankan di browser, dan tutor AI 24/7 menjawab pertanyaanmu saat kamu mengerjakan pelajaran ini.
Apakah aku perlu pengalaman untuk memulai Web3 & DApp Development Fundamentals?
Tidak diperlukan pengalaman sebelumnya. Web3 & DApp Development Fundamentals di CoddyKit dirancang untuk pemula hingga pelajar tingkat lanjut, jadi kamu bisa memulai di sini atau dari awal dan belajar sesuai kecepatan kamu sendiri. Ini adalah pelajaran 1 dari 3.
Berapa lama pelajaran “Pengantar Solidity” memakan waktu?
Sebagian besar pelajaran CoddyKit memakan waktu sekitar 5–10 menit. Setiap pelajaran ringkas dan interaktif, jadi kamu membuat kemajuan stabil dan melanjutkan dari tempat kamu tinggalkan di web dan aplikasi.
Bisakah aku menulis dan menjalankan kode dalam pelajaran Web3 & DApp Development Fundamentals ini?
Ya. Setiap pelajaran Web3 & DApp Development Fundamentals menyertakan editor kode bawaan, jadi kamu menulis dan menjalankan kode nyata langsung di browser dan mendapatkan umpan balik AI instan — tidak diperlukan penyiapan lokal.
Semua pelajaran dalam kursus ini
- Pengantar Solidity
- Variabel dan Tipe Data
- Fungsi dan Struktur Kontrol