配置端点
查询支持的区块链网络、代币和平台配置。
查询所有链信息
查询所有支持的区块链网络及其配置。
端点:POST /api/v2.0.0/config/queryAllChainInfo
请求
请求头:
Content-Type: application/json
请求体:不需要请求体(空 POST 请求)
响应
成功响应(200 OK):
{
"code": 0,
"msg": "success",
"data": [
{
"id": 1,
"chain": "Ethereum",
"chainDesc": "Ethereum Mainnet",
"enable": true,
"receiptAddress": "0x...",
"txConfirmCount": "12",
"walletConnectEnable": true,
"bridgeServerAddress": "https://bridge.hashnut.io",
"decimals": 18,
"baseChainSymbol": "ETH",
"env": 1,
"chainId": "1",
"baseChainCoin": "ETH",
"eip712ChainId": "1",
"eip1559Support": true
}
]
}
响应字段
| 字段 | 类型 | 描述 |
|---|---|---|
id | integer | 链标识符 |
chain | string | 链名称(例如,"Ethereum"、"BSC") |
chainDesc | string | 链描述 |
enable | boolean | 链当前是否启用 |
receiptAddress | string | HashNut 平台在此链上的接收地址 |
txConfirmCount | string | 交易所需的确认数 |
walletConnectEnable | boolean | 是否支持 WalletConnect |
bridgeServerAddress | string | WalletConnect 桥接服务器地址 |
decimals | integer | 基础货币小数位数(例如,ETH 为 18) |
baseChainSymbol | string | 基础链符号(例如,"ETH") |
env | integer | 环境(0=生产环境,1=测试环境,2=开发环境) |
chainId | string | 链 ID(例如,以太坊主网为 "1") |
baseChainCoin | string | 基础链代币符号 |
eip712ChainId | string | EIP-712 链 ID |
eip1559Support | boolean | 是否支持 EIP-1559 |
代码示例
- JavaScript
- Python
- cURL
const response = await fetch(
'https://testnet.hashnut.io/api/v2.0.0/config/queryAllChainInfo',
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
}
);
const result = await response.json();
if (result.code === 0) {
const chains = result.data;
chains.forEach(chain => {
console.log(`${chain.chain}: ${chain.chainId} (${chain.enable ? 'Enabled' : 'Disabled'})`);
});
}
import requests
response = requests.post(
'https://testnet.hashnut.io/api/v2.0.0/config/queryAllChainInfo',
headers={'Content-Type': 'application/json'}
)
result = response.json()
if result['code'] == 0:
for chain in result['data']:
print(f"{chain['chain']}: {chain['chainId']} ({'Enabled' if chain['enable'] else 'Disabled'})")
curl -X POST 'https://testnet.hashnut.io/api/v2.0.0/config/queryAllChainInfo' \
-H 'Content-Type: application/json'
查询所有代币信息
查询所有链上支持的所有货币/代币。
端点:POST /api/v2.0.0/config/queryAllCoinInfo
请求
请求头:
Content-Type: application/json
请求体:不需要请求体(空 POST 请求)
响应
成功响应(200 OK):
{
"code": 0,
"msg": "success",
"data": [
{
"id": 1,
"chain": "Ethereum",
"chainCode": "erc20",
"coinCode": "usdt",
"isToken": true,
"enable": true,
"contractAddress": "0xdAC17F958D2ee523a2206206994597C13D831ec7",
"coinDesc": "Tether USD",
"gateWayEnable": true,
"decimals": "6",
"nftmarket": null
}
]
}
响应字段
| 字段 | 类型 | 描述 |
|---|---|---|
id | integer | 代币标识符 |
chain | string | 代币所在的链名称 |
chainCode | string | 链代码(例如,"erc20"、"tron-trc20") |
coinCode | string | 货币代码(例如,"usdt"、"usdc")- 区分大小写 |
isToken | boolean | 是否为代币(原生币如 ETH 为 false) |
enable | boolean | 货币当前是否可用 |
contractAddress | string | 代币合约地址(原生币为 null) |
coinDesc | string | 货币描述 |
gateWayEnable | boolean | 是否启用网关支付 |
decimals | string | 货币小数位数(例如,USDT 为 "6",ETH 为 "18") |
nftmarket | string | NFT 市场(如适用) |
代码示例
- JavaScript
- Python
- cURL
const response = await fetch(
'https://testnet.hashnut.io/api/v2.0.0/config/queryAllCoinInfo',
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
}
);
const result = await response.json();
if (result.code === 0) {
const coins = result.data;
coins.forEach(coin => {
console.log(`${coin.coinCode} on ${coin.chain}: ${coin.contractAddress || 'Native'}`);
});
}
import requests
response = requests.post(
'https://testnet.hashnut.io/api/v2.0.0/config/queryAllCoinInfo',
headers={'Content-Type': 'application/json'}
)
result = response.json()
if result['code'] == 0:
for coin in result['data']:
address = coin['contractAddress'] or 'Native'
print(f"{coin['coinCode']} on {coin['chain']}: {address}")
curl -X POST 'https://testnet.hashnut.io/api/v2.0.0/config/queryAllCoinInfo' \
-H 'Content-Type: application/json'
按链代码查询支持的代币
查询特定链上支持的所有货币/代币。
端点:POST /api/v2.0.0/config/querySupportCoinsByChainCode
请求
请求头:
Content-Type: application/json
请求体:
{
"chainCode": "erc20"
}
请求参数
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
chainCode | string | ✅ 是 | 链代码(例如,"erc20"、"bsc-erc20"、"polygon-erc20"、"tron-trc20") |
响应
成功响应(200 OK):
{
"code": 0,
"msg": "success",
"data": [
{
"id": 2,
"chain": "Ethereum",
"chainCode": "erc20",
"coinCode": "usdc",
"isToken": true,
"enable": true,
"contractAddress": "0x4ca772bb3e6326647b8dd02ddbc758773aa7c650",
"coinDesc": "USD Coin",
"gateWayEnable": true,
"decimals": "6",
"nftmarket": "opensea"
}
]
}
响应格式与 queryAllCoinInfo 相同,但按 chainCode 过滤。
代码示例
- JavaScript
- Python
- cURL
const response = await fetch(
'https://testnet.hashnut.io/api/v2.0.0/config/querySupportCoinsByChainCode',
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
chainCode: 'erc20'
})
}
);
const result = await response.json();
if (result.code === 0) {
const coins = result.data;
console.log(`Supported coins on ERC-20: ${coins.map(c => c.coinCode).join(', ')}`);
}
import requests
response = requests.post(
'https://testnet.hashnut.io/api/v2.0.0/config/querySupportCoinsByChainCode',
headers={'Content-Type': 'application/json'},
json={'chainCode': 'erc20'}
)
result = response.json()
if result['code'] == 0:
coins = result['data']
coin_codes = [c['coinCode'] for c in coins]
print(f"Supported coins on ERC-20: {', '.join(coin_codes)}")
curl -X POST 'https://testnet.hashnut.io/api/v2.0.0/config/querySupportCoinsByChainCode' \
-H 'Content-Type: application/json' \
-d '{
"chainCode": "erc20"
}'
使用场景
动态链选择
使用 queryAllChainInfo 来:
- 向用户显示可用链
- 在创建订单之前检查链是否启用
- 获取链特定配置(确认数、chainId 等)
动态代币选择
使用 queryAllCoinInfo 或 querySupportCoinsByChainCode 来:
- 为所选链显示可用代币
- 在创建订单之前验证代币可用性
- 获取代币合约地址以进行钱包集成
- 检查代币小数位数以进行金额计算
集成示例
// 获取可用链
const chainsResponse = await fetch(
'https://testnet.hashnut.io/api/v2.0.0/config/queryAllChainInfo',
{ method: 'POST', headers: { 'Content-Type': 'application/json' } }
);
const chains = (await chainsResponse.json()).data;
// 获取所选链的代币
const selectedChain = chains.find(c => c.chainCode === 'erc20');
const tokensResponse = await fetch(
'https://testnet.hashnut.io/api/v2.0.0/config/querySupportCoinsByChainCode',
{
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ chainCode: selectedChain.chainCode })
}
);
const tokens = (await tokensResponse.json()).data;
// 现在可以使用验证过的链和代币创建订单
下一步
需要帮助? 查看故障排除 →