> For the complete documentation index, see [llms.txt](https://docs-bridgers-en.bridgers.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs-bridgers-en.bridgers.xyz/bridgers-api-endpoints/gas-free-swaps-on-solana.md).

# Gas-free swaps on Solana

### 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

![](/files/HaRY35cS2ger1rrz7AaV)
