跳到主要内容

配置端点

查询支持的区块链网络、代币和平台配置。

查询所有链信息

查询所有支持的区块链网络及其配置。

端点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
}
]
}

响应字段

字段类型描述
idinteger链标识符
chainstring链名称(例如,"Ethereum"、"BSC")
chainDescstring链描述
enableboolean链当前是否启用
receiptAddressstringHashNut 平台在此链上的接收地址
txConfirmCountstring交易所需的确认数
walletConnectEnableboolean是否支持 WalletConnect
bridgeServerAddressstringWalletConnect 桥接服务器地址
decimalsinteger基础货币小数位数(例如,ETH 为 18)
baseChainSymbolstring基础链符号(例如,"ETH")
envinteger环境(0=生产环境,1=测试环境,2=开发环境)
chainIdstring链 ID(例如,以太坊主网为 "1")
baseChainCoinstring基础链代币符号
eip712ChainIdstringEIP-712 链 ID
eip1559Supportboolean是否支持 EIP-1559

代码示例

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'})`);
});
}

查询所有代币信息

查询所有链上支持的所有货币/代币。

端点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
}
]
}

响应字段

字段类型描述
idinteger代币标识符
chainstring代币所在的链名称
chainCodestring链代码(例如,"erc20"、"tron-trc20")
coinCodestring货币代码(例如,"usdt"、"usdc")- 区分大小写
isTokenboolean是否为代币(原生币如 ETH 为 false)
enableboolean货币当前是否可用
contractAddressstring代币合约地址(原生币为 null)
coinDescstring货币描述
gateWayEnableboolean是否启用网关支付
decimalsstring货币小数位数(例如,USDT 为 "6",ETH 为 "18")
nftmarketstringNFT 市场(如适用)

代码示例

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'}`);
});
}

按链代码查询支持的代币

查询特定链上支持的所有货币/代币。

端点POST /api/v2.0.0/config/querySupportCoinsByChainCode

请求

请求头

Content-Type: application/json

请求体

{
"chainCode": "erc20"
}

请求参数

参数类型必填描述
chainCodestring✅ 是链代码(例如,"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 过滤。

代码示例

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(', ')}`);
}

使用场景

动态链选择

使用 queryAllChainInfo 来:

  • 向用户显示可用链
  • 在创建订单之前检查链是否启用
  • 获取链特定配置(确认数、chainId 等)

动态代币选择

使用 queryAllCoinInfoquerySupportCoinsByChainCode 来:

  • 为所选链显示可用代币
  • 在创建订单之前验证代币可用性
  • 获取代币合约地址以进行钱包集成
  • 检查代币小数位数以进行金额计算

集成示例

// 获取可用链
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;

// 现在可以使用验证过的链和代币创建订单

下一步


需要帮助? 查看故障排除 →