Skip to content

開始使用

這份 5 分鐘教學是 CloudBank 第一條交易流程的一站式入口:

  1. 設定環境
  2. 取得 nonce
  3. 簽署 challenge message
  4. 登入
  5. 檢查錢包
  6. 查看市場
  7. 下單

以下 API 路徑都基於 custodial-wallet 後端路徑:/api/v1

先決條件

  • EVM 錢包(MetaMask 或相容錢包)
  • 錢包已配置 BSC Testnet RPC
  • 視需要準備 testnet BNB 與 testnet USDC
  • 本機已安裝 curljq

1) 設定環境

bash
export API_ORIGIN="https://docs-test.cloudbank.to"
export API_BASE="$API_ORIGIN/api/v1"
export ADDRESS="0xYourWalletAddress"

# 快速檢查服務可用性
curl -sS "$API_ORIGIN/health" | jq

預期回應格式:

json
{
  "status": "healthy",
  "version": "v1.0.0",
  "uptimeSeconds": 12345
}

2) 取得 nonce

bash
curl -sS -X POST "$API_BASE/auth/nonce" \
  -H "Content-Type: application/json" \
  -d "{\"address\":\"$ADDRESS\"}" \
  | tee /tmp/cloudbank_nonce.json

預期回應格式:

json
{
  "nonce": "c7f7a4e0...",
  "message": "CloudBank Authentication\\n\\nAddress: 0x...\\nNonce: ...",
  "expiresAt": "2026-03-05T00:00:00Z"
}

3) 簽署 challenge message

先請求一次新的 challenge,然後用錢包 personal_signmessage 原文簽名。

bash
curl -sS -X POST "$API_BASE/auth/nonce" \
  -H "Content-Type: application/json" \
  -d "{\"address\":\"$ADDRESS\"}" \
  | tee /tmp/cloudbank_signing_nonce.json

export CHALLENGE_MESSAGE=$(jq -r '.message' /tmp/cloudbank_signing_nonce.json)
# 在錢包簽名 CHALLENGE_MESSAGE,然後貼上簽名:
export SIGNATURE="0xYourPersonalSignSignature"

nonce 回應預期格式:

json
{
  "nonce": "c7f7a4e0...",
  "message": "CloudBank Authentication\\n\\nAddress: 0x...\\nNonce: ...",
  "expiresAt": "2026-03-05T00:00:00Z"
}

4) 登入

bash
curl -sS -X POST "$API_BASE/auth/login" \
  -H "Content-Type: application/json" \
  -d "{\"address\":\"$ADDRESS\",\"signature\":\"$SIGNATURE\",\"message\":$(jq -Rs . <<< \"$CHALLENGE_MESSAGE\")}" \
  | tee /tmp/cloudbank_login.json

export JWT=$(jq -r '.token' /tmp/cloudbank_login.json)

預期回應格式:

json
{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "custodialWalletAddress": "0xYourCustodialWallet",
  "expiresAt": "2026-03-06T00:00:00Z"
}

5) 檢查錢包

bash
curl -sS "$API_BASE/wallet/info" \
  -H "Authorization: Bearer $JWT" | jq

預期回應格式:

json
{
  "userAddress": "0xYourWalletAddress",
  "custodialWalletAddress": "0xYourCustodialWallet",
  "createdAt": "2026-03-05T00:00:00Z"
}

6) 查看市場

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" | jq

預期回應格式:

json
{
  "marketId": "0xYourMarketId",
  "outcomeTokenId": "12345",
  "bids": [],
  "asks": [],
  "updatedAt": "2026-03-05T00:00:00Z"
}

7) 下單

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"
  }' | jq

預期回應格式:

json
{
  "orderHash": "0xOrderHash",
  "status": "live",
  "price": "0.55000000",
  "makerAmount": "1000000",
  "takerAmount": "550000",
  "createdAt": "2026-03-05T00:00:00Z"
}

下一步