# Basic information

> This document is mainly used to explain endpoints usage, illustrate with code examples for requesting endpoints, specific interface input parameters and output parameter information

### Important notice

{% hint style="info" %}
The request code examples in this document are using Axios
{% endhint %}

{% embed url="<https://www.npmjs.com/package/axios>" %}

#### LOGO: <https://images.bridgers.xyz/dex/bridgers1.png>

### Contract Address

{% hint style="info" %}
Currently Bridgers supports any currency exchange that has been supported on the 49 listed chains. The following are the contract addresses of each chain
{% endhint %}

1. eth mainnet contract address：0xc1d13492285eb664951E201BF7C80c7c6318a1b5
2. bsc mainnet contract address：0xc1d13492285eb664951E201BF7C80c7c6318a1b5
3. polygon mainnet contract address：0xc1d13492285eb664951E201BF7C80c7c6318a1b5
4. heco mainnet contract address：0xaeAE2CBb1E024E27e80cc61eE9A8B300282209B4
5. oec mainnet contract address：0xb685760ebd368a891f27ae547391f4e2a289895b
6. tron mainnet contract address：TJ4KeiGTvTX4wRUgLARiwr8rGLaurmVkdZ
7. fantom mainnet contract address：0xb685760ebd368a891f27ae547391f4e2a289895b
8. arbitrum mainnet contract address:  0xc1d13492285eb664951E201BF7C80c7c6318a1b5
9. avalanche mainnet contract address:  0xc1d13492285eb664951E201BF7C80c7c6318a1b5
10. optimism mainnet contract address:  0xc1d13492285eb664951E201BF7C80c7c6318a1b5
11. cronos mainnet contract address:  0x332fae8fa47941305e5de262ae3587ad6dca0a78
12. solana mainnet contract address: FDF8AxHB8UK7RS6xay6aBvwS3h7kez9gozqz14JyfKsg
13. aptos mainnet contract address: 0x3a73feb4921e11fa52f9916fa993a60912a63aa8f631d64aefda7f71b6bf34a6
14. sui mainnet contract address: 0x2b0876f0b7034320ad6d2f378501fe92e41c8b4780bda7769094d2431170e532
15. BASE mainnet contract address：0xa18968cc31232724f1dbd0d1e8d0b323d89f3501
16. opBNB mainnet contract address：0x8f957ed3f969d7b6e5d6df81e61a5ff45f594dd1
17. ZKSYNC mainnet contract address：0x2042ecdc71f9ffb2eb9cda7f801eccc5c6c8b7eb
18. CFX mainnet contract address：0x8f957ed3f969d7b6e5d6df81e61a5ff45f594dd1
19. mantle mainnet contract address：0xd1088d3376c2384d469d1c0d55d503695e1be3e6
20. CORE mainnet contract address：0x8159891dfe9de7fc3bf1b665eb1adda60f2acd0e
21. LINEA mainnet contract address：0x8159891dfe9de7fc3bf1b665eb1adda60f2acd0e
22. zkEVM mainnet contract address：0x8f957ed3f969d7b6e5d6df81e61a5ff45f594dd1
23. SCROLL mainnet contract address：0x8f957ed3f969d7b6e5d6df81e61a5ff45f594dd1
24. TON mainnet contract address: EQCqTuPS-cMN9SSRhaFrwJOGL7dKkFF8C0a05g2WzI9uRJ19
25. Merlin mainnet contract address: 0x8159891dfe9de7fc3bf1b665eb1adda60f2acd0e
26. Onchain mainnet contract address: 0x8159891dfe9de7fc3bf1b665eb1adda60f2acd0e
27. CELO mainnet contract address: 0xd1088d3376c2384d469d1c0d55d503695e1be3e6
28. XLayer mainnet contract address: 0xd1088d3376c2384d469d1c0d55d503695e1be3e6
29. Blast mainnet contract address: 0xd1088d3376c2384d469d1c0d55d503695e1be3e6
30. APE mainnet contract address: 0xd1088d3376c2384d469d1c0d55d503695e1be3e6
31. XRP mainnet contract address: rM27yzkCw6WA3T4g1sPaeC1kpxHUhuxRWn
32. BTC mainnet address: bc1q7t4vyehjsexdme84qhdgd4dawcn54djh0m78fz
33. DOGE mainnet address: DNqWDenhxgWTfy2bpJn4tES6uMwz1nqt6C
34. LTC mainnet address: ltc1q0sc0myh0a2wap7eshhyz2ahc2xdn86g7fv32r2
35. BCH mainnet address: qq9ndmhw4dyxfc2cy5czth9gwq7xmu7evvjudqj8lt
36. COSMOS mainnet address: cosmos12kvp0fgulyd9glnq8cj8t9f62amtdeaeh2zxl8
37. ETHF mainnet contract address: 0x89a70b162be7dbc8b5e7579066fa58190c48d693
38. Sonic mainnet contract address: 0x89a70b162be7dbc8b5e7579066fa58190c48d693
39. BERA mainnet contract address: 0x89a70b162be7dbc8b5e7579066fa58190c48d693
40. Unichain mainnet contract addres：0x89A70b162bE7dBc8b5e7579066fA58190C48d693
41. HyperEVM mainnet contract addres：0x89A70b162bE7dBc8b5e7579066fA58190C48d693
42. Morph mainnet contract addres：0x89A70b162bE7dBc8b5e7579066fA58190C48d693
43. MONAD mainnet contract addres：0x89A70b162bE7dBc8b5e7579066fA58190C48d693
44. ENI mainnet contract addres：0x89A70b162bE7dBc8b5e7579066fA58190C48d693
45. Kasplex mainnet contract addres：0xf1c930a6c26c2672e98a4170bb8148c9eadedc96
46. Robinhood mainnet contract addres：0x89A70b162bE7dBc8b5e7579066fA58190C48d693
47. BOTCHAIN mainnet contract addres：0x89A70b162bE7dBc8b5e7579066fA58190C48d693
48. Anubis mainnet contract addres：0x89A70b162bE7dBc8b5e7579066fA58190C48d693
49. ARC mainnet contract addres：0x89A70b162bE7dBc8b5e7579066fA58190C48d693


# Swap procedure

flow chart

{% hint style="info" %}
Note: There are two ways to obtain calldata data in step 17. One is that the frontend directly generates calldata data by requesting the smart contract, and the other is that calldata data is obtained by requesting the endpoint. For details, please refer to \[Obtain callData]
{% endhint %}

<figure><img src="https://1371637894-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBjj3xwD1ODc9uBxuQrlr%2Fuploads%2FKt6LTB0m0RtKRGy31eKk%2Ftelegram-cloud-photo-size-5-6127483056860893631-y.jpg?alt=media&amp;token=bf56d41e-9a0e-4777-adca-1fe610790dad" alt=""><figcaption></figcaption></figure>


# status code

### 1. The request method is POST, application/json

### 2. Status code description:

| code | description                                                                                                           |
| ---- | --------------------------------------------------------------------------------------------------------------------- |
| 101  | required parameter is empty                                                                                           |
| 102  | invalid parameter                                                                                                     |
| 103  | invalid address                                                                                                       |
| 104  | amount should be a valid number string                                                                                |
| 105  | Same currency cannot be exchanged                                                                                     |
| 106  | token does not exist                                                                                                  |
| 107  | This fromToken does not support exchange yet                                                                          |
| 108  | This toToken does not support exchange yet                                                                            |
| 109  | target address is not support coin contract address                                                                   |
| 110  | target address is not support contract address                                                                        |
| 111  | The fromToken or toToken is not available for exchange yet                                                            |
| 411  | Insufficient account balance                                                                                          |
| 412  | quote fail                                                                                                            |
| 413  | swap fail                                                                                                             |
| 414  | fail:updated, please do not update again！                                                                             |
| 415  | query fail                                                                                                            |
| 777  | Frequent operations, please try again later                                                                           |
| 906  | System exceptions                                                                                                     |
| 907  | Forbidden Request                                                                                                     |
| 908  | No authorization                                                                                                      |
| 999  | Service Internal Error                                                                                                |
| 1114 | Birdgers does not provide services for your current country/region                                                    |
| 1145 | There are risks in the target address, refund address or IP. Please change to other addresses and IPs for redemption. |
| 1146 | The XRP address does not activate the token                                                                           |


# Get coins list

Get the list of currencies supported on Bridgers

### Endpoint usage

<mark style="color:green;">`POST`</mark> `https://api.bridgers.xyz/api/exchangeRecord/getToken`

|       |        |                                                                                                                                                                                                                                                                                                                                                      |
| ----- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Name  | Type   | Description                                                                                                                                                                                                                                                                                                                                          |
| chain | String | Chain names: ETH,BSC,POLYGON,HECO,OKEXCHAIN,TRON,TRX,FANTOM,ARBITRUM,AVALANCHE,OPTIMISM,CRONOSSOLANA,APT,ZKSYNC,MNT,CORE,SUI,CFX,BASE,opBNB,zkEVM,SCROLL,LINEA,Blast,Merlin,Onchain,CELO,TON,XLayer,APE,XRP,BTC,DOGE,LTC,BCH,COSMOS,DASH,ETHF,Sonic,BERA,Unichain,HyperEVM,Morph,MONAD,ENI,Kasplex,Robinhood,MegaETH,BOTCHAIN,Anubis,Stable,ARC,etc. |

{% tabs %}
{% tab title="200: OK " %}

```javascript
{
  "resCode":"100",
  "resMsg":"Success",
  "data":{
      "tokens":[{"chain":"ETH","symbol":"USDT","name":"Tether USD","address":"0xdac17f958d2ee523a2206206994597c13d831ec7","decimals":6,"logoURI":"https://images.swft.pro/inch1/0xdac17f958d2ee523a2206206994597c13d831ec7.png","isCrossEnable":"1","withdrawGas":"40"},{"chain":"BSC","symbol":"USDT","name":"Tether USD","address":"0x55d398326f99059ff775485246999027b3197955","decimals":18,"logoURI":"https://images.swft.pro/inch1/0xdac17f958d2ee523a2206206994597c13d831ec7.png","isCrossEnable":"1","withdrawGas":"0.1"},{"chain":"HECO","symbol":"USDT","name":"Heco-Peg USDTHECO Token","address":"0xa71edc38d189767582c38a3145b5873052c3e47a","decimals":18,"logoURI":"https://images.swft.pro/heco/0xa71edc38d189767582c38a3145b5873052c3e47a.png","isCrossEnable":"1","withdrawGas":"0.1"},{"chain":"POLYGON","symbol":"USDT","name":"USDT(MATIC)","address":"0xc2132d05d31c914a87c6611c10748aeb04b58e8f","decimals":6,"logoURI":"https://swap.swftcoin.com/swft-v3/images/coins/USDT(MATIC).png","isCrossEnable":"1","withdrawGas":"0.1"},{"chain":"OKEXCHAIN","symbol":"USDT","name":"USDT","address":"0x382bb369d343125bfb2117af9c149795c6c65c50","decimals":18,"logoURI":"https://www.cherryswap.net/swapimages/images/coins/0x382bb369d343125bfb2117af9c149795c6c65c50.png","isCrossEnable":"1","withdrawGas":"0.1"}]
  }
}
```

{% endtab %}
{% endtabs %}

### Code example

{% tabs %}
{% tab title="JavaScript" %}

```
// getToken example
const res = await axios.post('https://api.bridgers.xyz/api/exchangeRecord/getToken')
console.log(res)
```

{% endtab %}
{% endtabs %}

### Postman example

![](https://1371637894-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBjj3xwD1ODc9uBxuQrlr%2Fuploads%2F8Pw5hoCmE7BvlKgk86yK%2F1.jpg?alt=media\&token=16c60bce-bed1-4b80-a2a1-86472896b569)


# Request quote

Provide a quote inquiry endpoint for users to inform users of currency transaction information and currency exchange range.

### Note

{% hint style="info" %}
Note: If the value filled in by the user is outside the convertible range, in order to avoid user losses, please remind the user to change the swap value
{% endhint %}

### Endpoint usage

<mark style="color:green;">`POST`</mark> `https://api.bridgers.xyz/api/sswap/quote`

**The fields with \* are required, and the fields without \* are optional**

#### Request Body

| Name                                               | Type    | Description                                                                                                                                                                                                                    |
| -------------------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| equipmentNo<mark style="color:red;">\*</mark>      | String  | Equipment number(This field will be used as the unique identifier of the user, and the third parties can obtain it on their own, such as the first 32 characters of fromAddress, or a string of 32 random numbers and letters) |
| sourceType                                         | String  | Device type  (H5/IOS/Android The field is optional, if it is requested directly through the API, it can be empty)                                                                                                              |
| sourceFlag<mark style="color:red;">\*</mark>       | String  | Source channel (Both sides need to agree on a name to represent the channel of the third parties)                                                                                                                              |
| fromTokenAddress<mark style="color:red;">\*</mark> | String  | Contract address for the token to sell (It can be obtained from the address field in the currency list)                                                                                                                        |
| toTokenAddress<mark style="color:red;">\*</mark>   | String  | Contract address for the token to receive   (It can be obtained from the address field in the currency list)                                                                                                                   |
| fromTokenAmount<mark style="color:red;">\*</mark>  | String  | Amount of token to sell                                                                                                                                                                                                        |
| fromTokenChain<mark style="color:red;">\*</mark>   | String  | Network of the token to sell (It can be obtained from the chain field in the currency list, For details of the support chain, please refer to \[Basic information])                                                            |
| toTokenChain<mark style="color:red;">\*</mark>     | String  | Network of the token to received (It can be obtained from the chain field in the currency list, For details of the support chain, please refer to \[Basic information])                                                        |
| userAddr                                           | String  | User address                                                                                                                                                                                                                   |
| fixedRateFlag                                      | Integer | Flag to toggle fixed rate mode. 1 = Enable, 0 = Disable. Default: 0                                                                                                                                                            |

{% tabs %}
{% tab title="200: OK " %}

```javascript
{
 "resCode":"100",
 "resMsg":"Success",
 "data":{
  "txData":{
   "amountOutMin": "5055580656532273000"// Expected amount received (WEI version)
   "chainFee":"0.02" // Gas fee
   "contractAddress":"0x6b4427caa371627e2a73521a2568fcf1212cd4d9", // Contract Address
   "depositMin": "30", // minimum swap value
   "depositMax": "21738659651027.298142", // maximum swap value
   "dex":"Bridgers1",
   "fee":0.002, // Processing fee ratio 
   "feeToken":"",
   "fromTokenAmount":"47079490000000000000",
   "fromTokenDecimal":18,
   "toTokenAmount":"5.0555806565",  // Expected amount received
   "toTokenDecimal":18,
   "path":["0x55d398326f99059ff775485246999027b3197955","0x6b4427caa371627e2a73521a2568fcf1212cd4d9","0xa71edc38d189767582c38a3145b5873052c3e47a"],
   "logoUrl":"https://images.bridgers.xyz/dex/sSwap.png",
   "recommendedSlippage":0.02,//Suggested slippage Settings
  }
 }
}
```

{% endtab %}

{% tab title="500: Internal Server Error " %}

```javascript
{
    // Response
}
```

{% endtab %}
{% endtabs %}

### Code example

{% tabs %}
{% tab title="JavaScript" %}

```
// quote example
 const params = {
   fromTokenAddress: '0x55d398326f99059ff775485246999027b3197955',
   toTokenAddress: '0xa71edc38d189767582c38a3145b5873052c3e47a',
   fromTokenAmount: '8000000000000000000',
   fromTokenChain: 'BSC',
   toTokenChain: 'HECO',
   userAddr: '0x...', //your wallet address
   equipmentNo:'', // your equipment number
   sourceFlag:'widget',
   sourceType:'H5',
  }
  const res = await axios.post('https://api.bridgers.xyz/api/sswap/quote',params)
  console.log(res)
```

{% endtab %}
{% endtabs %}

### Postman example

![](https://1371637894-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBjj3xwD1ODc9uBxuQrlr%2Fuploads%2F5h2ISInwdvKS7Cd9c2Ek%2F2.jpg?alt=media\&token=146fa8e7-0559-467b-b7ef-5f2821953a9b)


# Contract approval

Network tokens need to grant permission to the contract first to be able to exchange on the contract

## 1. EVM Chain

{% hint style="info" %}
This example uses the BSC chain USDT to apprive the contract 0xb685760ebd368a891f27ae547391f4e2a289895b
{% endhint %}

### abi File

{% file src="/files/j1jyiIq1s5lfckPRFW7d" %}

### Determine whether to approve and if gas is sufficient

```
// isApproved example
// USDT(BSC)  0x55d398326f99059ff775485246999027b3197955
 import { ethers } from "ethers";
 import abi from './abi'  // For details on the abi file, see the BridgersAbi.json file above
 import BigNumber from 'bignumber.js'

 const walletAddress = '0x6F14653a91AC36935bdB15db6ccC66dC57593653' // wallet address
 const contractAddress = '0x733dab9e78b67e1d4ccd1c2066f006d5eddf25be' //contract address
 const tokenContract = '0x55d398326f99059ff775485246999027b3197955' //token contract
 const provider = new ethers.providers.Web3Provider(window.ethereum, "any")
 const contract = new ethers.Contract(tokenContract, abi, provider)
 const fromNumber = 100 // 100 as a comparison quantity
 contract
  .allowance(walletAddress, contractAddress)
  .then((allowAmt) => {
    const num = new BigNumber(
     ethers.utils.formatUnits(allowAmt, 18),
    )
    const fromTokenNum = new BigNumber(fromNumber)
    console.log(num.toString())
    console.log(fromTokenNum.toString())
    if (num.gt(fromTokenNum)) {
        console.log('don`t need Approved')
    } else {
        console.log('need Approved')
    }
  })
  .catch( err => {
    //console.log(err)
  })
```

### approval code example

```
// Approved example
// USDT(BSC)  0x55d398326f99059ff775485246999027b3197955
 import { ethers } from "ethers";
 import abi from './abi'
 import BigNumber from 'bignumber.js'
 
 const walletAddress = '0x6F14653a91AC36935bdB15db6ccC66dC57593653' // wallet address
 const contractAddress = '0x733dab9e78b67e1d4ccd1c2066f006d5eddf25be' //contract address
 const tokenContract = '0x55d398326f99059ff775485246999027b3197955' //token contract
 const provider = new ethers.providers.Web3Provider(window.ethereum, "any")
 const signer = provider.getSigner()
 const contract = new ethers.Contract(tokenContract, abi, provider)
 contract.estimateGas
   .approve(contractAddress, ethers.constants.MaxUint256, {
     from: walletAddress,
   }).then(res => {
     contract.connect(signer)
       .approve(contractAddress, ethers.constants.MaxUint256, {
         from: walletAddress,
       })
       .then((res) => {
          console.log('user Approved ')
        })
       .catch((error) => {
          console.log('user cancle Approved ')
       })
  })
 let filter = contract.filters.Approval(
   walletAddress,
   contractAddress,
   null,
 )
 contract.on(filter, (from, to, amount, event) => {
   console.log('Approve success')
 })
```

## 2、TRON Chain

{% hint style="info" %}
This example uses the TRON chain USDT to apprive the contract TEorZTZ5MHx8SrvsYs1R3Ds5WvY1pVoMSA
{% endhint %}

### Determine whether to approve and if gas is sufficient

```
// isApproved example
// USDT(TRON)  TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t
 import { ethers } from "ethers";
 import BigNumber from 'bignumber.js'
 
const walletAddress = 'TV6MuMXfmLbBqPZvBHdwFsDnQeVfnmiuSi' // wallet address
const contractAddress = 'TEorZTZ5MHx8SrvsYs1R3Ds5WvY1pVoMSA' //contract address
const tokenContract = 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t' //token contract
const fromNumber = 100 // 100 as a comparison quantity

let tronWeb = window.tronWeb
const contract = await tronWeb.contract().at(tokenContract );
const allowance = contract.allowance(walletAddress , contractAddress)
const allowAmt = await allowance.call()
const num = new BigNumber(
  ethers.utils.formatUnits(allowAmt, 6 ),
)
const fromTokenNum = new BigNumber(fromNumber)
console.log(num.toString())
console.log(fromTokenNum.toString())
if (num.gt(fromTokenNum)) {
   console.log('don`t need Approved')
} else {
  console.log('need Approved')
}
```

### approval code example

```
// Approved example
// USDT(TRON)  TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t
 import { ethers } from "ethers";
 import BigNumber from 'bignumber.js'
 
 const walletAddress = 'TV6MuMXfmLbBqPZvBHdwFsDnQeVfnmiuSi' // wallet address
 const contractAddress = 'TEorZTZ5MHx8SrvsYs1R3Ds5WvY1pVoMSA' //contract address
 const tokenContract = 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t' //token contract
const contract = await tronWeb.contract().at(tokenContract);
contract.approve(contractAddress , ethers.constants.MaxUint256).send().then( (hash)=> {
    console.log('user Approved',hash)
    tronWeb.trx.getTransaction(hash).then((result) => {
      console.log('Approve success',result)
    })
}).catch(err => {
  console.log('user cancle Approved')
 })
```

### send coins code example

```
  const tronWeb = window.tronWeb
    const transaction = await tronWeb.transactionBuilder.triggerSmartContract(
      response.data.txData.tronRouterAddrees,  // From [Obtain callData] SWAP interface in the module to obtain the tronRouterAddrees field
      response.data.txData.functionName,  // From [Obtain callData] SWAP interface in the module to obtain the functionName field
      response.data.txData.options,// From [Obtain callData] SWAP interface in the module to obtain the options field
      response.data.txData.parameter,// From [Obtain callData] SWAP interface in the module to obtain the parameter field
      response.data.txData.fromAddress// From [Obtain callData] SWAP interface in the module to obtain the fromAddress field
    )
    let signedTx
    try{
      signedTx = await tronWeb.trx.sign(transaction.transaction)
    }catch{
      console.log("Signing failed")
    }
    tronWeb.trx.sendRawTransaction(signedTx)
    .then((broastTx) => {
      console.log(broastTx)
    }).catch( error => {
       console.log("Failed to send coins")
    })
```


# Obtain callData

Request endpoint to initiate the swap

### Note

> Before the swap, wallet address needs to confirm that FROM currency token approves the contract address. The contract address can be fetched by requesting the endpoint

## Method 1: Endpoint usage

<mark style="color:green;">`POST`</mark> `https://api.bridgers.xyz/api/sswap/swap`

**The fields with \* are required, and the fields without \* are optional**

#### Request Body

| Name                                               | Type    | Description                                                                                                                                                                                                                      |
| -------------------------------------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| equipmentNo<mark style="color:red;">\*</mark>      | String  | Equipment number  (This field will be used as the unique identifier of the user, and the third parties can obtain it on their own, such as the first 32 characters of fromAddress, or a string of 32 random numbers and letters) |
| sourceType                                         | String  | Device type (H5/IOS/Android The field is optional, if it is requested directly through the API, it can be empty)                                                                                                                 |
| sourceFlag<mark style="color:red;">\*</mark>       | String  | Source channel (Both sides need to agree on a name to represent the channel of the third parties)                                                                                                                                |
| fromTokenAddress<mark style="color:red;">\*</mark> | String  | Contract address for the token to sell  (It can be obtained from the address field in the currency list)                                                                                                                         |
| toTokenAddress<mark style="color:red;">\*</mark>   | String  | Contract address for the token to receive  (It can be obtained from the address field in the currency list)                                                                                                                      |
| fromAddress<mark style="color:red;">\*</mark>      | String  | User address                                                                                                                                                                                                                     |
| toAddress<mark style="color:red;">\*</mark>        | String  | receiving Address                                                                                                                                                                                                                |
| fromTokenChain<mark style="color:red;">\*</mark>   | String  | Network of the token to sell  (It can be obtained from the chain field in the currency list, For details of the support chain, please refer to \[Basic information])                                                             |
| toTokenChain<mark style="color:red;">\*</mark>     | String  | Network of the token to received  (It can be obtained from the chain field in the currency list, For details of the support chain, please refer to \[Basic information])                                                         |
| fromTokenAmount<mark style="color:red;">\*</mark>  | String  | Amount of token to sell (with precision, which can be obtained through the fromTokenAmount field in the quote endpoint)                                                                                                          |
| amountOutMin<mark style="color:red;">\*</mark>     | String  | Expected amount received (with precision, which can be obtained through the amountOutMin field in the quote endpoint)                                                                                                            |
| fromCoinCode<mark style="color:red;">\*</mark>     | String  | Token name for sell token  (It can be obtained from the symbol field in the currency list)                                                                                                                                       |
| toCoinCode<mark style="color:red;">\*</mark>       | String  | Token name for receive token  (It can be obtained from the symbol field in the currency list)                                                                                                                                    |
| slippage                                           | String  | <p>e.g. '0.1' (<strong>meaning 10%</strong>)<br>Minimum amount received = amountOutMin \* (1 - slippage)</p>                                                                                                                     |
| fixedRateFlag                                      | Integer | Flag to toggle fixed rate mode. 1 = Enable, 0 = Disable. Default: 0                                                                                                                                                              |

{% tabs %}
{% tab title="200: OK EVM chain and Tron chain return value" %}

```javascript
{
 "resCode":"100",
 "resMsg":"Success",
 "data":{
  "txData":{
   "data":"0x...", //交易calldata
   "to": "0x6b4427caa371627e2a73521a2568fcf1212cd4d9", //合约地址Contract Address
   "value":"0x2dd47b4d9a4000"
  }
 }
}
```

{% endtab %}

{% tab title="200: OK Solana chain return value" %}

```json
// Returned value: tx, signer 
   signer field only exists when deposit SOL assets
   tx field only exists when deposit tokens 
// tx is Signature Data, signer is an additional signature required by SOL to sign the data
{
    "resCode": 100,
    "resMsg": "Success",
    "data": {
        "txData": {
            "tx": [ // tx is Signature Data
                {
                    "keys": [
                        {
                            "pubkey": "5WtTutYKy6XtVS6FH8VAxHPYTtzKB1rq7LfPR8ySCvW6",
                            "isSigner": true,
                            "isWritable": true
                        },
                        {
                            "pubkey": "Ekg1SKxB61NMwpaccj1Y88mzyH2QKoaGCVnDUZZ3WXc5",
                            "isSigner": true,
                            "isWritable": true
                        }
                    ],
                    "programId": "11111111111111111111111111111111",
                    "data": [
                        0,
                        0,
                        0,
                        0,
                        240,
                        29,
                        31,
                        0,
                        0,
                        0,
                        0,
                        0,
                        165,
                        0,
                        0,
                        0,
                        0,
                        0,
                        0,
                        0,
                        6,
                        221,
                        246,
                        225,
                        215,
                        101,
                        161,
                        147,
                        217,
                        203,
                        225,
                        70,
                        206,
                        235,
                        121,
                        172,
                        28,
                        180,
                        133,
                        237,
                        95,
                        91,
                        55,
                        145,
                        58,
                        140,
                        245,
                        133,
                        126,
                        255,
                        0,
                        169
                    ]
                },
                {
                    "keys": [
                        {
                            "pubkey": "5WtTutYKy6XtVS6FH8VAxHPYTtzKB1rq7LfPR8ySCvW6",
                            "isSigner": true,
                            "isWritable": true
                        },
                        {
                            "pubkey": "Ekg1SKxB61NMwpaccj1Y88mzyH2QKoaGCVnDUZZ3WXc5",
                            "isSigner": false,
                            "isWritable": true
                        }
                    ],
                    "programId": "11111111111111111111111111111111",
                    "data": [
                        2,
                        0,
                        0,
                        0,
                        0,
                        202,
                        154,
                        59,
                        0,
                        0,
                        0,
                        0
                    ]
                },
                {
                    "keys": [
                        {
                            "pubkey": "Ekg1SKxB61NMwpaccj1Y88mzyH2QKoaGCVnDUZZ3WXc5",
                            "isSigner": false,
                            "isWritable": true
                        },
                        {
                            "pubkey": "So11111111111111111111111111111111111111112",
                            "isSigner": false,
                            "isWritable": false
                        },
                        {
                            "pubkey": "5WtTutYKy6XtVS6FH8VAxHPYTtzKB1rq7LfPR8ySCvW6",
                            "isSigner": false,
                            "isWritable": false
                        },
                        {
                            "pubkey": "SysvarRent111111111111111111111111111111111",
                            "isSigner": false,
                            "isWritable": false
                        }
                    ],
                    "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
                    "data": [
                        1
                    ]
                },
                {
                    "keys": [
                        {
                            "pubkey": "Ekg1SKxB61NMwpaccj1Y88mzyH2QKoaGCVnDUZZ3WXc5",
                            "isSigner": false,
                            "isWritable": true
                        },
                        {
                            "pubkey": "5WtTutYKy6XtVS6FH8VAxHPYTtzKB1rq7LfPR8ySCvW6",
                            "isSigner": true,
                            "isWritable": false
                        },
                        {
                            "pubkey": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
                            "isSigner": false,
                            "isWritable": false
                        },
                        {
                            "pubkey": "H71KjNoguKbjSP5uwi8LnR3Huh6pGte6rc3DtxrUzmQB",
                            "isSigner": false,
                            "isWritable": true
                        },
                        {
                            "pubkey": "52nXsHVT861uD8N2EyNhsHBage7d4XFxysD47hcZZiKJ",
                            "isSigner": false,
                            "isWritable": false
                        }
                    ],
                    "programId": "A1kitc8Td5hGFQTkXsencSRBzAT45gKxpgqwkigYFi6g",
                    "data": [
                        2,
                        0,
                        202,
                        154,
                        59,
                        0,
                        0,
                        0,
                        0,
                        42,
                        0,
                        0,
                        0,
                        48,
                        120,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        44,
                        0,
                        0,
                        0,
                        53,
                        87,
                        116,
                        84,
                        117,
                        116,
                        89,
                        75,
                        121,
                        54,
                        88,
                        116,
                        86,
                        83,
                        54,
                        70,
                        72,
                        56,
                        86,
                        65,
                        120,
                        72,
                        80,
                        89,
                        84,
                        116,
                        122,
                        75,
                        66,
                        49,
                        114,
                        113,
                        55,
                        76,
                        102,
                        80,
                        82,
                        56,
                        121,
                        83,
                        67,
                        118,
                        87,
                        54,
                        20,
                        0,
                        0,
                        0,
                        51,
                        49,
                        48,
                        50,
                        54,
                        54,
                        54,
                        53,
                        54,
                        54,
                        51,
                        54,
                        55,
                        49,
                        55,
                        53,
                        55,
                        48,
                        48,
                        48,
                        16,
                        0,
                        0,
                        0,
                        85,
                        83,
                        68,
                        84,
                        40,
                        66,
                        83,
                        67,
                        41,
                        124,
                        54,
                        48,
                        121,
                        121,
                        104,
                        110,
                        42,
                        0,
                        0,
                        0,
                        48,
                        120,
                        67,
                        69,
                        102,
                        55,
                        69,
                        52,
                        52,
                        68,
                        49,
                        51,
                        50,
                        56,
                        54,
                        101,
                        50,
                        51,
                        55,
                        56,
                        50,
                        69,
                        49,
                        50,
                        100,
                        54,
                        53,
                        52,
                        52,
                        53,
                        53,
                        70,
                        65,
                        53,
                        66,
                        51,
                        53,
                        70,
                        51,
                        54,
                        102,
                        56
                    ]
                },
                {
                    "keys": [
                        {
                            "pubkey": "Ekg1SKxB61NMwpaccj1Y88mzyH2QKoaGCVnDUZZ3WXc5",
                            "isSigner": false,
                            "isWritable": true
                        },
                        {
                            "pubkey": "5WtTutYKy6XtVS6FH8VAxHPYTtzKB1rq7LfPR8ySCvW6",
                            "isSigner": false,
                            "isWritable": true
                        },
                        {
                            "pubkey": "5WtTutYKy6XtVS6FH8VAxHPYTtzKB1rq7LfPR8ySCvW6",
                            "isSigner": true,
                            "isWritable": false
                        }
                    ],
                    "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
                    "data": [
                        9
                    ]
                }
            ],
            // signer is an additional signature required by SOL to sign the data
            "signer": "182,16,183,80,22,123,252,74,45,92,252,171,66,45,40,132,60,237,48,145,216,7,46,207,150,92,149,216,93,183,186,156,204,88,2,194,226,51,228,17,225,196,51,0,197,74,129,129,179,131,248,148,175,36,74,145,30,53,21,133,24,117,112,82"
        }
    }
}
```

{% endtab %}
{% endtabs %}

### Code example

{% tabs %}
{% tab title="JavaScript" %}

```
// swap example
 import { ethers } from 'ethers'
 const provider = new ethers.providers.Web3Provider(window.ethereum, 'any')
 cosnt signer = provider.getSigner()
 const params = {
   fromTokenAddress: '0x55d398326f99059ff775485246999027b3197955',
   toTokenAddress: '0xa71edc38d189767582c38a3145b5873052c3e47a',
   fromAddress: '0x...',  //The wallet address used to send the tokens
   toAddress: '0x...',  //The wallet address used to accept tokens
   fromTokenChain: 'BSC',
   toTokenChain: 'HECO',
   fromTokenAmount: '8000000000000000000',
   amountOutMin:'7884000000000000000',
   fromCoinCode:'USDT(BSC)',
   toCoinCode:'USDT(HECO)',
   equipmentNo:'', // your equipment number
   sourceType:'H5',
   sourceFlag:'widget'
  }
  const res = await axios.post('https://api.bridgers.xyz/api/sswap/swap',params)
  console.log(res)
  if(res.resCode === '100'){
    const transactionParameters = {
        to: res.data.txData.to, // Required except during contract publications.
        from: state.wallet.address, // must match user's active address.
        data: res.data.txData.data,
        value: res.data.txData.value,
        //gasPrice: 5000000000, // 6 gwei
        //gas: new BigNumber(1000000), // 1000000
    }
    signer.sendTransaction(transactionParameters)
      .then((data) => {
        console.log(data.hash)
      })   
  }
```

{% endtab %}
{% endtabs %}

### Postman example

![](https://1371637894-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBjj3xwD1ODc9uBxuQrlr%2Fuploads%2F8SupF7RWDwoi94QMcd8s%2F3.jpg?alt=media\&token=e54ed719-1edf-4c8f-8987-02a84b557a19)

## Method 2: Directly request the smart contract

**To send a swap message, call the contract's swap() or swapEth() function.**

**Here is an explanation of the swap() and swapEth() interface:**

```
// @param fromToken - fromToken token's address.
// @param toToken - The target token to be exchanged (obtained from the getToken interface's symbol. e.g. ETH(ARB))
// @param destination - The receiving address for the target token
// @param fromAmount - The amount of the original token
// @param minReturnAmount - The anticipated amount of the target token to be exchanged
function swap(
    address fromToken,
    string memory toToken,
    string memory destination,
    uint256 fromAmount,
    uint256 minReturnAmount
) external nonReentrant

// @param toToken - The target token to be exchanged (obtained from the getToken interface's symbol. e.g. ETH(ARB))
// @param destination - The receiving address for the target token
// @param minReturnAmount - The anticipated amount of the target token to be exchanged
function swapEth(
    string memory toToken,
    string memory destination,
    uint256 minReturnAmount
)
```

**Mainnet currency swap calls the swapEth() method, and token swap calls the swap() method.** \
**EVM Contract call instance:**

{% tabs %}
{% tab title="nodejs" %}

```
exports.swapCallData = async (nodeHost,fromTokenChain,fromTokenAddress,fromTokenAmount,toCoinCode,toAddress,amountOutMin) => {
    const web3 = new Web3(new Web3.providers.HttpProvider(nodeHost));
    const ROUTER_ADDRESS =  ''; // contract address
    const ROUTE_ABI = require('./abis/BridgersAbi.json'); //ABI Stored inside the contract on chain
    const routerContract = new web3.eth.Contract(ROUTE_ABI, ROUTER_ADDRESS);
    let data;
    let value;
    if('0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'==fromTokenAddress){
        data = routerContract.methods.swapEth(toCoinCode,toAddress,amountOutMin).encodeABI();
        value = '0x' + new BigNumber(fromTokenAmount).toString(16);
    }else{
        data = routerContract.methods.swap(fromTokenAddress,toCoinCode,toAddress,fromTokenAmount,amountOutMin).encodeABI();
        value = '0x0';
    }

    let res = {
        'data': data,
        'to': ROUTER_ADDRESS,
        'value': value
    };
    return res;
}
```

{% endtab %}

{% tab title="JavaScript" %}

```
const fromAddress = '0xCEf7E44D13286e23782E12d654455FA5B35F36f8' //Address of token to sell 
const toAddress = '0xCEf7E44D13286e23782E12d654455FA5B35F36f8' //receiving Address 
const toTokenCode = 'USDT(BSC)' //Token name for receive token 
const amount = '140000000000000000' // Amount of token to sell  
const amountOutMin = '53837610794859360000' // Minimum receiving amount 
const fromTokenAddress = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' // Contract address for the token to sell
const ROUTE_ABI = require('./sswapABI.json') // abi json 
const web3 = new Web3(new Web3.providers.HttpProvider('https://bsc-dataseed1.binance.org/')); 
const ROUTER_ADDRESS = '0x1ed5685f345b2fa564ea4a670de1fde39e484751'; 
const routerContract = new web3.eth.Contract(ROUTE_ABI, ROUTER_ADDRESS); 
let data,value; 
if('0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'== fromTokenAddress){
   data = routerContract.methods.swapEth(toTokenCode,fromAddress,amountOutMin).encodeABI(); 
   value = '0x' + new BigNumber(amount).toString(16); 
}else{ 
  data = routerContract.methods.swap(fromTokenAddress,toTokenCode,toAddress,amount,amountOutMin).encodeABI(); 
  value = '0x0'; 
}
console.log(data,value)
```

{% endtab %}
{% endtabs %}

&#x20;**TON Contract call instance:**

{% tabs %}
{% tab title="nodejs" %}

```
const TonWeb = require('tonweb');
const { Contract, ContractProvider, Sender, Address, Cell, contractAddress, beginCell, SendMode, toNano } = require("@ton/core");
const { TonClient, JettonMaster, WalletContractV4} = require("@ton/ton");
const { getHttpEndpoint } = require("@orbs-network/ton-access")

exports.swapCallData = async(fromAddress, fromTokenAddress, amount, toAddress, amountOutMin, toCoinCode) => {
    const swap = 1783769518;
    const swapETH = 1023744248;
    const transfer = 260734629;
    const gas = toNano("0.06").toString();
    const forwardAmount = toNano("0.01").toString();
    if (fromTokenAddress.toLowerCase() == '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee') {
        const forwardPayload = beginCell()
            .storeUint(swapETH, 32)
            .storeAddress(Address.parse(fromAddress))
            .storeCoins(forwardAmount)
            .storeRef(beginCell().storeUint(0, 32).storeStringTail(JSON.stringify({"fromToken": fromTokenAddress, "toToken":  toCoinCode, "sender": fromAddress, "destination" : toAddress, "minReturnAmount": amountOutMin})).endCell())
            .endCell();
        const body = beginCell()
            .storeUint(0x7362d09c, 32)
            .storeRef(forwardPayload)
            .endCell();
        return {address: sdkInfo.sswapContract.TON, amount: amount, payload: body.toBoc().toString("base64")};
    }
    const swap_forwardPayload = beginCell()
        .storeUint(swap, 32)
        .storeAddress(Address.parse(fromAddress))
        .storeCoins(forwardAmount)
        .storeRef(beginCell().storeUint(0, 32).storeStringTail(JSON.stringify({"fromToken": fromTokenAddress, "toToken":  toCoinCode, "sender": fromAddress, "destination" : toAddress, "minReturnAmount": amountOutMin})).endCell())
        .endCell();

    const swap_body = beginCell()
        .storeUint(transfer, 32)
        .storeUint(0, 64)
        .storeCoins(amount)
        .storeAddress(Address.parse(tonContractAddress))
        .storeAddress(Address.parse(fromAddress))
        .storeBit(0)
        .storeCoins(forwardAmount)
        .storeBit(1)
        .storeRef(swap_forwardPayload)
        .endCell();
    const client = new TonClient({
        endpoint: await getHttpEndpoint({ network: 'mainnet' }),
    })
    const jettonMasterAddress = Address.parse(fromTokenAddress);
    const userAddress = Address.parse(fromAddress);
    const jettonMaster = client.open(JettonMaster.create(jettonMasterAddress));
    const jettonWalletAddress = await jettonMaster.getWalletAddress(userAddress);
    return {address: jettonWalletAddress.toString(), amount: gas, payload: swap_body.toBoc().toString("base64")};
}
```

{% endtab %}
{% endtabs %}

**XRP Contract call instance:**

{% tabs %}
{% tab title="nodejs" %}

```
const  {Xumm} = require("xumm");

exports.swapCallData = async (fromAddress, fromTokenAddress, fromTokenDecimals, amount, toAddress, amountOutMin, toCoinCode, xrpTokenCode = '') => {
    let result = '';
    const memoData = {
        "fromToken": fromTokenAddress,
        "toToken": toCoinCode,
        "sender": fromAddress,
        "destination": toAddress,
        "minReturnAmount": amountOutMin,
        "fromAmount": amount
    };
    const buffer = Buffer.from(JSON.stringify(memoData), 'utf-8');
    const hexStr = buffer.toString('hex');
    if (fromTokenAddress == '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee') {
        result = {
            TransactionType: "Payment",
            Destination: bridgersXRPContract,
            Amount: amount,
            Memos: [{Memo: {MemoData: hexStr}}],
        }
    } else {
        let amount1 = new BigNumber(amount).shiftedBy(parseInt(-fromTokenDecimals)).dp(10).toFixed();
        result = {
            TransactionType: "Payment",
            Destination: bridgersXRPContract,
            Amount: {
                currency: xrpTokenCode,
                value: amount1,
                issuer: fromTokenAddress
            },
            Memos: [{Memo: {MemoData: hexStr}}],
        }
    }
    const xumm = new Xumm(API-KEY, API-SECRET);
    let payload = await xumm.payload?.create({
        txjson: result,
        options: {
            force_network: "MAINNET"
        }
    });
    return payload;
}
```

{% endtab %}
{% endtabs %}


# Gas-free swaps on Solana

Request endpoint to initiate the swap,Only supports USDT and USDC as the source token.

### Note

> Before the swap, wallet address needs to confirm that FROM currency token approves the contract address. The contract address can be fetched by requesting the endpoint

## Method 1: Endpoint usage

<mark style="color:green;">`POST`</mark> `https://api.bridgers.xyz/api/sswap/solana/swap`

**The fields with \* are required, and the fields without \* are optional**

#### Request Body

| Name                                               | Type    | Description                                                                                                                                                                                                                      |
| -------------------------------------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| equipmentNo<mark style="color:red;">\*</mark>      | String  | Equipment number  (This field will be used as the unique identifier of the user, and the third parties can obtain it on their own, such as the first 32 characters of fromAddress, or a string of 32 random numbers and letters) |
| sourceType                                         | String  | Device type (H5/IOS/Android The field is optional, if it is requested directly through the API, it can be empty)                                                                                                                 |
| sourceFlag<mark style="color:red;">\*</mark>       | String  | Source channel (Both sides need to agree on a name to represent the channel of the third parties)                                                                                                                                |
| fromTokenAddress<mark style="color:red;">\*</mark> | String  | Contract address for the token to sell  (It can be obtained from the address field in the currency list)                                                                                                                         |
| toTokenAddress<mark style="color:red;">\*</mark>   | String  | Contract address for the token to receive  (It can be obtained from the address field in the currency list)                                                                                                                      |
| fromAddress<mark style="color:red;">\*</mark>      | String  | User address                                                                                                                                                                                                                     |
| toAddress<mark style="color:red;">\*</mark>        | String  | receiving Address                                                                                                                                                                                                                |
| fromTokenChain<mark style="color:red;">\*</mark>   | String  | Network of the token to sell  (It can be obtained from the chain field in the currency list, For details of the support chain, please refer to \[Basic information])                                                             |
| toTokenChain<mark style="color:red;">\*</mark>     | String  | Network of the token to received  (It can be obtained from the chain field in the currency list, For details of the support chain, please refer to \[Basic information])                                                         |
| fromTokenAmount<mark style="color:red;">\*</mark>  | String  | Amount of token to sell (with precision, which can be obtained through the fromTokenAmount field in the quote endpoint)                                                                                                          |
| amountOutMin<mark style="color:red;">\*</mark>     | String  | Expected amount received (with precision, which can be obtained through the amountOutMin field in the quote endpoint)                                                                                                            |
| fromCoinCode<mark style="color:red;">\*</mark>     | String  | Token name for sell token  (It can be obtained from the symbol field in the currency list)                                                                                                                                       |
| toCoinCode<mark style="color:red;">\*</mark>       | String  | Token name for receive token  (It can be obtained from the symbol field in the currency list)                                                                                                                                    |
| slippage                                           | String  | <p>e.g. '0.1' (<strong>meaning 10%</strong>)<br>Minimum amount received = amountOutMin \* (1 - slippage)</p>                                                                                                                     |
| fixedRateFlag                                      | Integer | Flag to toggle fixed rate mode. 1 = Enable, 0 = Disable. Default: 0                                                                                                                                                              |

{% tabs %}
{% tab title="200: OK Solana chain return value" %}

```json
// Returned value: tx, signer 
   signer field only exists when deposit SOL assets
   tx field only exists when deposit tokens 
// tx is Signature Data, signer is an additional signature required by SOL to sign the data
{
    "resCode": 100,
    "resMsg": "Success",
    "data": {
        "txData": {
            "tx": [ // tx is Signature Data
                {
                    "keys": [
                        {
                            "pubkey": "5WtTutYKy6XtVS6FH8VAxHPYTtzKB1rq7LfPR8ySCvW6",
                            "isSigner": true,
                            "isWritable": true
                        },
                        {
                            "pubkey": "Ekg1SKxB61NMwpaccj1Y88mzyH2QKoaGCVnDUZZ3WXc5",
                            "isSigner": true,
                            "isWritable": true
                        }
                    ],
                    "programId": "11111111111111111111111111111111",
                    "data": [
                        0,
                        0,
                        0,
                        0,
                        240,
                        29,
                        31,
                        0,
                        0,
                        0,
                        0,
                        0,
                        165,
                        0,
                        0,
                        0,
                        0,
                        0,
                        0,
                        0,
                        6,
                        221,
                        246,
                        225,
                        215,
                        101,
                        161,
                        147,
                        217,
                        203,
                        225,
                        70,
                        206,
                        235,
                        121,
                        172,
                        28,
                        180,
                        133,
                        237,
                        95,
                        91,
                        55,
                        145,
                        58,
                        140,
                        245,
                        133,
                        126,
                        255,
                        0,
                        169
                    ]
                },
                {
                    "keys": [
                        {
                            "pubkey": "5WtTutYKy6XtVS6FH8VAxHPYTtzKB1rq7LfPR8ySCvW6",
                            "isSigner": true,
                            "isWritable": true
                        },
                        {
                            "pubkey": "Ekg1SKxB61NMwpaccj1Y88mzyH2QKoaGCVnDUZZ3WXc5",
                            "isSigner": false,
                            "isWritable": true
                        }
                    ],
                    "programId": "11111111111111111111111111111111",
                    "data": [
                        2,
                        0,
                        0,
                        0,
                        0,
                        202,
                        154,
                        59,
                        0,
                        0,
                        0,
                        0
                    ]
                },
                {
                    "keys": [
                        {
                            "pubkey": "Ekg1SKxB61NMwpaccj1Y88mzyH2QKoaGCVnDUZZ3WXc5",
                            "isSigner": false,
                            "isWritable": true
                        },
                        {
                            "pubkey": "So11111111111111111111111111111111111111112",
                            "isSigner": false,
                            "isWritable": false
                        },
                        {
                            "pubkey": "5WtTutYKy6XtVS6FH8VAxHPYTtzKB1rq7LfPR8ySCvW6",
                            "isSigner": false,
                            "isWritable": false
                        },
                        {
                            "pubkey": "SysvarRent111111111111111111111111111111111",
                            "isSigner": false,
                            "isWritable": false
                        }
                    ],
                    "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
                    "data": [
                        1
                    ]
                },
                {
                    "keys": [
                        {
                            "pubkey": "Ekg1SKxB61NMwpaccj1Y88mzyH2QKoaGCVnDUZZ3WXc5",
                            "isSigner": false,
                            "isWritable": true
                        },
                        {
                            "pubkey": "5WtTutYKy6XtVS6FH8VAxHPYTtzKB1rq7LfPR8ySCvW6",
                            "isSigner": true,
                            "isWritable": false
                        },
                        {
                            "pubkey": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
                            "isSigner": false,
                            "isWritable": false
                        },
                        {
                            "pubkey": "H71KjNoguKbjSP5uwi8LnR3Huh6pGte6rc3DtxrUzmQB",
                            "isSigner": false,
                            "isWritable": true
                        },
                        {
                            "pubkey": "52nXsHVT861uD8N2EyNhsHBage7d4XFxysD47hcZZiKJ",
                            "isSigner": false,
                            "isWritable": false
                        }
                    ],
                    "programId": "A1kitc8Td5hGFQTkXsencSRBzAT45gKxpgqwkigYFi6g",
                    "data": [
                        2,
                        0,
                        202,
                        154,
                        59,
                        0,
                        0,
                        0,
                        0,
                        42,
                        0,
                        0,
                        0,
                        48,
                        120,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        101,
                        44,
                        0,
                        0,
                        0,
                        53,
                        87,
                        116,
                        84,
                        117,
                        116,
                        89,
                        75,
                        121,
                        54,
                        88,
                        116,
                        86,
                        83,
                        54,
                        70,
                        72,
                        56,
                        86,
                        65,
                        120,
                        72,
                        80,
                        89,
                        84,
                        116,
                        122,
                        75,
                        66,
                        49,
                        114,
                        113,
                        55,
                        76,
                        102,
                        80,
                        82,
                        56,
                        121,
                        83,
                        67,
                        118,
                        87,
                        54,
                        20,
                        0,
                        0,
                        0,
                        51,
                        49,
                        48,
                        50,
                        54,
                        54,
                        54,
                        53,
                        54,
                        54,
                        51,
                        54,
                        55,
                        49,
                        55,
                        53,
                        55,
                        48,
                        48,
                        48,
                        16,
                        0,
                        0,
                        0,
                        85,
                        83,
                        68,
                        84,
                        40,
                        66,
                        83,
                        67,
                        41,
                        124,
                        54,
                        48,
                        121,
                        121,
                        104,
                        110,
                        42,
                        0,
                        0,
                        0,
                        48,
                        120,
                        67,
                        69,
                        102,
                        55,
                        69,
                        52,
                        52,
                        68,
                        49,
                        51,
                        50,
                        56,
                        54,
                        101,
                        50,
                        51,
                        55,
                        56,
                        50,
                        69,
                        49,
                        50,
                        100,
                        54,
                        53,
                        52,
                        52,
                        53,
                        53,
                        70,
                        65,
                        53,
                        66,
                        51,
                        53,
                        70,
                        51,
                        54,
                        102,
                        56
                    ]
                },
                {
                    "keys": [
                        {
                            "pubkey": "Ekg1SKxB61NMwpaccj1Y88mzyH2QKoaGCVnDUZZ3WXc5",
                            "isSigner": false,
                            "isWritable": true
                        },
                        {
                            "pubkey": "5WtTutYKy6XtVS6FH8VAxHPYTtzKB1rq7LfPR8ySCvW6",
                            "isSigner": false,
                            "isWritable": true
                        },
                        {
                            "pubkey": "5WtTutYKy6XtVS6FH8VAxHPYTtzKB1rq7LfPR8ySCvW6",
                            "isSigner": true,
                            "isWritable": false
                        }
                    ],
                    "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
                    "data": [
                        9
                    ]
                }
            ],
            // signer is an additional signature required by SOL to sign the data
            "signer": "182,16,183,80,22,123,252,74,45,92,252,171,66,45,40,132,60,237,48,145,216,7,46,207,150,92,149,216,93,183,186,156,204,88,2,194,226,51,228,17,225,196,51,0,197,74,129,129,179,131,248,148,175,36,74,145,30,53,21,133,24,117,112,82"
        }
    }
}
```

{% endtab %}
{% endtabs %}

### Code example

{% tabs %}
{% tab title="JavaScript" %}

```
// swap example
 import { ethers } from 'ethers'
 const provider = new ethers.providers.Web3Provider(window.ethereum, 'any')
 cosnt signer = provider.getSigner()
 const params = {
   fromTokenAddress: '0x55d398326f99059ff775485246999027b3197955',
   toTokenAddress: '0xa71edc38d189767582c38a3145b5873052c3e47a',
   fromAddress: '0x...',  //The wallet address used to send the tokens
   toAddress: '0x...',  //The wallet address used to accept tokens
   fromTokenChain: 'BSC',
   toTokenChain: 'HECO',
   fromTokenAmount: '8000000000000000000',
   amountOutMin:'7884000000000000000',
   fromCoinCode:'USDT(BSC)',
   toCoinCode:'USDT(HECO)',
   equipmentNo:'', // your equipment number
   sourceType:'H5',
   sourceFlag:'widget'
  }
  const res = await axios.post('https://api.bridgers.xyz/api/sswap/swap',params)
  console.log(res)
  if(res.resCode === '100'){
    const transactionParameters = {
        to: res.data.txData.to, // Required except during contract publications.
        from: state.wallet.address, // must match user's active address.
        data: res.data.txData.data,
        value: res.data.txData.value,
        //gasPrice: 5000000000, // 6 gwei
        //gas: new BigNumber(1000000), // 1000000
    }
    signer.sendTransaction(transactionParameters)
      .then((data) => {
        console.log(data.hash)
      })   
  }
```

{% endtab %}
{% endtabs %}

### Postman example

![](https://1371637894-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBjj3xwD1ODc9uBxuQrlr%2Fuploads%2F8SupF7RWDwoi94QMcd8s%2F3.jpg?alt=media\&token=e54ed719-1edf-4c8f-8987-02a84b557a19)


# Generate order information

After wallet sent the FROM currency, upload hash to get the order details

### Endpoint usage

<mark style="color:green;">`POST`</mark> `https://api.bridgers.xyz/api/exchangeRecord/updateDataAndStatus`

**The fields with \* are required, and the fields without \* are optional**

#### Request Body

| Name                                               | Type   | Description                                                                                                                                                                                                                      |
| -------------------------------------------------- | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| equipmentNo<mark style="color:red;">\*</mark>      | String | Equipment number  (This field will be used as the unique identifier of the user, and the third parties can obtain it on their own, such as the first 32 characters of fromAddress, or a string of 32 random numbers and letters) |
| sourceType                                         | String | Device type  (H5/IOS/Android The field is optional, if it is requested directly through the API, it can be empty)                                                                                                                |
| sourceFlag<mark style="color:red;">\*</mark>       | String | Source channel  (Both sides need to agree on a name to represent the channel of the third parties)                                                                                                                               |
| hash<mark style="color:red;">\*</mark>             | String | Transaction hash                                                                                                                                                                                                                 |
| fromTokenAddress<mark style="color:red;">\*</mark> | String | Contract address for the token to sell  (It can be obtained from the address field in the currency list)                                                                                                                         |
| toTokenAddress<mark style="color:red;">\*</mark>   | String | Contract address for the token to receive  (It can be obtained from the address field in the currency list)                                                                                                                      |
| fromAddress<mark style="color:red;">\*</mark>      | String | User address                                                                                                                                                                                                                     |
| toAddress<mark style="color:red;">\*</mark>        | String | receiving Address                                                                                                                                                                                                                |
| fromTokenChain<mark style="color:red;">\*</mark>   | String | Network of the token to sell (It can be obtained from the chain field in the currency list, For details of the support chain, please refer to \[Basic information])                                                              |
| toTokenChain<mark style="color:red;">\*</mark>     | String | Network of the token to received (It can be obtained from the chain field in the currency list, For details of the support chain, please refer to \[Basic information])                                                          |
| fromTokenAmount<mark style="color:red;">\*</mark>  | String | Amount of token to sell (with precision, which can be obtained through the fromTokenAmount field in the quote endpoint)                                                                                                          |
| amountOutMin<mark style="color:red;">\*</mark>     | String | Expected amount received (with precision, which can be obtained through the amountOutMin field in the quote endpoint)                                                                                                            |
| fromCoinCode<mark style="color:red;">\*</mark>     | String | Token name for sell token  (It can be obtained from the symbol field in the currency list)                                                                                                                                       |
| toCoinCode<mark style="color:red;">\*</mark>       | String | Token name for receive token  (It can be obtained from the symbol field in the currency list)                                                                                                                                    |
| slippage                                           | String | <p>e.g. '0.1' (<strong>meaning 10%</strong>)<br>Minimum amount received = amountOutMin \* (1 - slippage)</p>                                                                                                                     |

{% tabs %}
{% tab title="200: OK " %}

```javascript
{
 "resCode":100,
 "resMsg":"success",
 "data":{
  "orderId":"..." // 订单号orderId
  }
}
```

{% endtab %}
{% endtabs %}

### Code example

{% tabs %}
{% tab title="JavaScript" %}

```
// example
//You can get the order number through the swap interface
const params = {
    hash: '0x05920386bc07d71b58109fab0ab591c5e07d7b15f7a8d77c692fd735048d9dba', //  User sends token hash
    fromTokenAddress: '0x55d398326f99059ff775485246999027b3197955',
    toTokenAddress: '0xa71edc38d189767582c38a3145b5873052c3e47a',
    fromAddress:"0x19...",
    toAddress:"0x19...",
    fromTokenChain:"HECO",
    toTokenChain:"HECO",
    fromTokenAmount: "3293000000000000000",
    amountOutMin:"28891153244504185000",
    fromCoinCode:"HT(HECO)",
    toCoinCode:"USDT(HECO)",
    sourceFlag:"widget",
    sourceType:"H5"
}
const res = await axios.post('https://api.bridgers.xyz/api/exchangeRecord/updateDataAndStatus',params)
console.log(res)
```

{% endtab %}
{% endtabs %}

### Postman

![](https://1371637894-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBjj3xwD1ODc9uBxuQrlr%2Fuploads%2FW0GE3krIqoZFe2WAIYSU%2F4.jpg?alt=media\&token=3add8d76-c9e2-4667-a230-4f11cdd136e8)


# Query transaction records

Query user history transaction records

### Endpoint usage

<mark style="color:green;">`POST`</mark> `https://api.bridgers.xyz/api/exchangeRecord/getTransData`

**The fields with \* are required, and the fields without \* are optional**

#### Request Body

| Name                                          | Type    | Description                                                                                                                                                                                                                      |
| --------------------------------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| equipmentNo<mark style="color:red;">\*</mark> | String  | Equipment number  (This field will be used as the unique identifier of the user, and the third parties can obtain it on their own, such as the first 32 characters of fromAddress, or a string of 32 random numbers and letters) |
| sourceType                                    | String  | Device type (H5/IOS/Android The field is optional, if it is requested directly through the API, it can be empty)                                                                                                                 |
| sourceFlag<mark style="color:red;">\*</mark>  | String  | Source channel  (Both sides need to agree on a name to represent the channel of the third parties)                                                                                                                               |
| pageNo<mark style="color:red;">\*</mark>      | Integer | current page number                                                                                                                                                                                                              |
| pageSize<mark style="color:red;">\*</mark>    | Integer | Page size                                                                                                                                                                                                                        |
| fromAddress<mark style="color:red;">\*</mark> | String  | User address                                                                                                                                                                                                                     |

{% tabs %}
{% tab title="200: OK " %}

```javascript
{
    "resCode":100,
    "resMsg":"success",
    "data":{
        "list":[
            {
                "id":283,
                "orderId":"kydjhyt5_rec8_tfdi_s67b_td5kpu8qezy0",  // Order Id 
                "fromTokenAddress":"0xa71edc38d189767582c38a3145b5873052c3e47a",  // Contract address for the token to sell 
                "toTokenAddress":"0x382bb369d343125bfb2117af9c149795c6c65c50",    // Contract address for the token to receive  
                "fromTokenAmount":"5",  // Amount of token to sell 
                "toTokenAmount":"3.99", // Estimated amount to receive  
                "fromAddress":"0x20...", //  User address                 
                "slippage":"",  // slippage
                "fromChain":"HECO",  // Network of the token to sell 
                "toChain":"OKEXCHAIN",  // Network of the token to received  
                "hash":"0x505c3b4ebecb3f95e2d51d140c732be7ac6b57119ff2a08908f171f6f00daa1a",   // Deposit hash
                "depositHashExplore":"https://hecoinfo.com/tx/0x505c3b4ebecb3f95e2d51d140c732be7ac6b57119ff2a08908f171f6f00daa1a",  // Deposit hash explorer URL 
                "dexName":"",
                "status":"receive_complete",  // Order status  
                "createTime":"2022-01-25 14:24:32", // Order create time                
                 "source":"Bridgers1",  // Source channel 
                "toAddress":"0x20...",  // Receiving address 
                "toHash":"0xf4575d8e99474319bbc8f5a849ac8821ace868bc3d4ca93723f2c5ead200a5bb",  // Transaction Hash
                "receiveHashExplore":"https://www.oklink.com/oec/tx/0xf4575d8e99474319bbc8f5a849ac8821ace868bc3d4ca93723f2c5ead200a5bb",  // Transaction hash explorer URL 
                "equipmentNo":"0x19b9....",  // Equipment number 
                "refundCoinAmt":"",  //  Refund amount 
                "refundHash":"",  //  Refund Hash 
                "refundHashExplore":"",  // Refund hash explorer URL 
                "refundReason": "1", //(1-Insufficient liquidity, 2-Exceeding threshold error, 3-Maintenance of the original currency, 4-Blacklisted, 5-Maintenance of the target currency, 6-The amount of redemption is not within the range, 7-Deposit timeout, 8-Interact with risky address)
                "fromCoinCode":"USDT(HECO)",  // Token to sell 
                "toCoinCode":"USDT(OKExChain)"   // Token to receive  
            }
        ],
        "total":1,  // Total page number  
        "pageNo":"1"  //  Current page number
    }
}
```

{% endtab %}
{% endtabs %}

### Code example

{% tabs %}
{% tab title="JavaScript" %}

```
//  transData example
  const params = {
    pageNo: 1,
    pageSize: 5,
    fromAddress: '',  //your wallet address
    equipmentNo:'', // your equipment number
    sourceType: 'H5',
    sourceFlag:'widget'
  }
  const res = await axios.post('https://api.bridgers.xyz/api/exchangeRecord/getTransData',params)
  console.log(res)
```

{% endtab %}
{% endtabs %}

### Postman example

![](https://1371637894-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBjj3xwD1ODc9uBxuQrlr%2Fuploads%2FGN5cqkQVyGPVAWhTeGdX%2F5.jpg?alt=media\&token=e044d8f6-1cc4-495f-b62e-a2f9b3f3643f)

### Status field Parsed for display

wait\_deposit\_send: 'Waiting for deposit',&#x20;

wait\_deposit\_send\_fail: 'User deposit failed',&#x20;

wait\_exchange\_push: 'Exchanging...',&#x20;

wait\_exchange\_return: 'Exchanging...',

wait\_exchange\_return\_success: 'Exchanging...',

wait\_receive\_send: 'Exchange complete, ready to issue crypto',

wait\_enough\_send:'Issuing crypto …'

wait\_receive\_confirm: 'Confirming issue …',&#x20;

receive\_complete: 'Swap completed',

wait\_refund\_send: 'Refunding',

wait\_refund\_confirm: 'Confirming refund ...',&#x20;

refund\_complete: 'refund complete',

timeout: 'Timeout',

ERROR: 'Exchanging...',

wait\_for\_information:'please contact customer service.'


# Query transaction details

Query the details of a single transaction

### Endpoint usage

<mark style="color:green;">`POST`</mark> `https://api.bridgers.xyz/api/exchangeRecord/getTransDataById`

**The fields with \* are required, and the fields without \* are optional**

#### Request Body

| Name                                      | Type   | Description |
| ----------------------------------------- | ------ | ----------- |
| orderId<mark style="color:red;">\*</mark> | String | Order Id    |

{% tabs %}
{% tab title="200: OK " %}

```javascript
{
    "resCode":100,
    "resMsg":"success",
    "data":{
        "id":283,
        "orderId":"kydjhyt5_rec8_tfdi_s67b_td5kpu8qezy0",  //  Order Id 
        "fromTokenAddress":"0xa71edc38d189767582c38a3145b5873052c3e47a", // Contract address for the token to sell 
        "toTokenAddress":"0x382bb369d343125bfb2117af9c149795c6c65c50",  // Contract address for the token to receive  
        "fromTokenAmount":"5",   // Amount of token to sell
        "toTokenAmount":"3.99",  // Estimated amount to receive  
        "fromAddress":"0x19...",  // User address 
        "slippage":"",  // slippage 
        "fromChain":"HECO",  // Network of the token to sell 
        "toChain":"OKEXCHAIN",  // Network of the token to received  
        "hash":"0x505c3b4ebecb3f95e2d51d140c732be7ac6b57119ff2a08908f171f6f00daa1a",   // Deposit Hash 
        "depositHashExplore":"https://hecoinfo.com/tx/0x505c3b4ebecb3f95e2d51d140c732be7ac6b57119ff2a08908f171f6f00daa1a", // Deposit hash explorer URL
        "dexName":"",
        "status":"receive_complete",  // Order status 
        "createTime":"2022-01-25 14:24:35", // Order create time  
        "source":"Bridgers1",  // Source channel 
        "toAddress":"0x19...",   // Receiving address 
        "toHash":"0xf4575d8e99474319bbc8f5a849ac8821ace868bc3d4ca93723f2c5ead200a5bb",    // Transaction Hash 
        "receiveHashExplore":"https://www.oklink.com/oec/tx/0xf4575d8e99474319bbc8f5a849ac8821ace868bc3d4ca93723f2c5ead200a5bb", //  Transaction hash explorer URL 
        "equipmentNo":"0x19b991...", // Equipment number 
        "refundCoinAmt":"",  // Refund amount 
        "refundHash"：:"",   // Refund Hash
        "refundHashExplore":"",   // Refund hash explorer URL
        "refundReason": "1", //(1-Insufficient liquidity, 2-Exceeding threshold error, 3-Maintenance of the original currency, 4-Blacklisted, 5-Maintenance of the target currency, 6-The amount of redemption is not within the range, 7-Deposit timeout, 8-Interact with risky address)
        "fromCoinCode":"USDT(HECO)",  // Token to sell 
        "toCoinCode":"USDT(OKExChain)"   // Token to receive  
    }
}

```

{% endtab %}
{% endtabs %}

### Code example

{% tabs %}
{% tab title="JavaScript" %}

```
// example
const params = {
 orderId: '', //order number
}
 const res = await axios.post('https://api.bridgers.xyz/api/exchangeRecord/getTransDataById',params)
 console.log(res)
```

{% endtab %}
{% endtabs %}

### Postman example

![](https://1371637894-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBjj3xwD1ODc9uBxuQrlr%2Fuploads%2FfV4Ntqba0tz12WsBmtkB%2F6.jpg?alt=media\&token=61b3b82f-0eb7-4b65-b308-0d5981282605)

### Status field Parsed for display

wait\_deposit\_send: 'Waiting for deposit',&#x20;

wait\_deposit\_send\_fail: 'User deposit failed',&#x20;

wait\_exchange\_push: 'Exchanging...',&#x20;

wait\_exchange\_return: 'Exchanging...',

wait\_exchange\_return\_success: 'Exchanging...',

wait\_receive\_send: 'Exchange complete, ready to issue crypto',

wait\_enough\_send:'Issuing crypto….'

wait\_receive\_confirm: 'Confirming issue ….',&#x20;

receive\_complete: 'Swap completed',

wait\_refund\_send: 'Refunding',

wait\_refund\_confirm: 'Confirming refund ...',&#x20;

refund\_complete: 'refund complete',

timeout: 'Timeout',

ERROR: 'Exchanging...',

wait\_for\_information:'please contact customer service.'


# bridgers skills

### Comprehensive Bridgers API integration for user crypto swaps. Supports quoting, tokens fetching, calldata generation, order tracking, and transaction status queries. Use this when you need to swap tokens using Bridgers API.

```
npx skills add https://github.com/bridgers-skills/bridgers-api-skill
```


# FAQ

For third-party enquiries with integration issues

<details>

<summary>Q:   Does Bridgers have a frontend web app?</summary>

**A**:   [https://www.bridgers.xyz](https://www.bridgers.xyz/#/)

</details>

<details>

<summary>Q:   Is it possible to set the third-party processing fee separately for different parties?</summary>

**A:   Yes, different third-party can have customized processing fee as they wish**

</details>

<details>

<summary>Q:   What are the available trading pairs?</summary>

**A:**   Currently Bridgers1 supports any currency exchange that is available on ETH, BSC, HECO, POLYGON,OEC,FANTOM,TRON,ARBITRUM,AVALANCHE,OPTIMISM,CRONOS ,SOLANA and APT chain, and will continue to expand in the future with EVM chians as priority;

</details>

<details>

<summary>Q:   How long could one transaction take?</summary>

**A:   Generally, it will only take around 30 seconds if we have a sufficient pool, will take slightly longer if our pool needs to be refilled**

</details>

<details>

<summary>Q:   How long a third party team can expect to integrate Bridgers API?</summary>

**A:   6 endpoints are involved, it can be expected to be done within a day**

</details>


# Consensus Mechanism

&#x20;   Digital currency cross-chain bridges are technologies that allow communication and asset exchange between different blockchains. They aim to solve the interoperability issue between different blockchain networks. To achieve this goal, cross-chain bridges require a consensus mechanism to ensure the secure and accurate transmission of information and transactions between different blockchains.

There are several types of consensus mechanisms for cross-chain bridges, and some common ones are:

1. Federated Consensus: Federated consensus is a decentralized consensus mechanism composed of pre-selected nodes that represent their respective chains in achieving consensus on their own chain. These representative nodes need to maintain trust between each other, and when cross-chain transactions occur, they jointly supervise and verify the cross-chain transactions to ensure their correctness.
2. Hashed Timelock Contracts (HTLCs): HTLCs are cryptographic contracts used to ensure the secure exchange of assets in cross-chain transactions. These contracts need to meet certain conditions before a specified time, or the transaction will be revoked. They are commonly used with payment channel networks (such as Bitcoin's Lightning Network or Ethereum's Raiden Network) to enable cross-chain asset exchange.
3. Cross-chain Atomic Swaps: Cross-chain atomic swaps allow two users to securely exchange assets on different blockchains without relying on a third party. Atomic swaps use a technique called "atomicity" to ensure that the exchange either happens entirely or not at all, thereby reducing the risk of transaction failure.
4. &#x20;Relay Chain: A relay chain is a type of blockchain that acts as a cross-chain bridge, connecting and coordinating communication between different blockchains. Projects like Polkadot and Cosmos use relay chains to achieve cross-chain interoperability. This approach simplifies cross-chain transactions by delegating their consensus and verification to the relay chain.
5. Virtual Machines: Virtual machine technology can also be used to achieve cross-chain interoperability. For example, Cosmos' InterBlockchain Communication (IBC) protocol allows different blockchains to communicate and exchange assets through virtual machines. This approach uses virtual machines to establish a common runtime environment between different blockchains, enabling them to understand and pass information to each other.

Each of these consensus mechanisms has its advantages and disadvantages, and they are suitable for different scenarios and requirements. Choosing the appropriate cross-chain bridge consensus mechanism depends on the project's goals, security requirements, performance needs, and the level of interoperability with other blockchains. Here are some suggestions to help you choose the right consensus mechanism:

1. Consider security: Security is an important factor when choosing a cross-chain bridge consensus mechanism. For example, federated consensus may be susceptible to centralization risks in some cases, while atomic swaps and hashed timelock contracts offer higher security guarantees.
2. &#x20;Consider performance: Performance is another key factor, as different consensus mechanisms may impact the speed and efficiency of cross-chain transactions. For example, virtual machine and relay chain methods may offer higher throughput, while atomic swaps and hashed timelock contracts may have lower throughput.
3. Consider the degree of decentralization: Depending on your project's needs, you may want to choose a more decentralized consensus mechanism. For example, although federated consensus is decentralized to some extent, it still relies on a set of pre-selected nodes. In contrast, atomic swaps and hashed timelock contracts offer a higher degree of decentralization.
4. Consider interoperability: The cross-chain bridge consensus mechanism should support interoperability with other blockchains. Relay chain and virtual machine methods typically offer better interoperability, as they can communicate and exchange assets with multiple blockchains.
5. Consider ease of use and developer support: When choosing a consensus mechanism, also consider its ease of use and developer support. For example, choosing a consensus mechanism with extensive community support and documentation may make your project's implementation smoother.

&#x20; In summary, when choosing a digital currency cross-chain bridge consensus mechanism,various factors such as security, performance, degree of decentralization, interoperability, and ease of use need to be taken into account. Understanding these factors will help you choose the most suitable consensus mechanism for your project.

&#x20; It's essential to research and analyze existing cross-chain solutions and consensus mechanisms to make informed decisions. Engaging with the blockchain community and seeking advice from experienced developers can also provide valuable insights and help you choose the best consensus mechanism for your specific use case.

&#x20; Moreover, as the blockchain industry continues to evolve rapidly, new cross-chain solutions and consensus mechanisms may emerge, potentially offering improved performance, security, and interoperability. Staying up-to-date with the latest developments in the field can help you make better decisions and ensure the long-term success of your project.

&#x20; The Bridgers cross-chain bridge uses the SMPC (Secure Multi-Party Computation) consensus mechanism. Secure Multi-Party Computation (SMPC) is not a conventional consensus mechanism but rather a cryptographic technique that allows multiple participants to jointly compute a function without revealing their individual data. Although SMPC is related to consensus mechanisms to some extent, its primary purpose is to address privacy and data protection concerns, rather than consensus issues in blockchain networks.

&#x20; In secure multi-party computation, participants encrypt their data and perform calculations on the encrypted data. Once the computation is complete, the result is shared with all participants in encrypted form. Each participant can decrypt the encrypted result using their private key to obtain the computed outcome. Due to the encryption and decryption processes, participants cannot directly access each other's raw data, ensuring data privacy.

&#x20; Although SMPC technology is not a typical blockchain consensus mechanism, it can be combined with blockchain technology to enhance data privacy and security. For example, in some privacy-preserving blockchain applications, SMPC can be used to verify the validity of transactions without revealing transaction details.


