0Pricing
Web3 & DApp Development Fundamentals · บทเรียน

การนำไปใช้งานและการโต้ตอบ

ฝึกนำสัญญาอัจฉริยะที่คอมไพล์แล้วไปใช้งานบนสภาพแวดล้อมบล็อกเชนจำลอง และโต้ตอบกับฟังก์ชันของสัญญาผ่านส่วนติดต่อผู้ใช้ Remix

การนำไปใช้งานและการโต้ตอบ เป็นบทเรียน Web3 & DApp Development Fundamentals ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 3 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Web3 & DApp Development Fundamentals และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Web3 & DApp Development Fundamentals มีบทเรียนทั้งหมด 3 บทเรียน

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

What is Smart Contract Deployment?

You've learned to write and compile smart contracts in Remix. The next step is to deploy them.

Deploying a contract means publishing its compiled code onto a blockchain. Once deployed, your contract becomes an immutable, self-executing program accessible to anyone on that network.

Remix's Deploy & Run Panel

Remix IDE has a dedicated panel for deployment and interaction. Look for the 'Deploy & Run transactions' plugin, usually represented by an Ethereum logo.

This panel allows you to:

  • Select a blockchain environment.
  • Choose an account for deployment.
  • Deploy your compiled contracts.
  • Interact with deployed contracts.

Choosing a Blockchain Environment

Before deploying, you need to tell Remix which blockchain to target. In the 'Environment' dropdown, you'll see options:

  • JavaScript VM: A local, in-browser simulated blockchain. Perfect for testing!
  • Injected Provider: Connects to an external wallet like MetaMask.
  • Web3 Provider: Connects to a custom RPC endpoint (e.g., a local Hardhat node).

For this lesson, we'll use the JavaScript VM.

Test Accounts in JavaScript VM

When you select 'JavaScript VM', Remix automatically provides several test accounts. These accounts are pre-funded with fake Ether (ETH).

You'll use one of these accounts to deploy your contract. The deployment transaction will deduct 'gas' (transaction fees) from the chosen account's balance, just like on a real blockchain.

Gas Limit and Value

In the 'Deploy & Run' panel, you'll also see fields for 'Gas limit' and 'Value'.

  • Gas limit: The maximum amount of gas (computational effort) you're willing to spend on a transaction.
  • Value: The amount of Ether (or other native token) you want to send along with the transaction (e.g., for payable functions or sending funds to a contract).

For most simple deployments, the default gas limit is sufficient. We'll leave 'Value' at 0 for now.

Our Simple Counter Contract

Let's use a basic Counter contract to practice deployment and interaction. This contract simply stores an unsigned integer and allows us to increment or decrement it.

Copy and paste this code into a new file named Counter.sol in Remix, then compile it.

pragma solidity ^0.8.0;

contract Counter {
    uint public count;

    constructor() {
        count = 0;
    }

    function increment() public {
        count++;
    }

    function decrement() public {
        count--;
    }
}

Deploying the Counter Contract

With Counter.sol compiled and 'JavaScript VM' selected:

  1. Ensure Counter is selected in the 'CONTRACT' dropdown.
  2. Click the orange 'Deploy' button.

You'll see a transaction recorded in the Remix terminal, and your deployed contract will appear under 'Deployed Contracts'.

Interacting with Deployed Contracts

Once deployed, your contract will show up under the 'Deployed Contracts' section in the 'Deploy & Run' panel.

You'll see buttons for each of the contract's functions and public state variables. These buttons are color-coded:

  • Blue: View/pure functions (read-only, no transaction cost).
  • Orange: Non-payable functions (modify state, require transaction).
  • Red: Payable functions (modify state and accept Ether).

Reading Contract State: 'count'

Our Counter contract has a public state variable called count. When a state variable is declared public, Solidity automatically creates a getter function for it.

Click the blue 'count' button in the deployed contract interface. You should see its initial value, 0, displayed below the button.

Modifying Contract State: 'increment()'

Now, let's change the contract's state. Click the orange 'increment' button.

This will trigger a transaction. You'll see a new transaction in the terminal. After it's mined (almost instantly in JS VM), click the blue 'count' button again. The value should now be 1!

Try clicking 'decrement' and observing the change too.

Quick Check: Remix Deployment

Which of the following best describes the primary purpose of the 'JavaScript VM' environment in Remix?

Recap: Deploying & Interacting

Congratulations! You've learned the essential steps to deploy and interact with smart contracts using Remix IDE:

  • Used the 'Deploy & Run transactions' panel.
  • Selected the 'JavaScript VM' for a simulated environment.
  • Deployed a simple Counter contract.
  • Interacted with its public variable and functions to read and modify its state.

This hands-on experience is crucial for understanding how smart contracts live and operate on the blockchain!

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

บทเรียน “การนำไปใช้งานและการโต้ตอบ” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การนำไปใช้งานและการโต้ตอบ” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Web3 & DApp Development Fundamentals ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Web3 & DApp Development Fundamentals มีบทเรียนทั้งหมด 3 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “การนำไปใช้งานและการโต้ตอบ”

ฝึกนำสัญญาอัจฉริยะที่คอมไพล์แล้วไปใช้งานบนสภาพแวดล้อมบล็อกเชนจำลอง และโต้ตอบกับฟังก์ชันของสัญญาผ่านส่วนติดต่อผู้ใช้ Remix คุณปฏิบัติ Web3 & DApp Development Fundamentals ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Web3 & DApp Development Fundamentals หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Web3 & DApp Development Fundamentals บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 3 บทเรียน

บทเรียน “การนำไปใช้งานและการโต้ตอบ” ใช้เวลานานแค่ไหน

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

ฉันเขียนและรันโค้ดในบทเรียน Web3 & DApp Development Fundamentals นี้ได้ไหม

ได้ บทเรียน Web3 & DApp Development Fundamentals ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

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

  1. ภาพรวม Remix IDE
  2. การคอมไพล์สัญญาอัจฉริยะ
  3. การนำไปใช้งานและการโต้ตอบ
← กลับไปที่ Web3 & DApp Development Fundamentals