Home > Blog > tech

Blockchain Development คืออะไร? สอนเขียน Smart Contract และ DApp สำหรับ Developer มือใหม่ 2026

blockchain development beginners guide
Blockchain Development Beginners Guide 2026
2026-04-10 | tech | 3500 words

Blockchain ไม่ได้เป็นเรื่องของนักลงทุนหรือ Trader เท่านั้น สำหรับ Developer แล้ว Blockchain คือ Platform ที่เปิดโอกาสให้สร้างแอปพลิเคชันที่ Trustless และ Decentralized ซึ่งเป็นสิ่งที่ระบบ Traditional ทำไม่ได้ ตั้งแต่ DeFi (Decentralized Finance) จนถึง NFT Marketplace, DAO (Decentralized Autonomous Organization) และ Supply Chain Tracking ล้วนสร้างบน Smart Contract ทั้งสิ้น

บทความนี้เขียนสำหรับ Developer ที่มีพื้นฐานการเขียนโปรแกรมอยู่แล้ว (ไม่จำเป็นต้องรู้ Blockchain มาก่อน) จะพาเรียนรู้ตั้งแต่พื้นฐานของ Blockchain, การเขียน Smart Contract ด้วย Solidity, การใช้เครื่องมือพัฒนา (Hardhat, Foundry), การสร้าง DApp ด้วย ethers.js จนถึง ERC Standards และ Security Best Practices

Blockchain Fundamentals สำหรับ Developer

Blockchain คือ Distributed Ledger ที่เก็บข้อมูลแบบ Immutable ข้อมูลจัดเก็บเป็น Blocks เชื่อมต่อกันเป็น Chain แต่ละ Block มี Hash ของ Block ก่อนหน้า ทำให้แก้ไขข้อมูลย้อนหลังไม่ได้โดยไม่ทำลาย Chain ทั้งหมด สิ่งที่ทำให้ Blockchain พิเศษสำหรับ Developer คือ Smart Contract ซึ่งเป็นโปรแกรมที่ Deploy บน Blockchain และทำงานตาม Logic ที่กำหนดโดยอัตโนมัติ ไม่มีใครแก้ไขหรือหยุดได้หลัง Deploy

Block Structure

แต่ละ Block ประกอบด้วย Block Header (Timestamp, Previous Hash, Nonce, Merkle Root) และ Block Body (รายการ Transactions ทั้งหมดใน Block นั้น) Transactions คือการเปลี่ยนแปลง State บน Blockchain ไม่ว่าจะเป็นการโอนเงิน การเรียก Function ของ Smart Contract หรือการ Deploy Contract ใหม่ ทุก Transaction ต้องได้รับการ Verify จาก Network ก่อนจึงจะถูกบันทึกใน Block

Consensus Mechanisms — กลไกฉันทามติ

Consensus Mechanism คือวิธีที่ Nodes ในเครือข่ายตกลงกันว่า State ปัจจุบันของ Blockchain คืออะไร เป็นหัวใจสำคัญที่ทำให้ระบบ Decentralized ทำงานได้โดยไม่ต้องมีตัวกลาง

Proof of Work (PoW)

PoW เป็นกลไกดั้งเดิมที่ Bitcoin ใช้ Miners ต้องใช้พลังงานคำนวณเพื่อหา Nonce ที่ทำให้ Hash ของ Block ตรงตามเงื่อนไข (เช่น ขึ้นต้นด้วย 0 กี่ตัว) กระบวนการนี้ยากและใช้เวลานาน แต่ตรวจสอบง่าย ข้อเสียคือใช้พลังงานมหาศาลและ Transaction Speed ช้า

Proof of Stake (PoS)

PoS เป็นกลไกที่ Ethereum ใช้ปัจจุบัน (ตั้งแต่ The Merge ปี 2022) Validators ต้อง Stake ETH เป็นหลักประกัน และได้รับเลือกให้สร้าง Block ตามสัดส่วนที่ Stake ถ้าทำไม่ซื่อสัตย์จะถูก Slash (ยึด ETH ที่ Stake) PoS ใช้พลังงานน้อยกว่า PoW มาก (ลดลง 99.95%) และรองรับ Transaction ได้มากกว่า

Delegated Proof of Stake (DPoS)

DPoS ใช้โดยเครือข่ายอย่าง EOS และ TRON ผู้ถือ Token เลือก Delegates ให้เป็น Block Producers แทนตัวเอง ทำให้ Transaction Speed สูงมาก แต่ Decentralization น้อยกว่า PoS เพราะมี Block Producers จำนวนจำกัด

Ethereum Basics — รากฐานของ Smart Contract

Ethereum เป็น Blockchain ที่นิยมที่สุดสำหรับ Smart Contract Development มี Ecosystem ที่ใหญ่ที่สุด ทั้ง Tools, Libraries, Community และ Documentation

EVM — Ethereum Virtual Machine

EVM เป็น Runtime Environment ที่รัน Smart Contract ทำงานเหมือน Sandboxed Virtual Machine ที่ทุก Node ในเครือข่ายรันพร้อมกัน Code ที่เขียนด้วย Solidity จะถูก Compile เป็น Bytecode แล้วรันบน EVM EVM เป็น Stack-based Machine ที่มี Memory, Storage และ Calldata เป็นส่วนประกอบหลัก ความสำคัญของ EVM คือทำให้ Smart Contract ทำงานเหมือนกันทุก Node ไม่ว่าจะเป็น Hardware หรือ OS ใดก็ตาม

Gas — ค่าธรรมเนียมการทำงาน

ทุก Operation บน EVM มีค่า Gas ที่ต้องจ่าย Gas เป็นกลไกที่ป้องกัน Infinite Loops และ DDoS Attack ผู้ใช้ต้องกำหนด Gas Limit (จำนวน Gas สูงสุดที่ยอมจ่าย) และ Gas Price (ราคาต่อ Gas Unit เป็น Gwei) ค่า Gas จริงที่จ่าย = Gas Used x Gas Price ตัวอย่างเช่น Simple ETH Transfer ใช้ 21,000 Gas ส่วน Complex Smart Contract Interaction อาจใช้ 100,000-500,000 Gas การเขียน Code ที่ Gas-efficient จึงเป็นทักษะสำคัญของ Blockchain Developer

Accounts — ประเภทบัญชี

Ethereum มี 2 ประเภทบัญชี คือ EOA (Externally Owned Account) ที่ควบคุมด้วย Private Key คือบัญชีของผู้ใช้ทั่วไป สร้าง Transaction ได้ และ Contract Account ที่ควบคุมด้วย Code คือ Smart Contract ที่ Deploy แล้ว ไม่สามารถสร้าง Transaction เองได้ แต่สามารถเรียก Contract อื่นได้เมื่อถูกเรียกจาก EOA

Solidity Language Basics — พื้นฐาน Solidity

Solidity เป็นภาษาหลักสำหรับเขียน Smart Contract บน Ethereum และ EVM-compatible chains ทั้งหมด Syntax คล้าย JavaScript แต่มีลักษณะเฉพาะของ Blockchain เช่น Gas optimization, Storage vs Memory, Payable functions

โครงสร้างพื้นฐาน

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

contract SimpleStorage {
    // State Variables — เก็บบน Blockchain (เสีย Gas เยอะ)
    uint256 public storedNumber;
    address public owner;
    string public name;
    bool public isActive;

    // Mapping — key-value store
    mapping(address => uint256) public balances;
    mapping(address => mapping(address => uint256)) public allowances;

    // Array
    address[] public users;

    // Struct
    struct User {
        string name;
        uint256 balance;
        bool isRegistered;
    }
    mapping(address => User) public userProfiles;

    // Events — log ที่อ่านจาก Frontend ได้
    event NumberUpdated(uint256 oldValue, uint256 newValue, address updatedBy);
    event UserRegistered(address indexed user, string name);

    // Modifiers — เงื่อนไขที่ใช้ซ้ำได้
    modifier onlyOwner() {
        require(msg.sender == owner, "Not the owner");
        _;
    }

    modifier whenActive() {
        require(isActive, "Contract is paused");
        _;
    }

    // Constructor — รันครั้งเดียวตอน Deploy
    constructor(string memory _name) {
        owner = msg.sender;
        name = _name;
        isActive = true;
    }

    // Functions
    function setNumber(uint256 _number) public whenActive {
        uint256 oldNumber = storedNumber;
        storedNumber = _number;
        emit NumberUpdated(oldNumber, _number, msg.sender);
    }

    function register(string memory _name) public {
        require(!userProfiles[msg.sender].isRegistered, "Already registered");
        userProfiles[msg.sender] = User(_name, 0, true);
        users.push(msg.sender);
        emit UserRegistered(msg.sender, _name);
    }

    // Payable — รับ ETH ได้
    function deposit() public payable {
        require(msg.value > 0, "Must send ETH");
        balances[msg.sender] += msg.value;
    }

    // View function — อ่านข้อมูลฟรี (ไม่เสีย Gas)
    function getBalance(address _user) public view returns (uint256) {
        return balances[_user];
    }

    // Only owner can withdraw
    function withdraw() public onlyOwner {
        uint256 amount = address(this).balance;
        (bool success, ) = payable(owner).call{value: amount}("");
        require(success, "Transfer failed");
    }

    // Pause/Unpause
    function toggleActive() public onlyOwner {
        isActive = !isActive;
    }
}
Storage vs Memory vs Calldata: storage เก็บถาวรบน Blockchain (แพงที่สุด), memory เก็บชั่วคราวระหว่าง Function call (ถูกกว่า), calldata เก็บ Input data ที่ไม่สามารถแก้ไขได้ (ถูกที่สุด สำหรับ external function parameters)

Development Tools — เครื่องมือพัฒนา

Hardhat — JavaScript/TypeScript Framework

# สร้างโปรเจกต์ Hardhat
mkdir my-dapp && cd my-dapp
npm init -y
npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox

# Initialize Hardhat project
npx hardhat init
# เลือก "Create a TypeScript project"

# โครงสร้างโปรเจกต์
# contracts/      — Solidity files
# scripts/        — Deploy scripts
# test/           — Test files
# hardhat.config.ts — Configuration
// hardhat.config.ts
import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";

const config: HardhatUserConfig = {
  solidity: {
    version: "0.8.24",
    settings: {
      optimizer: { enabled: true, runs: 200 },
    },
  },
  networks: {
    sepolia: {
      url: process.env.SEPOLIA_RPC_URL || "",
      accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : [],
    },
    hardhat: {
      // Local development network
    },
  },
};

export default config;

Foundry — Rust-based Framework (เร็วกว่ามาก)

# ติดตั้ง Foundry
curl -L https://foundry.paradigm.xyz | bash
foundryup

# สร้างโปรเจกต์
forge init my-dapp
cd my-dapp

# โครงสร้างโปรเจกต์
# src/       — Solidity contracts
# test/      — Solidity test files
# script/    — Deploy scripts
# lib/       — Dependencies

# Compile
forge build

# Test (เร็วมาก)
forge test -vvv

Remix — IDE ในเบราว์เซอร์

Remix IDE (remix.ethereum.org) เป็น Web IDE ที่ใช้เขียนและทดสอบ Smart Contract ได้ทันทีโดยไม่ต้องติดตั้งอะไร เหมาะสำหรับการเรียนรู้และ Prototype แต่ไม่เหมาะสำหรับโปรเจกต์จริงที่ต้องการ Version Control และ CI/CD Pipeline

Deploying First Smart Contract

// scripts/deploy.ts (Hardhat)
import { ethers } from "hardhat";

async function main() {
  const [deployer] = await ethers.getSigners();
  console.log("Deploying with:", deployer.address);
  console.log("Balance:", ethers.formatEther(
    await ethers.provider.getBalance(deployer.address)
  ));

  // Deploy contract
  const SimpleStorage = await ethers.getContractFactory("SimpleStorage");
  const contract = await SimpleStorage.deploy("MyStorage");
  await contract.waitForDeployment();

  const address = await contract.getAddress();
  console.log("Contract deployed to:", address);

  // Verify on Etherscan (optional)
  if (network.name !== "hardhat") {
    console.log("Waiting for block confirmations...");
    await contract.deploymentTransaction()?.wait(5);
    await run("verify:verify", {
      address: address,
      constructorArguments: ["MyStorage"],
    });
  }
}

main().catch(console.error);
# Deploy to local network
npx hardhat node                    # เปิด local node
npx hardhat run scripts/deploy.ts --network localhost

# Deploy to Sepolia testnet
npx hardhat run scripts/deploy.ts --network sepolia

Testing Smart Contracts

Hardhat Tests (TypeScript)

// test/SimpleStorage.test.ts
import { expect } from "chai";
import { ethers } from "hardhat";
import { loadFixture } from "@nomicfoundation/hardhat-toolbox/network-helpers";

describe("SimpleStorage", function () {
  async function deployFixture() {
    const [owner, user1, user2] = await ethers.getSigners();
    const SimpleStorage = await ethers.getContractFactory("SimpleStorage");
    const contract = await SimpleStorage.deploy("TestStorage");
    return { contract, owner, user1, user2 };
  }

  describe("Deployment", function () {
    it("Should set the right owner", async function () {
      const { contract, owner } = await loadFixture(deployFixture);
      expect(await contract.owner()).to.equal(owner.address);
    });

    it("Should set the right name", async function () {
      const { contract } = await loadFixture(deployFixture);
      expect(await contract.name()).to.equal("TestStorage");
    });
  });

  describe("setNumber", function () {
    it("Should update the number", async function () {
      const { contract } = await loadFixture(deployFixture);
      await contract.setNumber(42);
      expect(await contract.storedNumber()).to.equal(42);
    });

    it("Should emit NumberUpdated event", async function () {
      const { contract, owner } = await loadFixture(deployFixture);
      await expect(contract.setNumber(42))
        .to.emit(contract, "NumberUpdated")
        .withArgs(0, 42, owner.address);
    });

    it("Should revert when paused", async function () {
      const { contract } = await loadFixture(deployFixture);
      await contract.toggleActive();
      await expect(contract.setNumber(42))
        .to.be.revertedWith("Contract is paused");
    });
  });

  describe("deposit", function () {
    it("Should accept ETH", async function () {
      const { contract, user1 } = await loadFixture(deployFixture);
      const amount = ethers.parseEther("1.0");
      await contract.connect(user1).deposit({ value: amount });
      expect(await contract.getBalance(user1.address)).to.equal(amount);
    });

    it("Should revert with 0 ETH", async function () {
      const { contract } = await loadFixture(deployFixture);
      await expect(contract.deposit({ value: 0 }))
        .to.be.revertedWith("Must send ETH");
    });
  });
});

Foundry Fuzz Testing

// test/SimpleStorage.t.sol (Foundry)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import "forge-std/Test.sol";
import "../src/SimpleStorage.sol";

contract SimpleStorageTest is Test {
    SimpleStorage public store;
    address public owner;
    address public user1;

    function setUp() public {
        owner = address(this);
        user1 = makeAddr("user1");
        store = new SimpleStorage("TestStorage");
    }

    function test_SetNumber() public {
        store.setNumber(42);
        assertEq(store.storedNumber(), 42);
    }

    // Fuzz Test — Foundry จะสุ่มค่า _number มาทดสอบหลายร้อยครั้ง
    function testFuzz_SetNumber(uint256 _number) public {
        store.setNumber(_number);
        assertEq(store.storedNumber(), _number);
    }

    function test_RevertWhenPaused() public {
        store.toggleActive();
        vm.expectRevert("Contract is paused");
        store.setNumber(42);
    }

    function test_Deposit() public {
        vm.deal(user1, 10 ether);
        vm.prank(user1);
        store.deposit{value: 1 ether}();
        assertEq(store.getBalance(user1), 1 ether);
    }

    // Fuzz test for deposit
    function testFuzz_Deposit(uint256 _amount) public {
        _amount = bound(_amount, 1, 100 ether);
        vm.deal(user1, _amount);
        vm.prank(user1);
        store.deposit{value: _amount}();
        assertEq(store.getBalance(user1), _amount);
    }
}
Fuzz Testing สำคัญมาก: Smart Contract เมื่อ Deploy แล้วแก้ไขไม่ได้ Fuzz Testing ช่วยค้นหา Edge Cases ที่อาจเป็นช่องโหว่ด้านความปลอดภัย Foundry สามารถรัน Fuzz Test หลายพันรอบใน milliseconds ใช้เวลาเขียนเพิ่มแค่นิดเดียวแต่ได้ความมั่นใจมาก

Frontend Integration — สร้าง DApp

DApp (Decentralized Application) ประกอบด้วย Smart Contract บน Blockchain เป็น Backend และ Web Frontend ที่เชื่อมต่อกับ Contract ผ่าน Library เช่น ethers.js หรือ viem สำหรับนักพัฒนาที่มีพื้นฐาน React หรือ Next.js การสร้าง DApp Frontend จะคุ้นเคยมาก

ethers.js — Library มาตรฐาน

// ethers.js v6 — Connect to contract
import { ethers } from "ethers";

// Connect to provider
const provider = new ethers.BrowserProvider(window.ethereum);

// Request account access
const signer = await provider.getSigner();
const userAddress = await signer.getAddress();

// Connect to contract
const contractAddress = "0x1234...";
const abi = [
  "function storedNumber() view returns (uint256)",
  "function setNumber(uint256 _number)",
  "function deposit() payable",
  "function getBalance(address) view returns (uint256)",
  "event NumberUpdated(uint256 oldValue, uint256 newValue, address updatedBy)",
];

const contract = new ethers.Contract(contractAddress, abi, signer);

// Read data (free, no gas)
const number = await contract.storedNumber();
console.log("Stored number:", number.toString());

// Write data (costs gas)
const tx = await contract.setNumber(42);
console.log("Transaction hash:", tx.hash);
const receipt = await tx.wait(); // Wait for confirmation
console.log("Confirmed in block:", receipt.blockNumber);

// Send ETH
const depositTx = await contract.deposit({
  value: ethers.parseEther("0.1")
});
await depositTx.wait();

// Listen to events
contract.on("NumberUpdated", (oldVal, newVal, updatedBy) => {
  console.log(`Number changed from ${oldVal} to ${newVal} by ${updatedBy}`);
});

wagmi + viem — Modern React Hooks

// wagmi v2 — React Hooks สำหรับ Blockchain
import { useAccount, useConnect, useReadContract, useWriteContract } from 'wagmi';
import { parseEther } from 'viem';

function App() {
  // Connect wallet
  const { address, isConnected } = useAccount();
  const { connect, connectors } = useConnect();

  // Read contract
  const { data: storedNumber } = useReadContract({
    address: '0x1234...',
    abi: contractABI,
    functionName: 'storedNumber',
  });

  // Write contract
  const { writeContract, isPending } = useWriteContract();

  const handleSetNumber = () => {
    writeContract({
      address: '0x1234...',
      abi: contractABI,
      functionName: 'setNumber',
      args: [42n],
    });
  };

  return (
    <div>
      {!isConnected ? (
        <button onClick={() => connect({ connector: connectors[0] })}>
          Connect Wallet
        </button>
      ) : (
        <div>
          <p>Connected: {address}</p>
          <p>Stored Number: {storedNumber?.toString()}</p>
          <button onClick={handleSetNumber} disabled={isPending}>
            Set Number to 42
          </button>
        </div>
      )}
    </div>
  );
}

Wallet Connection — MetaMask และ WalletConnect

Wallet เป็นประตูหลักที่ผู้ใช้เข้าถึง DApp ทุก DApp ต้องรองรับการเชื่อมต่อ Wallet MetaMask เป็น Browser Extension Wallet ที่นิยมที่สุด ส่วน WalletConnect เป็น Protocol ที่เชื่อมต่อกับ Mobile Wallets ได้

// ConnectKit หรือ RainbowKit — UI สำเร็จรูปสำหรับ Wallet Connection
// ใช้ RainbowKit เป็นตัวอย่าง
npm install @rainbow-me/rainbowkit wagmi viem @tanstack/react-query

// App.tsx
import { RainbowKitProvider, ConnectButton } from '@rainbow-me/rainbowkit';
import { WagmiProvider } from 'wagmi';
import { QueryClientProvider, QueryClient } from '@tanstack/react-query';
import { config } from './wagmi-config';

const queryClient = new QueryClient();

function App() {
  return (
    <WagmiProvider config={config}>
      <QueryClientProvider client={queryClient}>
        <RainbowKitProvider>
          <ConnectButton />
          {/* DApp content */}
        </RainbowKitProvider>
      </QueryClientProvider>
    </WagmiProvider>
  );
}

ERC Standards — มาตรฐาน Token

ERC-20 — Fungible Token

ERC-20 เป็นมาตรฐาน Token ที่ใช้กันมากที่สุด ทุก Token มีค่าเท่ากัน (Fungible) เช่น USDT, LINK, UNI ฟังก์ชันหลักคือ transfer, approve, transferFrom, balanceOf, totalSupply

// ERC-20 Token ด้วย OpenZeppelin
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract MyToken is ERC20, Ownable {
    constructor() ERC20("My Token", "MTK") Ownable(msg.sender) {
        // Mint 1,000,000 tokens ให้ deployer
        _mint(msg.sender, 1_000_000 * 10 ** decimals());
    }

    function mint(address to, uint256 amount) public onlyOwner {
        _mint(to, amount);
    }
}

ERC-721 — Non-Fungible Token (NFT)

ERC-721 เป็นมาตรฐาน NFT ที่แต่ละ Token มีเอกลักษณ์เฉพาะตัว (Non-Fungible) ใช้สำหรับ Digital Art, Gaming Items, Certificates ฟังก์ชันหลักคือ ownerOf, transferFrom, approve, tokenURI

// ERC-721 NFT ด้วย OpenZeppelin
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract MyNFT is ERC721URIStorage, Ownable {
    uint256 private _nextTokenId;

    constructor() ERC721("My NFT", "MNFT") Ownable(msg.sender) {}

    function mint(address to, string memory uri) public onlyOwner returns (uint256) {
        uint256 tokenId = _nextTokenId++;
        _safeMint(to, tokenId);
        _setTokenURI(tokenId, uri);
        return tokenId;
    }
}

ERC-1155 — Multi Token Standard

ERC-1155 รวม ERC-20 และ ERC-721 เข้าด้วยกันในสัญญาเดียว สามารถจัดการทั้ง Fungible และ Non-Fungible Tokens ในคราวเดียว ประหยัด Gas มาก เหมาะสำหรับ Gaming ที่มี Items หลายประเภท เช่น Gold Coins (Fungible) และ Unique Weapons (Non-Fungible) อยู่ในสัญญาเดียวกัน

Security — ความปลอดภัยของ Smart Contract

Smart Contract Security สำคัญมากเพราะเมื่อ Deploy แล้วแก้ไขไม่ได้ และมีเงินจริงอยู่ใน Contract Bug เดียวอาจทำให้สูญเสียเงินหลายล้านดอลลาร์ นี่คือช่องโหว่ที่พบบ่อยที่สุด

Reentrancy Attack

Reentrancy เป็นช่องโหว่ที่อันตรายที่สุด เกิดจากการที่ Contract เรียก External Contract ก่อนอัปเดต State ทำให้ Attacker สามารถเรียกกลับเข้ามาซ้ำก่อนที่ State จะเปลี่ยน (เหตุการณ์ DAO Hack 2016 สูญเสีย $60M)

// ไม่ปลอดภัย — Reentrancy Vulnerable
function withdraw() public {
    uint256 amount = balances[msg.sender];
    (bool success, ) = msg.sender.call{value: amount}(""); // External call BEFORE state update
    require(success);
    balances[msg.sender] = 0; // State update AFTER external call
}

// ปลอดภัย — Checks-Effects-Interactions Pattern
function withdraw() public {
    uint256 amount = balances[msg.sender];
    require(amount > 0, "No balance");
    balances[msg.sender] = 0; // State update FIRST
    (bool success, ) = msg.sender.call{value: amount}(""); // External call LAST
    require(success, "Transfer failed");
}

// หรือใช้ OpenZeppelin ReentrancyGuard
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";

contract Secure is ReentrancyGuard {
    function withdraw() public nonReentrant {
        // Protected from reentrancy
    }
}

Integer Overflow/Underflow

ใน Solidity เวอร์ชันก่อน 0.8.0 การคำนวณที่เกินขอบเขตของ Integer จะ Wrap around โดยไม่ Error เช่น uint8(255) + 1 = 0 ตั้งแต่ Solidity 0.8.0 มี Built-in overflow/underflow check แล้ว ถ้าเกิดจะ Revert อัตโนมัติ

Access Control

ทุก Function ที่เปลี่ยน State สำคัญต้องมี Access Control ใช้ OpenZeppelin AccessControl หรือ Ownable เพื่อจำกัดสิทธิ์การเรียกใช้ อย่าลืมตรวจสอบว่า msg.sender มีสิทธิ์ทำ Action นั้นจริง

OpenZeppelin Contracts — Library มาตรฐานอุตสาหกรรม

OpenZeppelin เป็น Library ที่ผ่านการ Audit แล้ว มี Smart Contract Templates สำเร็จรูปที่ปลอดภัย ใช้เป็นพื้นฐานสำหรับโปรเจกต์ทั้งหมด ประกอบด้วย Token Standards (ERC-20, ERC-721, ERC-1155), Access Control (Ownable, AccessControl, TimelockController), Security (ReentrancyGuard, Pausable, PullPayment), Governance (Governor, TimelockController) และ Utilities (Counters, Strings, Address, Math)

# ติดตั้ง OpenZeppelin
npm install @openzeppelin/contracts

# หรือ Foundry
forge install OpenZeppelin/openzeppelin-contracts

Layer 2 Development — พัฒนาบน L2

Layer 2 Solutions ช่วยแก้ปัญหา Scalability ของ Ethereum ทำให้ Transaction ถูกลงและเร็วขึ้นมาก ในขณะที่ยัง inherit security จาก Ethereum mainnet

Optimism และ Base

Optimism ใช้ Optimistic Rollups สมมติว่า Transaction ถูกต้องก่อน แล้วค่อยท้าทาย (Challenge) ภายหลังถ้าไม่ถูก Base สร้างโดย Coinbase บน Optimism Stack (OP Stack) เหมาะสำหรับ Consumer-facing DApps ทั้งสองใช้ Solidity และ EVM เหมือนกัน Developer แทบไม่ต้องเปลี่ยน Code แค่เปลี่ยน RPC URL ในการ Deploy

Arbitrum

Arbitrum ใช้ Optimistic Rollups เช่นกัน แต่มี Fraud Proof mechanism ที่แตกต่าง มี Ecosystem ที่ใหญ่ที่สุดใน L2 (TVL สูงสุด) รองรับ Stylus ที่ให้เขียน Smart Contract ด้วย Rust, C++ นอกเหนือจาก Solidity

// Deploy ไป L2 — แค่เปลี่ยน Network Config
// hardhat.config.ts
networks: {
  optimism: {
    url: "https://mainnet.optimism.io",
    accounts: [process.env.PRIVATE_KEY],
  },
  base: {
    url: "https://mainnet.base.org",
    accounts: [process.env.PRIVATE_KEY],
  },
  arbitrum: {
    url: "https://arb1.arbitrum.io/rpc",
    accounts: [process.env.PRIVATE_KEY],
  },
}

// Deploy
// npx hardhat run scripts/deploy.ts --network base

Alternative Chains — Blockchain อื่นนอกจาก EVM

Solana — High Performance Blockchain

Solana ใช้ Proof of History (PoH) + PoS ทำ Transaction ได้ 65,000 TPS (เทียบกับ Ethereum ที่ 30 TPS) ค่า Gas ถูกมาก (ต่ำกว่า $0.01) Smart Contract เขียนด้วย Rust ใช้ Anchor Framework ช่วยง่ายขึ้น Programming model แตกต่างจาก EVM มาก เพราะแยก Logic กับ State ออกจากกัน (Program vs Account model)

TON — The Open Network

TON สร้างโดย Telegram มี Integration กับ Telegram Mini Apps ทำให้เข้าถึงผู้ใช้ 900+ ล้านคนได้ Smart Contract เขียนด้วย FunC หรือ Tact (ภาษาใหม่ที่ง่ายกว่า) ใช้ Actor Model ที่แตกต่างจาก EVM มี Sharding ในตัวทำให้ Scale ได้ดีมาก

Blockchain Developer Career Path

Blockchain Development เป็นสายอาชีพที่ต้องการสูงมากในปี 2026 เงินเดือนเฉลี่ยสูงกว่า Traditional Development อย่างมาก เส้นทางการเติบโตมีดังนี้

เส้นทางจาก Beginner สู่ Expert

  1. Foundation (1-3 เดือน): เข้าใจ Blockchain fundamentals, เขียน Solidity พื้นฐาน, ใช้ Hardhat/Foundry Deploy Contract, เข้าใจ ERC Standards พื้นฐาน
  2. Intermediate (3-6 เดือน): เขียน Complex Smart Contracts ได้, เข้าใจ Security patterns, สร้าง DApp frontend ด้วย ethers.js/wagmi, Deploy บน Testnet และ Mainnet ได้
  3. Advanced (6-12 เดือน): ออกแบบ Smart Contract Architecture ที่ซับซ้อน, Gas Optimization, Upgradeable Contracts (Proxy Patterns), Protocol Design (DeFi, DAO, NFT Marketplace), การทำ Testing ที่ครอบคลุม
  4. Expert (12+ เดือน): Smart Contract Auditing, Protocol Security Research, Cross-chain Development, Zero-knowledge Proofs, Contribute to Core Protocol

ทักษะที่ต้องมี

ทักษะระดับรายละเอียด
Solidityจำเป็นภาษาหลักสำหรับ EVM chains
JavaScript/TypeScriptจำเป็นสำหรับ Testing, Scripting, Frontend
Reactสำคัญสำหรับ DApp Frontend
Rustเสริมสำหรับ Solana, Substrate, Foundry
SecurityสำคัญมากSmart Contract Audit, Common Vulnerabilities
DeFi KnowledgeเสริมAMM, Lending, Yield Farming protocols
Distributed SystemsเสริมConsensus, P2P Networking

Thai Blockchain Ecosystem

ประเทศไทยมี Blockchain ecosystem ที่เติบโตอย่างต่อเนื่อง ทั้งในด้าน Regulation และ Development

Regulation

สำนักงาน ก.ล.ต. (SEC Thailand) กำกับดูแล Digital Asset Business ทั้ง Exchange, Broker, Dealer, ICO Portal และ DeFi ที่ให้บริการในประเทศไทย Developer ที่สร้างผลิตภัณฑ์ที่เกี่ยวข้องกับ Digital Assets ต้องเข้าใจกฎหมายเหล่านี้ โดยเฉพาะ พ.ร.ก. การประกอบธุรกิจสินทรัพย์ดิจิทัล พ.ศ. 2561

โอกาสสำหรับ Developer ไทย

สรุปและขั้นตอนเริ่มต้น

Blockchain Development เป็นสาขาที่ท้าทายแต่ให้ผลตอบแทนสูง สิ่งที่ทำให้แตกต่างจาก Traditional Development คือความสำคัญของ Security (เพราะ Code เกี่ยวข้องกับเงินจริง) และความ Immutable ของ Smart Contract (Deploy แล้วแก้ไม่ได้) จึงต้องรอบคอบมากกว่า

เริ่มต้นวันนี้ด้วยขั้นตอนง่ายๆ เปิด Remix IDE (remix.ethereum.org) เขียน Smart Contract แรก Deploy บน Sepolia Testnet (ขอ Test ETH จาก Faucet) สร้าง Frontend ด้วย React + ethers.js แล้วเชื่อมต่อกับ Contract ของคุณ เรียนรู้ ERC Standards (ERC-20, ERC-721) สร้าง Token แรกของคุณ

สำหรับ Developer ที่สนใจสร้าง DApp ที่สมบูรณ์ การมีพื้นฐาน TypeScript จะช่วยมากในการเขียน Test Scripts และ Frontend รวมถึงการเข้าใจ Web Security ที่จะช่วยให้คิดเรื่อง Smart Contract Security ได้อย่างเป็นระบบมากขึ้น และการติดตาม Analytics จะช่วยให้เข้าใจว่าผู้ใช้ Interact กับ DApp ของคุณอย่างไร


Back to Blog | iCafe Forex | SiamLanCard | Siam2R