Developer Portal · v19.9

Build on PKT

REST API, WebSocket, JS/TS SDK, và Webhooks — mọi thứ cần để xây dựng ứng dụng trên nền PKT blockchain.

Quickstart API Playground Webhooks
Tính năng

REST API

Blocks, transactions, addresses, UTXOs, mempool — toàn bộ data on-chain qua HTTP JSON.

🔔

Webhooks

Push notification real-time khi có block mới, transaction, hoặc activity tại address cụ thể.

📦

JS/TS SDK

Package @pktcore/sdk — typed client cho REST, JSON-RPC, và WebSocket subscribe.

Quickstart
1

Gọi API không cần auth

Tất cả endpoint GET /api/testnet/* đều public — không cần API key.

bash
# Lấy block mới nhất curl https://oceif.com/blockchain-rust/api/testnet/headers?limit=1 # Balance của một address curl https://oceif.com/blockchain-rust/api/testnet/balance/pkt1q...
2

Cài JS/TS SDK

SDK typed đầy đủ, hỗ trợ REST + JSON-RPC + WebSocket.

bash
npm install @pktcore/sdk
typescript
import { PktClient } from '@pktcore/sdk'; const client = new PktClient({ baseUrl: 'https://oceif.com/blockchain-rust', }); const summary = await client.getSummary(); console.log(summary.height, summary.hashrate);
3

Subscribe real-time qua WebSocket

Nhận block/tx mới không cần polling.

typescript
client.subscribe('block', (block) => { console.log('New block:', block.height, block.hash); }); client.subscribe('tx', (tx) => { console.log('New tx:', tx.tx_id, tx.fee); });
4

Đăng ký Webhook (cần write API key)

Nhận HTTP POST khi có event — không cần giữ WebSocket connection.

bash
curl -X POST https://oceif.com/blockchain-rust/api/webhooks \ -H "X-API-Key: your_write_key" \ -H "Content-Type: application/json" \ -d '{"url":"https://your-app.com/hook","events":["new_block"]}'
API Endpoints
Method Path Mô tả Auth
GET/api/testnet/headersBlock headers (paginated)
GET/api/testnet/block/:heightBlock theo height
GET/api/testnet/tx/:txidTransaction theo txid
GET/api/testnet/balance/:addrSố dư PKT của address
GET/api/testnet/utxos/:addrUTXOs của address
GET/api/testnet/address/:addr/txsLịch sử giao dịch (paginated)
GET/api/testnet/summaryNetwork summary (hashrate, mempool…)
GET/api/testnet/mempoolPending transactions
GET/api/testnet/analyticsTime-series hashrate/difficulty
GET/api/testnet/rich-listTop holders
GET/api/testnet/search?q=Tìm block/tx/address
GET/api/health/detailedNode health status
GET/api/webhooksDanh sách webhookswrite
POST/api/webhooksĐăng ký webhook mớiwrite
GET/api/testnet/address/:addr/export.csvExport lịch sử CSV
GET/api/keysLiệt kê API keysadmin
POST/api/keysTạo API key mớiadmin
DEL/api/keys/:key_idThu hồi API keyadmin
Thử nghiệm trong API Playground →
Rate Limits
Anonymous
60
requests / phút
API Key (read)
600
requests / phút
API Key (write)
120
requests / phút
API Key

Lấy API Key

API key được tạo server-side. Gửi email đến admin hoặc liên hệ qua GitHub để nhận key.

Header xác thực: X-API-Key: your_key_here

read Đọc dữ liệu blockchain
write read + quản lý webhooks
admin write + quản lý API keys
Verify Webhook Signature

Mỗi request từ PKTScan có header X-PKT-Signature = HMAC-SHA256(secret, body). Verify để đảm bảo request đến từ PKTScan.

Node.js / Express
import crypto from 'crypto'; app.post('/hook', (req, res) => { const sig = req.headers['x-pkt-signature']; const expected = crypto .createHmac('sha256', process.env.PKT_WEBHOOK_SECRET) .update(req.rawBody) .digest('hex'); if (sig !== expected) return res.status(401).end(); const { event, data } = req.body; if (event === 'new_block') console.log('Block:', data.height); res.sendStatus(200); });