0Pricing
Blockchain Smart Contracts with Solidity · บทเรียน

สัญญา Solidity แรกของคุณ

เขียนและคอมไพล์สัญญาอัจฉริยะ 'Hello World' อย่างง่ายด้วย Remix IDE เพื่อฝึกใช้ไวยากรณ์ของ Solidity

สัญญา Solidity แรกของคุณ เป็นบทเรียน Blockchain Smart Contracts with Solidity ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Blockchain Smart Contracts with Solidity และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Blockchain Smart Contracts with Solidity มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Your First Smart Contract!

Time to write your first smart contract! We'll build a simple Hello World in Solidity using the browser-based Remix IDE - no setup needed.

Meet Remix IDE

Remix IDE lets you write, compile, debug, and deploy Solidity contracts right in your browser. It's perfect for learning and quick prototyping.

Solidity Version Pragma

Every Solidity file opens with a pragma that pins the compiler version. The code below means versions 0.8.0 up to (but not including) 0.9.0 are allowed.

pragma solidity ^0.8.0;

Defining Your Contract

Solidity code lives inside a contract, much like a class in OOP. You declare it with the contract keyword, a name, and curly braces, as shown.

contract MyFirstContract {
  // Your contract's code goes here
}

Adding a State Variable

A state variable is stored permanently on chain and defines your contract's state. Here we add a string called greeting; public makes it readable by anyone.

contract MyFirstContract {
  string public greeting;
}

The Constructor Function

The constructor runs exactly once, at deployment, to initialize state. Here it sets greeting to "Hello CoddyKit!" the moment the contract goes live.

contract MyFirstContract {
  string public greeting;

  constructor() {
    greeting = "Hello CoddyKit!";
  }
}

Writing a View Function

A view function reads contract state without changing it. This getGreeting is public and returns a string from memory, as shown below.

contract MyFirstContract {
  string public greeting;

  constructor() {
    greeting = "Hello CoddyKit!";
  }

  function getGreeting() public view returns (string memory) {
    return greeting;
  }
}

Our Full 'Hello World' Contract

Here's the full Hello World contract. Paste it into Remix, compile, deploy to a test chain, then call getGreeting() to see it work.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract SimpleGreeting {
  string public greeting;

  constructor() {
    greeting = "Hello CoddyKit!";
  }

  function getGreeting() public view returns (string memory) {
    return greeting;
  }
}

Compiling Your Contract

Before deploying, a contract must be compiled - turning your Solidity into EVM bytecode. Remix has a built-in compiler with a handy Auto compile option.

Quick Check: Contract Structure

Which part of a Solidity smart contract specifies the minimum compatible compiler version?

Recap: Your First Contract

Recap: you built a Solidity contract with a pragma, a contract block, a state variable, a constructor, and a view function - all in Remix. Nice work!

คำถามที่พบบ่อย

บทเรียน “สัญญา Solidity แรกของคุณ” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “สัญญา Solidity แรกของคุณ” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Blockchain Smart Contracts with Solidity ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Blockchain Smart Contracts with Solidity มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “สัญญา Solidity แรกของคุณ”

เขียนและคอมไพล์สัญญาอัจฉริยะ 'Hello World' อย่างง่ายด้วย Remix IDE เพื่อฝึกใช้ไวยากรณ์ของ Solidity คุณปฏิบัติ Blockchain Smart Contracts with Solidity ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Blockchain Smart Contracts with Solidity หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Blockchain Smart Contracts with Solidity บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน

บทเรียน “สัญญา Solidity แรกของคุณ” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Blockchain Smart Contracts with Solidity นี้ได้ไหม

ได้ บทเรียน Blockchain Smart Contracts with Solidity ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. เทคโนโลยีบล็อกเชนคืออะไร
  2. พื้นฐาน Ethereum และ EVM
  3. สัญญา Solidity แรกของคุณ
  4. กระเป๋า คีย์ และธุรกรรม
← กลับไปที่ Blockchain Smart Contracts with Solidity