快速开始¶
本指南将引导您完成与 Sera 的首次交互 — 从查询可用代币到执行您的第一笔兑换。
前提条件¶
- 一个以太坊钱包(例如 MetaMask)
- 一些测试网 ETH 用于支付 Gas 费用(使用 Sepolia 水龙头)
第 1 步:探索可用代币¶
查询代币注册表以查看可用的稳定币:
第 2 步:获取兑换报价¶
获取两种代币之间的兑换报价:
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 — 这些是您将使用钱包签名的参数。
第 3 步:签名并执行兑换¶
使用 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
})
});
有关详细的签名说明,请参阅身份验证。
第 4 步:查看余额¶
创建 API 密钥以查询您的余额和订单历史。/balances 端点返回您的钱包余额(以太坊钱包中的代币)和 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}`);
}
使用 Web 应用¶
您也可以通过 Sera Web 界面直接交易:
- 访问 testnet.sera.cx
- 连接您的钱包
- 选择一个货币对
- 下限价单或执行即时兑换
- 在仪表板中监控您的订单