快速開始¶
本指南將帶您完成與 Sera 的首次互動 — 從查詢可用代幣到執行您的第一筆兌換。
前置條件¶
- 一個 Ethereum 錢包(例如 MetaMask)
- 一些測試網 ETH 用於支付 Gas(使用 Sepolia 水龍頭)
步驟一:瀏覽可用代幣¶
查詢代幣註冊表以查看有哪些穩定幣可用:
步驟二:取得兌換報價¶
取得兩種代幣之間的兌換報價:
curl -X POST https://api.sera.cx/api/v1/swap/quote \
-H "Content-Type: application/json" \
-d '{
"from_token": "0xDcAEcdd8Db64f4316A11917Ad0162DEBD935285b",
"to_token": "0xd3BdB2CE9cD98566EFc2e2977448c40578371779",
"from_amount": "1000000000",
"owner_address": "0xYOUR_ADDRESS",
"recipient": "0xYOUR_ADDRESS",
"expiration": 1735689600,
"gas_mode": "receive_less"
}'
const quote = await fetch('https://api.sera.cx/api/v1/swap/quote', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
from_token: '0xDcAEcdd8Db64f4316A11917Ad0162DEBD935285b', // USDC
to_token: '0xd3BdB2CE9cD98566EFc2e2977448c40578371779', // EURC
from_amount: '1000000000', // 1000 USDC (6 decimals)
owner_address: '0xYOUR_ADDRESS',
recipient: '0xYOUR_ADDRESS',
expiration: Math.floor(Date.now() / 1000) + 3600,
gas_mode: 'receive_less'
})
});
const data = await quote.json();
console.log(data);
回應中包含 uuid 和 route_params — 這些是您需要使用錢包簽署的參數。
步驟三:簽署並執行兌換¶
使用 EIP-712 類型資料簽名對 route_params 進行簽署,然後提交:
// Sign the route_params with your wallet (EIP-712)
const signature = await signer.signTypedData(domain, types, route_params);
// Submit the signed swap
const result = await fetch('https://api.sera.cx/api/v1/swap', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
uuid: data.uuid,
signature: signature
})
});
如需詳細的簽署說明,請參閱身份驗證。
步驟四:查詢餘額¶
建立 API key 以查詢您的餘額和訂單歷史。/balances 端點回傳您的錢包餘額(Ethereum 錢包中的代幣)和 Vault 餘額(為限價單交易存入的代幣),以及鎖定在未完成訂單中的凍結金額。
const response = await fetch('https://api.sera.cx/api/v1/balances?owner_address=0xYOUR_ADDRESS', {
headers: { 'Authorization': 'Bearer YOUR_API_KEY:YOUR_API_SECRET' }
});
const { balances } = await response.json();
for (const bal of balances) {
console.log(`${bal.symbol}:`);
console.log(` 錢包: ${bal.wallet_balance}`);
console.log(` Vault 可用: ${bal.vault_available}`);
console.log(` Vault 凍結: ${bal.vault_frozen}`);
}
使用網頁應用¶
您也可以直接透過 Sera 網頁介面進行交易:
- 前往 testnet.sera.cx
- 連接您的錢包
- 選擇貨幣對
- 掛限價單或執行即時兌換
- 在儀表板中監控您的訂單