SwapBox V2 API
SwapBox is a Intelligent Cross-chain DEX Aggregator, including native-chain Swap, cross-chain Swap, and cross-chain Bridge functionality.
Introduction
SwapBox is a Intelligent Cross-chain DEX Aggregator, including native-chain Swap, cross-chain Swap, and cross-chain Bridge functionality. SwapBox integrates multiple exchange channels to meet various user exchange needs.
This document primarily explains the Nerve relay network exchange channel. This chain facilitates cross-chain exchanges with other blockchain networks. Assets or tokens from other chains are registered on the Nerve chain and then cross-chain to the Nerve chain, where exchanges are completed through NerveSwap (AMM Swap & Multi-Routing) or directly cross-chained to the target chain via Nerve. The successfully exchanged assets are then cross-chained to the target chain's account address.
Currently, the Nerve exchange channel supports EVM-based chains and non-EVM chains, including BTC, Ethereum, BSC, Optimism, Arbitrum, Polygon, etc. More cross-chain support will be added as needed in the future.
The Nerve exchange channel allocates a chain ID (chainId) to each integrated blockchain on the Nerve chain and assigns asset IDs (assetId) to its assets and tokens. (Note: The chainId mentioned here is the chainId assigned by the Nerve chain to other integrated chains, which differs from the EVM chain's own chainId. The nativeId field in subsequent API documentation describes the EVM chain's chainId.)
Assets or tokens on each chain are considered as a type of asset, with each chain having a primary asset, such as Ethereum's ETH token. The primary asset is mainly used to pay transaction fees when assembling transactions.
We also provide the SwapBox js.sdk tool, allowing users to assemble cross-chain exchange transactions through js.sdk.
Request and Response
Domain: https://swapbox.io
RESTful access format: Add request headers:
language: en // English, cn // ChineseContent-Type: application/json;charset=UTF-8Accept: application/json
Response Format: Successful Example
{
"code": 0, // Return code, 0 indicates success, others indicate failure
"msg": "Success", // Return message
"data": { // Return data
"xxxx": xxx
}
}Error Example
API Endpoints
Get Chain Configuration
Description: Retrieve the configuration information of all supported chains in Nabox. All applications should call this API to get the chain configuration (chain information and primary asset information) and cache it locally when opening the DApp.
URL: /api/config/chains Method: GET
Parameters: None
Response: Chain Configuration List
Get Swap-able Assets List
Description: Retrieve the list of exchangeable assets supported by SwapBox for the current chain. Only the chain parameter is mandatory. To query a single asset (currency), NULS and NERVE chain assets are uniquely identified by chainId and assetId. For other chains (e.g., EVM chains), when querying the main token, set assetId to 1; for other ERC20 tokens, provide the contractAddress.
URL: /api/config/asset Method: POST
Parameters:
Response: Asset Information List
Query Exchange Route (Supports Native-Chain Swap and Cross-Chain Swap)
Description: Based on user input for chain and asset information, this endpoint routes the exchangeable paths for various channels and returns the routing information. If fromChain and toChain parameters are the same, it is an on-chain exchange.
URL: /api/swap/route
Method: POST
Parameters:
Response: List of routing channels
Create Swap Transaction (Supports Native-Chain Swap and Cross-Chain Swap)
Description: Based on user input for channel, chain, and asset information, this endpoint generates an unsigned transaction txHex for the source chain.
URL: /api/swap/tx/encode
Method: POST
Parameters:
Response: Unsigned transaction txHex
Submit Swap Order
Description
Check the legality of the chain and swap asset information based on user input and create an order.
URL
POST /api/swap/tx/save
Parameters
Response
Update Order Transaction Hash
Description
After the order is created, the front end needs to sign and broadcast the unsigned transaction txHex returned by the routing interface. After successful broadcasting, update the transaction hash to the order.
URL
POST /api/swap/tx/hash/update
Parameters
Response
Order details
Query Bridge Route (Cross-Chain Bridge)
Description
Based on the user's input for the chain and source chain asset information, query the routing paths available for the Bridge channel and return the routing information.
URL
POST /api/bridge/route
Parameters
Response
Generate Bridge Transaction (Cross-Chain Bridge)
Description
Based on the user’s input for channel information, chain details, and swap asset information, generate an unsigned transaction txHex for the source chain.
URL
POST /api/bridge/tx/encode
Parameters
Response
Submit Bridge Order
Description
Based on the user's input for the chain and swap asset information, validate the information and create an order.
URL
POST /api/bridge/tx/save
Parameters
Response
Update Order Transaction Hash
Description
After the order is created, the frontend needs to sign and broadcast the unsigned transaction txHex returned by the routing interface. Once broadcasting is successful, update the transaction hash to the order.
URL
POST /api/bridge/tx/hash/update
Parameters
Response
Query Swap and Bridge Order Transactions
Description
Query all swap and bridge order transaction records for the user, sorted in descending order by order time.
URL
POST /api/swap/txs/query
Parameters
Response
Query Swap and Bridge Order Transaction Details
Description
Query the details of a swap or bridge transaction based on the order number.
URL
POST /api/swap/tx/query
Parameters
Response
Last updated