# SwapBox V1 API

## Request and Return

### RESTFUl access format:

Add request header Content-Type: application/json;charset=UTF-8

### interface address:

[https://api.v2.nabox.io/nabox-api](https://api.v2.nabox.io/nabox-api)

### Return format:

```json
//Successful example
{
"code": 1000, //return code, 1000 means success, the rest means failure
"msg": "success", //return message
"data": { //return data
      "success": true
    }
}
//error example
{
"code": 1002,
"msg": "Language type error",
"data": null
}
```

## Interface Details

### SWAP

#### Query chain configuration

**Detailed description:** Query the swap configuration information of each chain currently supported by nabox. All applications should first call this interface to obtain the chain configuration (chain information and asset information) and cache it locally.

**Access:**

| url        | method | description                          |
| ---------- | ------ | ------------------------------------ |
| /swap/info | get    | Query swap configuration information |

**parameters:** none

**return:**

```
{
"chain": "Ethereum", //chain name
"evmChainId": 1, //evm_id of the chain
"chainId": 101, //The chain id assigned to the current chain by the nerve cross-chain system
"chainType": 2, //chain type: 1: NERVE chain, 2: EVM chain

"configs": { //Other configuration of the chain
    "multiCallAddress": "0x6899aa135037a4c8a3cab11622d35cea4cd63747",
    //Batch query contract address
    "crossAddress": "0xc707e0854da2d72c90a7453f8dc224dd937d7e82",
    //Intermediate account for cross-chain swap
    "nft": "eth" //Whether NFT is supported
},

"stableSwapAssetList": [ //The token list of stablecoin sawp
  {
    "chain": "Ethereum", //The chain to which the asset belongs
    "chainId": 101, //The chain id of the chain to which the asset belongs corresponds to the nerve cross-chain system
    "assetId": 0, //The asset id assigned to the asset by the nerve chain, the token assetId=1 of each chain,
    "contractAddress": "0xdac17f958d2ee523a2206206994597c13d831ec7",
    //token's contract address
    "decimals": 6, //asset decimal places
    "symbol": "USDT",
    "channelInfo": { // asset-backed swap channel information
        "iSwap": { //iswap channel information
            "code": [
                "BIG", // large amount exchange
                "BRG", //large cross-chain bridge
                "SWP" //Ordinary exchange
            ],
            "token": "USDT"
        },
        "NERVE": { //NERVE stable currency exchange channel information
            "pairAddress": "NERVEepb7WDfEU4ZKsEFmwCfGwCaYWgdHgk5tW",
                             //Stablecoin trading pair contract address
            "coinIndex": 0, //The index corresponding to the current asset
            "lpChainId": 9, //The chain id corresponding to the lp asset on the nerve chain
            "lpAssetId": 220 //The asset id corresponding to the lp asset on the nerve chain
        }
    }
  }
]
      
```

#### Query order details

**Detailed description: Query the details of swap transactions initiated by swapbox through the order id**.

**access:**

| url              | method | description                    |
| ---------------- | ------ | ------------------------------ |
| /swap/tx/orderId | post   | Query swap transaction details |

**parameter:**

| Parameter Name | Type   | Required | Description                     |
| -------------- | ------ | -------- | ------------------------------- |
| language       | string | Y        | Language: EN/CHS                |
| orderId        | string | Y        | The order id of the transaction |

**return:**

```
{
    "id": 232,
    "orderId": "25172d2b-bdb9-4dd3-8698-b5e0fe34ad97", //order id
    "channel": "NERVE", //Exchange channel
    "platform": "NABOX", //Initiate the exchange platform
    "swapType": 2, //Exchange type 1: Normal exchange, 2: Stable currency exchange, 3: Large amount exchange
    "fromChain": "Heco", //Initiate the chain
    "fromAddress": "0xf8a8435f7a93c73862974e19865b7089707813F1",//Originating address
    "toChain": "BSC", //Exchange target chain
    "toAddress": "0xf8a8435f7a93c73862974e19865b7089707813F1", //target address
    "chainId": 103, //Initiate the id of the nervous distribution chain corresponding to the chain asset
    "assetId": 0, //The asset id of the originating chain asset, the value of the token is 1, and the asset of the token contract is 0
    "contractAddress": "0xa71edc38d189767582c38a3145b5873052c3e47a",
                             //The address of the token contract that initiates the chain asset
    "decimal": 18, //Initial chain asset decimal place
    "symbol": "USDT", //asset symbol
    "swapChainId": 102, //The ID of the nerve distribution chain corresponding to the target chain asset
    "swapAssetId": 0, //The asset id of the target chain asset
    "swapContractAddress": "0x55d398326f99059ff775485246999027b3197955",
                             //The token contract address of the target chain asset
    "swapDecimal": 18, //The decimal place of the target chain asset
    "swapSymbol": "USDT" //Asset symbol
         
    "txHash": "0x7ee9e904c0183ad248587ae20052ea99485762602b5077e88e3ebfe8c3d4e4f1",
                             //Initiate the transaction hash of the chain
    "nerveTxHash": "243d52b1d354fb7dbfc17b918cb0cbfe1e0441d1702b48d11c03758f96005896",
                             //The transaction hash for exchange processing on thenerve chain
    "crossTxHash": "0x72c0a9f93bd04df3f81fdfb59a8e7267e81c8df86c3d6b752b2034a5536be537",
                             //The target chain address receives the transaction hash of the exchanged currency
    "amount": "8.898993", //The amount of assets in the originating chain
    "swapSuccAmount": "8.897193", //The amount of the target chain successfully exchanged
    "swapFee": "0.001800", //The handling fee charged by the exchange (receive the exchange assets)
    "crossFee": "0.049300", //Cross-chain fee for exchange (received token of origination chain)
    "slippage": 0, //slippage
    "pairAddress": "NERVEepb7WDfEU4ZKsEFmwCfGwCaYWgdHgk5tW",
                                   //The contract address of the negotiated chain
    "status": 3, //Order status 0: Order has been generated, 1: Initiation chain transaction has been sent,
                  // 2: Initiate chain transaction has been confirmed, 3: Exchange successfully, 4: Exchange failed
    "nerveStatus": 2, //The exchange status on the nerve chain 0: not exchanged, 1: exchanged, 2: cross-chain transfer out
    "createTime": "2022-03-02 21:04:04",
    "updateTime": "2022-03-02 21:04:03",
    "errorMsg": "" //Exchange failure message
}
```

#### Query order list

**Detailed description: Query the order list through the originating address, and return the latest 10 records**.

**access:**

| url            | method | description                 |
| -------------- | ------ | --------------------------- |
| /swap/tx/query | post   | Query swap transaction list |

**parameter:**

| Parameter Name | Type   | Required | Description      |
| -------------- | ------ | -------- | ---------------- |
| language       | string | Y        | Language: EN/CHS |
| nativeId       | int    | Y        | evmChainId       |
| address        | string | Y        | User address     |

**return:**

```
{
    "code": 1000,
    "msg": "success",
    "data": [
        {
            "id": 103,
            "orderId": "7f1426ad-36b4-4786-9b01-524d4bdff4ac",
            "channel": "NERVE",
            "platform": "SWFT",
            "swapType": 2,
            "fromChain": "BSC",
            "fromAddress": "0x3083f7ed267dca41338de3401c4e054db2a1cd2f",
            "toChain": "NERVE",
            "toAddress": "TNVTdTSPVaHLGXQJDVCyNAo67zAoUcvbpeUri",
            "chainId": 102,
            "assetId": 0,
            "contractAddress": "0xd0a347e0ebea8f8efc26d539e17853c8e7a721c4",
            "decimal": 18,
            "symbol": "USDT",
            "swapChainId": 5,
            "swapAssetId": 90,
            "swapContractAddress": "",
            "swapDecimal": 6,
            "swapSymbol": "USDT",
            "txHash": "0x4e94169c2dc457dbac3af5a7d90c80eb825abf29b0414da6d2a7f2d1d42a9efe",
            "nerveTxHash": "0929249e710c203851a4f723a8d2774dc4d0fb9ecdcebbd058e6cbc82051372e",
            "crossTxHash": "0x4c07ee6e235af2e4cbb95d6a459fe37e365c71de55563036c78d90fef856d675",
            "amount": "100",
            "swapSuccAmount": "99.9500",
            "swapFee": "0.05",
            "crossFee": "0.0001",
            "slippage": 0,
            "pairAddress": "TNVTdTSQoL9quSyGJCA9sY8pcMEVy4RN4EjbB",
            "status": 3,
            "nerveStatus": 2,
            "createTime": "2022-03-09 14:18:12",
            "updateTime": "2022-03-23 ​​14:27:20",
            "errorMsg": ""
        },
        {
            "id": 102,
            "orderId": "90c9784a-8ce9-4271-8c0b-037ac7fd918d",
            "channel": "NERVE",
            "platform": "SWFT",
            "swapType": 2,
            "fromChain": "BSC",
            "fromAddress": "0x3083f7ed267dca41338de3401c4e054db2a1cd2f",
            "toChain": "NERVE",
            "toAddress": "TNVTdTSPVaHLGXQJDVCyNAo67zAoUcvbpeUri",
            "chainId": 102,
            "assetId": 0,
            "contractAddress": "0xd0a347e0ebea8f8efc26d539e17853c8e7a721c4",
            "decimal": 18,
            "symbol": "USDT",
            "swapChainId": 5,
            "swapAssetId": 90,
            "swapContractAddress": "",
            "swapDecimal": 6,
            "swapSymbol": "USDT",
            "txHash": "0xb94eaeb65630d536a2313f6bea20ccf6f2eb735dd20e2f65c15a972fb5b6379d",
            "nerveTxHash": "e62cba9f464d5fca04d90f0280bbbe763eb148255ef2c41b8788ef6c8c744e94",
            "crossTxHash": "0x68a8c10c638d4412a8638e1a0799584facfa7eccad1b3a2581ed760af1089260",
            "amount": "100",
            "swapSuccAmount": "99.9500",
            "swapFee": "0.05",
            "crossFee": "0.0001",
            "slippage": 0,
            "pairAddress": "TNVTdTSQoL9quSyGJCA9sY8pcMEVy4RN4EjbB",
            "status": 3,
            "nerveStatus": 2,
            "createTime": "2022-03-09 14:14:32",
            "updateTime": "2022-03-23 ​​14:27:20",
            "errorMsg": ""
        }
```
