01 — Getting Started
เริ่มต้นพัฒนาบน ORIN Chain ใน 3 ขั้นตอน: ติดตั้ง SDK, เชื่อมต่อ Chain, รับ test mCoin
Install Python SDK
# ติดตั้ง ORIN Python SDK
pip install orin-sdk
# หรือจาก source
git clone https://github.com/macllm/orin-sdk-python.git
cd orin-sdk-python && pip install -e .
Install JavaScript SDK
npm install orin-sdk-js
// หรือ
yarn add orin-sdk-js
Connect to ORIN Chain
from orin.sdk import ORINClient
client = ORINClient(
endpoint="https://api.macllm.ai",
api_key="your-api-key"
)
# ตรวจสอบการเชื่อมต่อ
status = client.health()
print(status) # {'status': 'healthy', 'chain_height': 12345}
Get Test mCoin from Faucet
สำหรับ development และ testing — ขอ test mCoin ได้ฟรี (จำกัด 100 mCoin/วัน)
# ผ่าน SDK
result = client.faucet.request(address="your-orin-address")
print(result) # {'amount': 100, 'tx_hash': '0xabc...'}
# ผ่าน cURL
curl -X POST https://api.macllm.ai/v3/faucet/request \
-H "Content-Type: application/json" \
-d '{"address": "your-orin-address"}'
02 — Chain Overview
Architecture
ORIN Chain คือ distributed AI infrastructure ที่ออกแบบสำหรับ AI computation sharing
┌─────────────────────────────────────────────────┐
│ ORIN Network │
│ │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ Node A │ │ Node B │ │ Node C │ ... │
│ │ (Brain) │←→│ (Brain) │←→│ (Brain) │ │
│ └────┬─────┘ └────┬─────┘ └────┬─────┘ │
│ │ │ │ │
│ ┌────▼──────────────▼──────────────▼───────┐ │
│ │ BFT + PoC Consensus │ │
│ │ (Byzantine Fault Tolerant + Proof of │ │
│ │ Contribution) │ │
│ └────────────────┬──────────────────────────┘ │
│ │ │
│ ┌────────────────▼──────────────────────────┐ │
│ │ ORIN Chain (Ledger) │ │
│ │ mCoin transfers + ORC-20 tokens + │ │
│ │ Smart contracts + Governance votes │ │
│ └───────────────────────────────────────────┘ │
└─────────────────────────────────────────────────┘
Consensus: BFT + PoC
- BFT (Byzantine Fault Tolerant) — ทนได้ถึง 1/3 ของ nodes ที่ทำงานผิดพลาด
- PoC (Proof of Contribution) — Node ได้รับ reward ตามงานที่ทำ ไม่ใช่ computing power
- Block time: ~5 วินาที, Finality: 1 block
- Consensus threshold: 2/3 supermajority
Tokens
mCoin (Native Token)
- ใช้จ่ายค่า transaction fee และ computation cost
- Node rewards จาก PoC consensus
- Soft peg ~0.35 THB/mCoin
MACLLM Token (Governance)
- Governance voting — เสนอและโหวต proposals
- Staking สำหรับ validator nodes
- Revenue sharing จาก network fees
ORC-20 Token Standard
มาตรฐาน token บน ORIN Chain คล้าย ERC-20 — รองรับ fungible tokens ทุกประเภท
name(),symbol(),decimals(),totalSupply()balanceOf(address),transfer(to, amount)approve(spender, amount),transferFrom(from, to, amount)allowance(owner, spender)
03 — API Reference
Base URL: https://api.macllm.ai — ทุก request ต้องมี Authorization: Bearer <api-key>
Chain Endpoints
| Method | Endpoint | Description |
|---|---|---|
| GET | /chain | Chain info — height, peers, consensus status |
| GET | /block/{n} | Block data by number — transactions, hash, timestamp |
| GET | /account/{addr} | Account balance, nonce, token holdings |
| POST | /transfer | Transfer mCoin between accounts |
# Transfer example
POST /transfer
{
"from": "orin1abc...",
"to": "orin1def...",
"amount": 50.0,
"memo": "Payment for AI computation"
}
// Response
{
"tx_hash": "0x7f3a...",
"status": "confirmed",
"block": 12346,
"fee": 0.01
}
DEX Endpoints
| Method | Endpoint | Description |
|---|---|---|
| GET | /v3/dex/pairs | รายการ trading pairs ทั้งหมด |
| GET | /v3/dex/quote | ขอราคา quote ก่อน swap |
| POST | /v3/dex/swap | Execute token swap |
| POST | /v3/dex/liquidity/add | เพิ่ม liquidity เข้า pool |
| POST | /v3/dex/liquidity/remove | ถอน liquidity ออกจาก pool |
| GET | /v3/dex/liquidity/positions | ดู liquidity positions ของตัวเอง |
Bridge Endpoints
| Method | Endpoint | Description |
|---|---|---|
| GET | /v3/bridge/rates | อัตราแลกเปลี่ยนข้าม chain |
| POST | /v3/bridge/deposit | ฝาก token จาก external chain เข้า ORIN |
| POST | /v3/bridge/withdraw | ถอน token จาก ORIN ไป external chain |
Governance Endpoints
| Method | Endpoint | Description |
|---|---|---|
| GET | /v3/governance/proposals | รายการ proposals ทั้งหมด |
| POST | /v3/governance/proposals | สร้าง proposal ใหม่ |
| POST | /v3/governance/vote | โหวต proposal (ต้องมี MACLLM token) |
Explorer Endpoints
| Method | Endpoint | Description |
|---|---|---|
| GET | /v3/explorer/blocks | รายการ blocks ล่าสุด (paginated) |
| GET | /v3/explorer/tx/{hash} | รายละเอียด transaction |
| GET | /v3/explorer/search?q= | ค้นหา block, tx, address |
Faucet Endpoint
| Method | Endpoint | Description |
|---|---|---|
| POST | /v3/faucet/request | ขอ test mCoin (testnet, 100/day limit) |
04 — Python SDK
Python SDK ครอบคลุมทุก API endpoint — รองรับ async และ sync
Initialize Client
from orin.sdk import ORINClient
# Sync client
client = ORINClient(
endpoint="https://api.macllm.ai",
api_key="orin_key_abc123"
)
# Async client
from orin.sdk import AsyncORINClient
async def main():
client = AsyncORINClient(endpoint="https://api.macllm.ai")
info = await client.chain.info()
print(info)
Query Chain
# Chain info
info = client.chain.info()
print(f"Height: {info['height']}, Peers: {info['peers']}")
# Get block
block = client.chain.block(12345)
print(f"Transactions: {len(block['transactions'])}")
# Account balance
account = client.account.get("orin1abc...")
print(f"Balance: {account['balance']} mCoin")
Transfer mCoin
# โอน mCoin
tx = client.transfer(
to="orin1def...",
amount=50.0,
memo="AI task payment"
)
print(f"TX Hash: {tx['tx_hash']}")
print(f"Status: {tx['status']}")
# รอ confirmation
receipt = client.chain.wait_for_tx(tx['tx_hash'], timeout=30)
print(f"Confirmed in block {receipt['block']}")
DEX Operations
# ดู pairs
pairs = client.dex.pairs()
for p in pairs:
print(f"{p['base']}/{p['quote']} — price: {p['price']}")
# ขอ quote
quote = client.dex.quote(
pair="mCoin/MACLLM",
side="buy",
amount=100
)
print(f"You get: {quote['output_amount']} MACLLM")
# Execute swap
swap = client.dex.swap(
pair="mCoin/MACLLM",
side="buy",
amount=100,
slippage=0.5 # 0.5% max slippage
)
Governance
# ดู proposals
proposals = client.governance.proposals(status="active")
for p in proposals:
print(f"[{p['id']}] {p['title']} — votes: {p['votes_for']}/{p['votes_against']}")
# โหวต
client.governance.vote(
proposal_id=42,
vote="for", # "for" | "against" | "abstain"
amount=1000 # MACLLM token weight
)
Error Handling
from orin.sdk.exceptions import (
ORINError, InsufficientFunds, RateLimited, ChainError
)
try:
tx = client.transfer(to="orin1def...", amount=99999)
except InsufficientFunds as e:
print(f"ยอดไม่พอ: มี {e.balance}, ต้องการ {e.required}")
except RateLimited:
print("เกิน rate limit — รอแล้วลองใหม่")
except ORINError as e:
print(f"Error: {e.code} — {e.message}")
05 — JavaScript SDK
JavaScript/TypeScript SDK สำหรับ Node.js และ Browser
Initialize
import { ORINClient } from 'orin-sdk-js';
const client = new ORINClient({
endpoint: 'https://api.macllm.ai',
apiKey: 'orin_key_abc123',
});
// Health check
const health = await client.health();
console.log(health); // { status: 'healthy', chain_height: 12345 }
Chain Operations
// Chain info
const info = await client.chain.info();
// Get block
const block = await client.chain.block(12345);
// Account
const account = await client.account.get('orin1abc...');
console.log(`Balance: ${account.balance} mCoin`);
Transfer
const tx = await client.transfer({
to: 'orin1def...',
amount: 50.0,
memo: 'Payment',
});
console.log(`TX: ${tx.tx_hash}`);
// Wait for confirmation
const receipt = await client.chain.waitForTx(tx.tx_hash, { timeout: 30000 });
console.log(`Confirmed in block ${receipt.block}`);
DEX Swap
// Get quote
const quote = await client.dex.quote({
pair: 'mCoin/MACLLM',
side: 'buy',
amount: 100,
});
// Execute swap
const swap = await client.dex.swap({
pair: 'mCoin/MACLLM',
side: 'buy',
amount: 100,
slippage: 0.5,
});
Event Listener
// Subscribe to new blocks
client.chain.onBlock((block) => {
console.log(`New block #${block.height} — ${block.transactions.length} txs`);
});
// Subscribe to account changes
client.account.onChange('orin1abc...', (event) => {
console.log(`Balance changed: ${event.old_balance} → ${event.new_balance}`);
});
TypeScript Types
import type {
ChainInfo, Block, Account,
TransferResult, SwapResult, Quote,
Proposal, VoteResult
} from 'orin-sdk-js';
06 — Smart Contracts (ORC-20)
ORC-20 คือมาตรฐาน fungible token บน ORIN Chain — คล้าย ERC-20 แต่ optimized สำหรับ AI workloads
ORC-20 Interface
# ORC-20 Standard Interface
class ORC20:
def name(self) -> str: ...
def symbol(self) -> str: ...
def decimals(self) -> int: ...
def total_supply(self) -> int: ...
def balance_of(self, owner: str) -> int: ...
def transfer(self, to: str, amount: int) -> bool: ...
def approve(self, spender: str, amount: int) -> bool: ...
def transfer_from(self, frm: str, to: str, amount: int) -> bool: ...
def allowance(self, owner: str, spender: str) -> int: ...
Create Your Token
from orin.sdk import ORINClient
from orin.sdk.contracts import ORC20Contract
client = ORINClient(endpoint="https://api.macllm.ai", api_key="...")
# Deploy ORC-20 token
contract = ORC20Contract(
name="My AI Token",
symbol="MAIT",
decimals=18,
initial_supply=1_000_000
)
deploy_tx = client.contracts.deploy(contract)
print(f"Contract deployed at: {deploy_tx['contract_address']}")
print(f"TX Hash: {deploy_tx['tx_hash']}")
Interact with Contract
# Load existing contract
token = client.contracts.orc20("orin_contract_addr...")
# Read
name = token.name() # "My AI Token"
supply = token.total_supply() # 1000000
bal = token.balance_of("orin1abc...")
# Transfer
tx = token.transfer(to="orin1def...", amount=500)
# Approve + TransferFrom (สำหรับ DEX/DApp)
token.approve(spender="orin_dex_addr...", amount=1000)
token.transfer_from(frm="orin1abc...", to="orin1ghi...", amount=200)
Events
# Listen to Transfer events
token.on("Transfer", lambda e:
print(f"{e['from']} → {e['to']}: {e['amount']}")
)
# Listen to Approval events
token.on("Approval", lambda e:
print(f"{e['owner']} approved {e['spender']} for {e['amount']}")
)
07 — Node Setup
รัน ORIN validator node เพื่อช่วยประมวลผล AI tasks และรับ mCoin rewards
System Requirements
| Component | Minimum | Recommended |
|---|---|---|
| CPU | 4 cores | 8+ cores |
| RAM | 8 GB | 16+ GB |
| Storage | 50 GB SSD | 200+ GB NVMe |
| Network | 10 Mbps | 100+ Mbps |
| OS | macOS 13+, Ubuntu 22.04+, Windows 10+ | |
Quick Install
# macOS / Linux
curl -fsSL https://macllm.ai/install.sh | bash
# Windows (PowerShell)
irm https://macllm.ai/install.ps1 | iex
Manual Setup
# 1. Clone
git clone https://github.com/macllm/orin-node.git
cd orin-node
# 2. Install dependencies
pip install -r requirements.txt
# 3. Configure
cp .env.example .env
# แก้ไข .env:
# ORIN_NODE_NAME="my-node"
# ORIN_BOOTSTRAP="https://api.macllm.ai"
# ORIN_PORT=8090
# 4. Generate node key
python -m orin.node keygen
# 5. Start node
python -m orin.node start
Verify Node is Running
# Check local health
curl http://localhost:8090/health
# Check chain sync status
curl http://localhost:8090/chain
# Expected output:
{
"status": "synced",
"height": 12350,
"peers": 4,
"node_id": "orin_node_xyz..."
}
Node Configuration
# .env configuration options
ORIN_NODE_NAME="my-validator" # ชื่อ node
ORIN_BOOTSTRAP="https://api.macllm.ai" # Bootstrap server
ORIN_PORT=8090 # Listen port
ORIN_MAX_TASKS=5 # Max concurrent tasks
ORIN_CPU_LIMIT=80 # CPU usage cap (%)
ORIN_RAM_LIMIT=70 # RAM usage cap (%)
ORIN_WALLET="orin1abc..." # Reward address
ORIN_LOG_LEVEL="info" # debug/info/warning/error
08 — DEX Integration
ORIN DEX ใช้ AMM (Automated Market Maker) model — เพิ่ม liquidity และ swap tokens programmatically
Add Liquidity
from orin.sdk import ORINClient
client = ORINClient(endpoint="https://api.macllm.ai", api_key="...")
# เพิ่ม liquidity เข้า mCoin/MACLLM pool
result = client.dex.add_liquidity(
pair="mCoin/MACLLM",
amount_a=1000, # 1000 mCoin
amount_b=500, # 500 MACLLM
slippage=1.0, # 1% max slippage
)
print(f"LP Tokens received: {result['lp_tokens']}")
print(f"Pool share: {result['share_percent']}%")
Remove Liquidity
# ถอน liquidity ออก
result = client.dex.remove_liquidity(
pair="mCoin/MACLLM",
lp_amount=50, # LP tokens to redeem
min_a=90, # minimum mCoin received
min_b=45, # minimum MACLLM received
)
print(f"Received: {result['amount_a']} mCoin + {result['amount_b']} MACLLM")
Execute Swap
# Step 1: Get quote
quote = client.dex.quote(
pair="mCoin/MACLLM",
side="buy", # buy MACLLM with mCoin
amount=100, # spend 100 mCoin
)
print(f"Expected: {quote['output_amount']} MACLLM")
print(f"Price impact: {quote['price_impact']}%")
print(f"Fee: {quote['fee']} mCoin")
# Step 2: Execute swap (ถ้า quote ยอมรับได้)
if quote['price_impact'] < 2.0: # max 2% impact
swap = client.dex.swap(
pair="mCoin/MACLLM",
side="buy",
amount=100,
slippage=0.5,
)
print(f"Swap TX: {swap['tx_hash']}")
else:
print("Price impact สูงเกินไป — ลดจำนวนหรือรอ liquidity เพิ่ม")
Monitor Positions
# ดู liquidity positions ทั้งหมด
positions = client.dex.positions()
for pos in positions:
print(f"{pos['pair']}:")
print(f" LP Tokens: {pos['lp_tokens']}")
print(f" Value: {pos['value_a']} + {pos['value_b']}")
print(f" Fees earned: {pos['fees_earned']}")
print(f" APR: {pos['apr']}%")
JavaScript DEX Example
import { ORINClient } from 'orin-sdk-js';
const client = new ORINClient({ endpoint: 'https://api.macllm.ai', apiKey: '...' });
// Add liquidity
const lp = await client.dex.addLiquidity({
pair: 'mCoin/MACLLM',
amountA: 1000,
amountB: 500,
slippage: 1.0,
});
// Swap
const swap = await client.dex.swap({
pair: 'mCoin/MACLLM',
side: 'buy',
amount: 100,
slippage: 0.5,
});
console.log(`Swap complete: ${swap.tx_hash}`);