Khởi động nhanh
Hướng dẫn này giúp bạn chạy luồng API end-to-end đầu tiên của CloudBank:
- Chuẩn bị môi trường
- Xác thực bằng chữ ký ví
- Kiểm tra health và thông tin ví
- Gửi giao dịch orderbook
- Rút tiền
Tất cả đường dẫn API bên dưới dùng base path của backend custodial-wallet: /api/v1.
Điều kiện cần
- Ví EVM (MetaMask hoặc tương thích)
- Ví đã cấu hình BSC Testnet RPC
- testnet BNB và testnet USDC khi cần
- Cài sẵn
curlvàjq
1) Cấu hình biến môi trường
bash
export API_ORIGIN="https://docs-test.cloudbank.to"
export API_BASE="$API_ORIGIN/api/v1"
# Địa chỉ ví EOA của bạn (dùng để đăng nhập)
export ADDRESS="0xYourWalletAddress"2) Xác thực (nonce -> sign -> JWT)
2.1 Yêu cầu nonce challenge
bash
curl -sS -X POST "$API_BASE/auth/nonce" \
-H "Content-Type: application/json" \
-d "{\"address\":\"$ADDRESS\"}" | tee /tmp/cloudbank_nonce.jsonTrường dữ liệu kỳ vọng:
noncemessageexpiresAt
2.2 Ký challenge message bằng ví
Dùng personal_sign trong ví với đúng message từ /auth/nonce.
bash
MESSAGE=$(jq -r '.message' /tmp/cloudbank_nonce.json)
# Thay bằng chữ ký từ ví của bạn (0x...)
export SIGNATURE="0xYourPersonalSignSignature"2.3 Đổi chữ ký lấy JWT
bash
curl -sS -X POST "$API_BASE/auth/login" \
-H "Content-Type: application/json" \
-d "{\"address\":\"$ADDRESS\",\"signature\":\"$SIGNATURE\",\"message\":$(jq -Rs . <<< "$MESSAGE")}" \
| tee /tmp/cloudbank_login.json
export JWT=$(jq -r '.token' /tmp/cloudbank_login.json)3) Lệnh API đầu tiên: health + wallet info
3.1 Health check
Route health của backend là /health.
bash
curl -sS "$API_ORIGIN/health" | jq3.2 Lấy thông tin ví custodial
bash
curl -sS "$API_BASE/wallet/info" \
-H "Authorization: Bearer $JWT" | jqTrường dữ liệu kỳ vọng:
userAddresscustodialWalletAddresscreatedAt
4) Đặt lệnh qua orderbook
4.1 Đọc độ sâu orderbook
bash
export MARKET_ID="0xYourMarketId"
export OUTCOME_TOKEN_ID="12345"
curl -sS "$API_BASE/orderbook/book?marketId=$MARKET_ID&outcomeTokenId=$OUTCOME_TOKEN_ID&depth=20" | jq4.2 Gửi lệnh đã ký
POST /api/v1/orderbook/orders yêu cầu payload lệnh có chữ ký EIP-712.
bash
curl -sS -X POST "$API_BASE/orderbook/orders" \
-H "Authorization: Bearer $JWT" \
-H "Content-Type: application/json" \
-d '{
"marketId": "0xYourMarketId",
"timeInForce": "GTC",
"domain": {
"name": "Polymarket CTF Exchange",
"version": "1",
"chainId": 97,
"verifyingContract": "0xExchangeContract"
},
"order": {
"salt": "1700000000000000000",
"maker": "0xYourWalletAddress",
"signer": "0xYourWalletAddress",
"taker": "0x0000000000000000000000000000000000000000",
"tokenId": "12345",
"makerAmount": "1000000",
"takerAmount": "550000",
"expiration": "1767225600",
"nonce": "1",
"feeRateBps": "0",
"side": "buy",
"signatureType": "0"
},
"signature": "0xYourEip712OrderSignature"
}' | jqTrường dữ liệu chính kỳ vọng:
orderHashstatuspricemakerAmount/takerAmount
5) Rút tiền
asset có thể dùng USDC, BNB.
bash
curl -sS -X POST "$API_BASE/wallet/withdraw" \
-H "Authorization: Bearer $JWT" \
-H "Content-Type: application/json" \
-d '{
"asset": "USDC",
"toAddress": "0xYourDestinationAddress",
"amount": "10.5"
}' | jqTrường dữ liệu kỳ vọng:
txHashassetamountfeegasModestatuscreatedAt
Tiếp theo
- Ví dụ curl đầy đủ: /vi/guide/api-examples
- API reference đầy đủ: /tech/architecture/api-reference