读取公开资产目录
GET https://api.allswap.io/v2/assets 在一次 JSON 响应中列出 AllSwap 可以兑换的全部资产,包括所在链、小数位数、路由分组和最低支付金额。它是公开的:不需要 API 密钥,不需要账户,也不用注册。它返回的资产 ID 就是 Partner API 在报价和订单中使用的 ID。
资产目录不包含价格。报价和下单需要 Partner API 密钥,见快速开始。
用 curl 获取
curl -sS https://api.allswap.io/v2/assets该端点不接受任何查询参数:带查询字符串会返回 404,所以请在自己这边筛选。完整列表一次返回,响应不到 100 KB。
配合 jq 可以概括响应并挑出某一项,这里是 Tron 上的 USDT:
curl -sS https://api.allswap.io/v2/assets \
| jq '{version, observedAt, stale, nextCursor, assets: (.assets | length), tronUsdt: (.assets[] | select(.chainId == "tron:mainnet" and .symbol == "USDT"))}'{
"version": "live-catalog-a48aedb9fae6f641",
"observedAt": "2026-11-28T17:57:47.860595591Z",
"stale": false,
"nextCursor": null,
"assets": 346,
"tronUsdt": {
"assetId": "tron:mainnet/trc20:TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
"chainId": "tron:mainnet",
"decimals": 6,
"destinationGroups": [
"a",
"b"
],
"minAmountIn": "100000000",
"quotable": true,
"sourceGroups": [
"a",
"b"
],
"symbol": "USDT",
"version": 1
}
}响应字段
响应对象有五个字段,始终全部存在。
横向滚动表格,查看其余列。
| 字段 | 类型 | 说明 |
|---|---|---|
version必填 | string | 资产目录的版本标识,目录变化时随之改变。 |
observedAt必填 | string (UTC time) | 列表生成的时间,RFC 3339 UTC 格式(以 Z 结尾)。 |
stale必填 | boolean | 列表可能已经过时时为 true。 |
assets必填 | Asset[] | 全部资产,最多 1000 项;字段见下表。 |
nextCursor必填 | null | 始终为 null:列表不分页,保留该字段只为兼容。 |
assets[] 中的每一项
横向滚动表格,查看其余列。
| 字段 | 类型 | 说明 |
|---|---|---|
assetId必填 | string (CAIP-19) | 资产 ID,在报价和订单中用作 fromAssetId 和 toAssetId。 |
version必填 | integer | 该资产数据的版本号。 |
chainId必填 | string (CAIP-2) | 资产所在链的 ID。收款地址和退款地址以它作为 chainId。 |
decimals必填 | integer (0–77) | 小数位数,用于在最小单位与显示金额之间换算。 |
symbol必填 | string | 资产符号,不唯一:同一个符号会出现在多条链上。 |
quotable必填 | boolean | 当且仅当 sourceGroups 或 destinationGroups 不为空时为 true。 |
sourceGroups必填 | string[] | 该资产可以作为支付方(币对的来源)的路由分组标签。 |
destinationGroups必填 | string[] | 该资产可以作为接收方(币对的目标)的路由分组标签。 |
minAmountIn可选 | string | null | 平台对该资产作为来源时的最低支付金额,以最小单位表示。为 null 或不存在时表示没有下限。 |
金额一律是以资产最小单位表示的整数字符串,从不使用 JSON 数字。请用 decimals 配合字符串或 BigInt 运算换算,不要用浮点数。
资产 ID(CAIP-19)
assetId 遵循 CAIP-19:<chainId>/<namespace>:<reference>。第一个 / 之前是链,始终等于该项的 chainId。请按第一个 / 拆分,而不是按 :,因为链 ID 本身就含有冒号。
链 ID 遵循 CAIP-2:EVM 链是 eip155:<chain id>(eip155:1 即以太坊),比特币一类的链是 bip122:<genesis hash prefix>,其他链使用 tron:mainnet、ton:mainnet、near:mainnet、ripple:0 这样的名称。命名空间说明资产的类型:
横向滚动表格,查看其余列。
| 命名空间 | reference 的含义 | 示例 |
|---|---|---|
slip44 | 链的原生币;reference 是它的 SLIP-44 币种编号(ETH 为 60)。 | eip155:1/slip44:60 |
erc20 | EVM 链上的代币;reference 是代币合约地址。 | eip155:1/erc20:0xdac17f958d2ee523a2206206994597c13d831ec7 |
trc20 | Tron 上的代币;reference 是代币合约地址。 | tron:mainnet/trc20:TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t |
spl | Solana 上的代币;reference 是 mint 地址。 | solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/spl:Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB |
jetton | TON 上的代币;reference 是 jetton master 地址。 | ton:mainnet/jetton:EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs |
nep141 | NEAR 上的代币;reference 是代币合约账户。 | near:mainnet/nep141:usdt.tether-token.near |
编写本指南时,资产目录中的每一项都属于这六种命名空间之一。把资产 ID 传回时,请保持收到时的原样。
用 TypeScript 列出资产
这个脚本只用内置的 fetch。它打印每一个 USDT 条目及拆分后的资产 ID、设有最低支付金额的资产,以及 Tron 上的 USDT 和 BTC 能否组成币对。
// Fields as defined by the AssetsResponse and Asset schemas
interface Asset {
assetId: string;
version: number;
chainId: string;
decimals: number;
symbol: string;
quotable: boolean;
sourceGroups: string[];
destinationGroups: string[];
minAmountIn?: string | null;
}
interface AssetsResponse {
version: string;
observedAt: string;
stale: boolean;
assets: Asset[];
nextCursor: null;
}
// CAIP-19: <chainId>/<assetNamespace>:<assetReference>
function splitAssetId(assetId: string) {
const slash = assetId.indexOf("/");
const chain = assetId.slice(0, slash);
const asset = assetId.slice(slash + 1);
const colon = asset.indexOf(":");
return { chain, namespace: asset.slice(0, colon), reference: asset.slice(colon + 1) };
}
// Smallest units to a display amount, without floating point
function formatUnits(amount: string, decimals: number) {
const padded = amount.padStart(decimals + 1, "0");
const whole = padded.slice(0, padded.length - decimals);
const fraction = padded.slice(padded.length - decimals).replace(/0+$/, "");
return fraction ? `${whole}.${fraction}` : whole;
}
// A source and a destination can form a pair only when their groups share a label
function canPair(from: Asset, to: Asset) {
return from.sourceGroups.some((group) => to.destinationGroups.includes(group));
}
const res = await fetch("https://api.allswap.io/v2/assets");
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const catalog = (await res.json()) as AssetsResponse;
console.log(`${catalog.assets.length} assets, catalog ${catalog.version}, observed ${catalog.observedAt}, stale=${catalog.stale}`);
// 1. Every USDT entry, with its CAIP-19 ID split into parts
for (const a of catalog.assets.filter((asset) => asset.symbol === "USDT")) {
const { chain, namespace, reference } = splitAssetId(a.assetId);
console.log(chain.padEnd(40), namespace.padEnd(7), reference);
}
// 2. Minimum payments, in display units
for (const a of catalog.assets) {
if (a.minAmountIn) console.log(`minimum: ${formatUnits(a.minAmountIn, a.decimals)} ${a.symbol} on ${a.chainId}`);
}
// 3. Can USDT on Tron be swapped to BTC?
const byId = new Map(catalog.assets.map((a) => [a.assetId, a]));
const from = byId.get("tron:mainnet/trc20:TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t");
const to = byId.get("bip122:000000000019d6689c085ae165831e93/slip44:0");
if (from && to) console.log(`USDT on Tron -> BTC: ${canPair(from, to)}`);node catalog.mts346 assets, catalog live-catalog-a48aedb9fae6f641, observed 2026-11-28T17:57:47.860595591Z, stale=false
eip155:1 erc20 0xdac17f958d2ee523a2206206994597c13d831ec7
eip155:10 erc20 0x94b008aa00579c1307b0ef2c499ad98a8ce58e58
eip155:100 erc20 0x4ecaba5870353805a9f068101a40e0f32ed605c6
eip155:137 erc20 0xc2132d05d31c914a87c6611c10748aeb04b58e8f
eip155:42161 erc20 0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9
eip155:43114 erc20 0x9702230a8ea53601f5cd2dc00fdbc13d4df4a8c7
eip155:4326 erc20 0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb
eip155:534352 erc20 0xf55bec9cafdbe8730f096aa55dad6d22d44099df
eip155:56 erc20 0x55d398326f99059ff775485246999027b3197955
eip155:747474 erc20 0x2dca96907fde857dd3d816880a0df407eeb2d2f2
eip155:8453 erc20 0xfde4c96c8593536e31f229ea8f37b2ada2699bb2
near:mainnet nep141 usdt.tether-token.near
solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp spl Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB
ton:mainnet jetton EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs
tron:mainnet trc20 TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t
minimum: 100 USDT on tron:mainnet
USDT on Tron -> BTC: trueNode.js 22.18 及以上版本可以直接运行 .mts 文件;更早的版本请使用 npx tsx catalog.mts。代码中的接口照搬了 OpenAPI 文档里的 AssetsResponse 和 Asset 两个 schema。
币对与最低金额
- 只有当来源资产的
sourceGroups与目标资产的destinationGroups有共同标签时,两者才可能组成币对。标签是不透明的,只能在同一次响应内比较,不要保存它们。 - 有共同标签并不保证此刻一定有路由:报价仍可能返回 422
NO_ROUTE。 sourceGroups为空的资产只能接收,不能用来支付。- 低于
minAmountIn的报价会以 422AMOUNT_OUT_OF_RANGE被拒绝。请在用户输入金额之前先展示最低金额。
缓存与错误
- 资产目录很少变化。请在你的应用中缓存,并定期刷新。响应带有
Cache-Control: no-store,HTTP 缓存和 CDN 不会替你保留副本。 GET /v2/assets不计入合作方额度。- 错误:带查询字符串时返回 404
NOT_FOUND,以及 500INTERNAL_ERROR,和 503TEMPORARILY_UNAVAILABLE(已知等待时间时附带Retry-After头)。GET 请求随时可以安全重试。错误响应体的格式见错误码与限流。
机器可读的规范
该端点是 Partner API 的 OpenAPI 3.1 文档 /docs/partner-v2.openapi.json 中的 GET /v2/assets,对应 schema 为 AssetsResponse 和 Asset。API 参考中也有说明。
相关内容
- 在本地校验地址与 Memo:在请求报价之前,按资产的
chainId校验收款地址。 - 快速开始:持 Partner API 密钥,从资产列表走到报价和订单。
- MCP 服务器:让 AI 助手搜索资产目录。