บทนำสู่ Solidity
ทำความรู้จักไวยากรณ์ โครงสร้าง และการประกาศสัญญาเบื้องต้นของ Solidity รวมถึงคีย์เวิร์ด pragma และ contract
บทนำสู่ Solidity เป็นบทเรียน Web3 & DApp Development Fundamentals ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 3 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Web3 & DApp Development Fundamentals และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Web3 & DApp Development Fundamentals มีบทเรียนทั้งหมด 3 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
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!
คำถามที่พบบ่อย
บทเรียน “บทนำสู่ Solidity” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “บทนำสู่ Solidity” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Web3 & DApp Development Fundamentals ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Web3 & DApp Development Fundamentals มีบทเรียนทั้งหมด 3 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “บทนำสู่ Solidity”
ทำความรู้จักไวยากรณ์ โครงสร้าง และการประกาศสัญญาเบื้องต้นของ Solidity รวมถึงคีย์เวิร์ด pragma และ contract คุณปฏิบัติ Web3 & DApp Development Fundamentals ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Web3 & DApp Development Fundamentals หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Web3 & DApp Development Fundamentals บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 3 บทเรียน
บทเรียน “บทนำสู่ Solidity” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Web3 & DApp Development Fundamentals นี้ได้ไหม
ได้ บทเรียน Web3 & DApp Development Fundamentals ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- บทนำสู่ Solidity
- ตัวแปรและชนิดข้อมูล
- ฟังก์ชันและโครงสร้างควบคุม