Home>Articles>100 Days of Blockchain: Day 3 — Smart Contract
Published :19 December 2025
blockchain

100 Days of Blockchain: Day 3 — Smart Contract

instagram

100 Days of Blockchain: Day 3 — Smart Contract

Press enter or click to view image in full size
Photo by Shubham Dhage on Unsplash

အားလုံးပဲ မင်္ဂလာပါ။ ဒီနေ့ကတော့ “100 Days of Blockchain” ရဲ့ Day 3 (၃ ရက်မြောက်နေ့) ဖြစ်ပါတယ်။ ဒီနေ့မှာတော့ Blockchain Development ရဲ့ အသက်ဖြစ်တဲ့ Smart Contracts တွေကို ရှင်းပြပေးသွားမှာ ဖြစ်ပါတယ်။ Smart Contract တွေ ဘယ်လိုအလုပ်လုပ်လဲဆိုတာကို နားလည်လွယ်အောင် ကျွန်တော်တို့အားလုံး ရင်းနှီးပြီးသားဖြစ်တဲ့ ကော်ဖီအရောင်းစက် (Vending Machine) လေးနဲ့ ဥပမာပေးပြီး ပြောပြသွားပါမယ်။

The Vending Machine Analogy (အရောင်းစက် သဘောတရား)

Smart Contract တွေအကြောင်း မပြောခင် Vending Machine တစ်ခု ဘယ်လိုအလုပ်လုပ်လဲဆိုတာကို အရင်ကြည့်ကြည့်ရအောင်။ သူက “Finite State Machine” လို့ခေါ်တဲ့ ယန္တရားအတိုင်း အဆင့် ၄ ဆင့်နဲ့ အလုပ်လုပ်ပါတယ်

  1. State 1 (Selection): ကိုယ်သောက်ချင်တဲ့ ကော်ဖီကို ရွေးမယ်။
  2. State 2 (Payment): သတ်မှတ်ထားတဲ့ ဈေးနှုန်းအတိုင်း ပိုက်ဆံထည့်မယ်။
  3. State 3 (Verification): စက်က ပိုက်ဆံပြည့်မပြည့်နဲ့ ပစ္စည်း Stock ရှိမရှိ စစ်ဆေး (Verify) မယ်။
  4. State 4 (Execution): အားလုံးမှန်ကန်တယ်ဆိုရင် ကော်ဖီထုတ်ပေးမယ်။ မှားနေရင် (ဥပမာ — ပိုက်ဆံမလောက်ရင်) မူလ State 1 ကို ပြန်ရောက်သွားမယ်။

Smart Contract ဆိုတာကလည်း ဒီ Logic အတိုင်း အလုပ်လုပ်တဲ့ Blockchain ပေါ်က Computer Program (Software) တစ်ခုပါပဲ။

Solidity နဲ့ ရေးသားခြင်း

Ethereum Blockchain ပေါ်မှာဆိုရင် Smart Contract တွေရေးဖို့အတွက် Solidity ဆိုတဲ့ Programming Language ကို အဓိက သုံးကြပါတယ်။ သူက Java လိုမျိုး Object-Oriented Language တွေနဲ့ Concept ဆင်တူပြီး၊ Class အစား Contract တွေကို အခြေခံတဲ့ “Contract-Oriented” Language တစ်ခုဖြစ်ပါတယ်။

Vending Machine တစ်ခုကို Solidity (version 0.8.20) နဲ့ ရေးမယ်ဆိုရင် အကြမ်းဖျင်း ဒီလိုပုံစံလေး ဖြစ်ပါလိမ့်မယ် -

Get Lynn The Light’s stories in your inbox

Join Medium for free to get updates from this writer.

Solidity

contract VendingMachine {
// State Variables (ဆိုင်ရဲ့ ဒေတာများ)
uint public price = 0.01 ether; // ဈေးနှုန်း
uint public stock = 100; // ပစ္စည်းအရေအတွက်
// ကော်ဖီဝယ်မယ့် Function
function buy() external payable {
// 1. ပိုက်ဆံလောက်မလောက် စစ်မယ်
require(msg.value >= price, "Not enough Ether");

// 2. ပစ္စည်းကျန်မကျန် စစ်မယ်
require(stock > 0, "Out of stock");
// 3. ပစ္စည်းထုတ်ပေးမယ် (stock ကို ၁ လျှော့မယ်)
stock -= 1;
}
}

The “Mind-Blowing” Shift: Web2 vs. Web3

ဒီအပိုင်းကတော့ Traditional Developer (Web2 သမား) တွေအတွက် Concept အပြောင်းအလဲ (Paradigm Shift) ဖြစ်သွားမယ့် အပိုင်းပါ။

Web2 Development (ဥပမာ Node.js သုံးတာမျိုး) မှာဆိုရင် Logic တွေ၊ Database တွေက Server တစ်လုံးတည်း (Centralized Server) ပေါ်မှာပဲ ရှိပါတယ်။ အဲ့ဒီ Server ပျက်သွားရင် ဒါမှမဟုတ် ဖျက်လိုက်ရင် Data တွေအကုန်ပျက်သွားမှာပါ။

Web3 မှာကျတော့ ကျွန်တော်တို့ရေးလိုက်တဲ့ VendingMachine Contract ကို Deploy လုပ်လိုက်တာနဲ့ သူက Server တစ်လုံးတည်းမှာ ရှိနေတာ မဟုတ်ပါဘူး။ Ethereum Blockchain ကြီးတစ်ခုလုံးအပေါ်ကို ရောက်သွားတာပါ။

အဓိကအချက်: Contract တစ်ခုကို Deploy လုပ်လိုက်တာနဲ့ သူ့ရဲ့ “State” (ဥပမာ — stock ဘယ်လောက်ကျန်လဲ ဆိုတဲ့ Data) က ကမ္ဘာပေါ်မှာရှိတဲ့ Blockchain Node တိုင်းမှာ သွားပြီး Duplicate ဖြစ်နေမှာပါ။ ဒါကို Global State လို့ ခေါ်ပါတယ်။

ဒါကြောင့် Blockchain ပေါ်ရောက်သွားတဲ့ Code (Smart Contract) တစ်ခုဟာ ဖျက်လို့မရတော့သလို (Immutable)၊ ဘယ်သူကမှလည်း ပိတ်ချလိုက်လို့ (Shut down) မရတော့ပါဘူး။

Gas Fees (လည်ပတ်စရိတ်)

ဒီလိုမျိုး Global Network ကြီးပေါ်မှာ Run တာဖြစ်တဲ့အတွက် အလကားတော့ မရပါဘူး။ အပေါ်က buy() function လိုမျိုး State ကို ပြောင်းလဲစေမယ့် (Stock လျှော့လိုက်တဲ့) အလုပ်မျိုးလုပ်မယ်ဆိုရင် Transaction Fee ပေးရပါတယ်။ ဒါကို Gas Fee လို့ခေါ်ပါတယ်။

  • User က Gas fee ပေးရတယ်။
  • Miner/Validator တွေက Code ကို Run ပေးတယ်။
  • require တွေနဲ့ စစ်ဆေးလို့ အားလုံးမှန်ကန်တယ်ဆိုရင် တစ်ကမ္ဘာလုံးက Node တွေမှာရှိတဲ့ State (Stock အရေအတွက်) က ပြောင်းလဲသွားမှာ ဖြစ်ပါတယ်။

အနှစ်ချုပ်

Smart Contract ဆိုတာ Blockchain ပေါ်မှာ Run နေတဲ့ ပရိုဂရမ်တစ်ခုပါပဲ။ သူက လူကြားခံမလိုဘဲ ရေးသားထားတဲ့ Code အတိုင်း တိတိကျကျ အလုပ်လုပ်ပေးနိုင်တဲ့ အလိုအလျောက် စက်ယန္တရား (Automated Machine) တစ်ခုလိုပါပဲ။

Next Up: Logic တွေကို နားလည်ပြီဆိုတော့ ဒီ Contract တွေနဲ့ ဘယ်လို Interact လုပ်မလဲ? နောက်ရက် (Day 4) မှာတော့ Wallets နဲ့ Private Keys အကြောင်း ဆက်ပြောပြသွားပါမယ်။

Youtube : https://youtu.be/S9-4cHnXnnE

Facebook : https://www.facebook.com/letsfxckingo

Sources : Medium

Listen To The Article

Ask For A Free Demo!
Phone
Phone
* T&C Apply
+91 8925923818+91 8925923818https://t.me/Osiz_Technologies_Salessalesteam@osiztechnologies.com
Christmas Offer 2025

X-Mas 30%

Offer

Osiz Technologies Software Development Company USA
Osiz Technologies Software Development Company USA