# Get Price Quote API

## Cross-chain Quote

GET <https://api2.chainge.finance/v1/getBridgeQuote>

### Query

<table><thead><tr><th width="173">Fields</th><th>Description</th></tr></thead><tbody><tr><td>amount</td><td>Amount paid by the user</td></tr><tr><td>symbol</td><td>From Token symbol</td></tr><tr><td>fromChain</td><td>From Chain nickName</td></tr><tr><td>toChain</td><td>To Chain nickName</td></tr></tbody></table>

example:&#x20;

```javascript
const result = await axios.get(`https://api2.chainge.finance/v1/getBridgeQuote?amount=100000000&symbol=USDT&fromChain=FSN&toChain=BNB`)
console.log(result)
//{
//    "code": 0,
//    "msg": "success",
//    "data": {
//        "price": "1",
//        "outAmount": "100000000000000000000",
//        "outAmountUsd": "100.000000000000000000",
//        "serviceFee": "50000000000000000",
//        "gasFee": "300000000000000000"
//    }
//}
const { outAmount, outAmountUsd, serviceFee, gasFee } = result.data
const outAmountBI = BigInt(outAmount)
const serviceFeeBI = BigInt(serviceFee)
const gasFeeBI = BigInt(gasFee)
const gasBI = serviceFeeBI + gasFeeBI
const receiveAmountBI = outAmountBI - totalGasBI
if(receiveAmountBI <= BigInt(0)) {
    // Unable to cover the transaction fee. The transaction should be terminated.
} else {
    // The actual value displayed to the user.
    console.log(formatUnits(receiveAmountBI, toToken?.decimals)) // 99.65
    console.log(formatUnits(gasBI, toToken?.decimals)) // 0.35 
    // Here, the extra parameter for submitOrder can be preprocessed.
    // submitOrder body params.extra
    const extra = `1_${receiveAmountBI.toString()}`
}
```

{% hint style="info" %}

<pre><code>The <a data-footnote-ref href="#user-content-fn-1">formatUnits</a> method is a function from the <a data-footnote-ref href="#user-content-fn-1">viem</a> library.
You can choose any equivalent library to use. 
Here, it's just a basic demonstration.
</code></pre>

{% endhint %}

{% hint style="info" %}

<pre><code><a data-footnote-ref href="#user-content-fn-1">fromChain, toChain, fromToken, toToken</a>
These are all results returned by the "Supported Chains &#x26; Tokens" interface.
</code></pre>

{% endhint %}

To provide higher flexibility, our return results need to be processed before displaying on the interface:

* price: The current price of the cross-chain currency for calculating its value.
* outAmount: The total amount received across chains, including gasFee and serviceFee. You need to subtract gasFee and serviceFee to get the actual amount received by the user.
* outAmountUsd: Estimated value in USDT.
* serviceFee: Official service fee, five per ten thousand (0.05%).
* gasFee: Gas fee for cross-chain transfers.

## Cross-chain Aggregate Quote API

GET <https://api2.chainge.finance/v1/getAggregateQuote>

<table><thead><tr><th width="218">Fields</th><th>Description</th></tr></thead><tbody><tr><td>fromAmount</td><td>Amount paid by the user</td></tr><tr><td>fromTokenAddress</td><td>From token contract address</td></tr><tr><td>fromDecimal</td><td>From token decimal</td></tr><tr><td>fromChain</td><td>From chain nickName</td></tr><tr><td>toTokenAddress</td><td>To token  contract address</td></tr><tr><td>toDecimal</td><td>To token decimal</td></tr><tr><td>toChain</td><td>To chain nickName</td></tr></tbody></table>

example:&#x20;

<pre class="language-javascript"><code class="lang-javascript"><strong>const result = await axios.get(`https://api2.chainge.finance/v1/getAggregateQuote?fromAmount=100000000&#x26;fromTokenAddress=0x8a20c13b42d7fe418f10f922f2cee06246c24269&#x26;fromDecimal=6&#x26;fromChain=FSN&#x26;toTokenAddress=0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d&#x26;toDecimal=18&#x26;toChain=BNB`)
</strong>console.log(result)
//{
//    "code": 0,
//    "msg": "success",
//    "data": {
//        "chain": "42161",
//        "chainDecimal": 6,
//        "aggregator": "Kyber",
//        "outAmount": "100061783",
//        "outAmountUsd": "99.20181999",
//        "minOutAmount": "",
//        "serviceFee": "50030",
//        "gasFee": "800079",
//        "priceImpact": "0.26",
//        "routeSummary": "H4sIAAAAAAAA/5ySUWvbMBSF/8t99ookW7KstxZWCGxslO0p5EG6vnJMHDlYcpsS8t+HHS/pVhisftP1Eeec++kEqd9RWAUwwI6+Zlo5LLGWWGheI1aoJTkqSm05Mqcqj85VkIHd92NI8z3Olu/N+GesL38g++3w1Q47St+HFun+2baddR2B8baLtGi+jWmOYb3WNVOSyhI1ohB5lYsSJdUut0UuhNIkdc6vfpeLUw7FS52/nV+D3AnFK6akUnCz+2emxkYwIORSrbFxFv7VuLHx4sHumGalZIwLrQolimoKSMc02EciMCfwRPdzrkkNGeDWDg09Ej28ggHIoI2r8HCI1wSe6ImQ2mcaJsE5g6EfE4FZr09w6PtuXhdOyDQnwXyVi5xx4RUVQrjaSym8Z8pZhTW/ofhf2B+l07X7Nj1RGofwR/H4Yg/Xwfvn8x4nHXFrQzPt/qXfO5sgm/t/odCkLZjicvzxerhJPu1tGxbd54kCmDB23YIEzOl83mxuJ8DtGHZxFXwPZr05n38FAAD//y+XPE8bAwAA"
//    }
//}
const { chain, chainDecimal, aggregator, outAmount, outAmountUsd, minOutAmount, serviceFee, gasFee, priceImpact, routeSummary } = result.data
const outAmountBI = BigInt(outAmount)
const serviceFeeBI = BigInt(serviceFee)
const gasFeeBI = BigInt(gasFee)
const gasBI = serviceFeeBI + gasFeeBI
const receiveAmountBI = outAmountBI - totalGasBI
if(receiveAmountBI &#x3C;= BigInt(0)) {
    // Unable to cover the transaction fee. The transaction should be terminated.
} else {
    // The actual value displayed to the user.
    console.log(formatUnits(receiveAmountBI, chainDecimal)) // 99.211674
    console.log(formatUnits(gasBI, chainDecimal)) // 0.850109
    // Here, the extra parameter for submitOrder can be preprocessed.
    // submitOrder body params.extra
    let extraToAmountBI = receiveAmountBI
    if(toChain.network !== chain) {
        const tempExtraToAmountStr = formatUnits(extraToAmountBI, chainDecimal)
        extraToAmountBI = parseUnits(tempExtraToAmountStr, toToken.decimals)
    }
    const extra = `1_${extraToAmountBI.toString()}`
     if(fromChain.network !== chain &#x26;&#x26; toChain.network !== chain) {
        // The subsequent process proceeds with the submitOrder function.
    } else {
       if(fromChain.network === toChain.network) {
            // The subsequent process proceeds with the getAggregateSwap function.
       } else {
           // The subsequent process proceeds with the submitOrder function.
       }
    }
}
</code></pre>

{% hint style="info" %}

<pre><code>The <a data-footnote-ref href="#user-content-fn-1">formatUnits</a> method is a function from the <a data-footnote-ref href="#user-content-fn-1">viem</a> library.
You can choose any equivalent library to use. 
Here, it's just a basic demonstration.
</code></pre>

{% endhint %}

{% hint style="info" %}
[fromChain, toChain, fromToken, toToken](#user-content-fn-1)[^1]

These are all results returned by the "Supported Chains & Tokens" interface.s
{% endhint %}

To provide greater flexibility, our return results need to be processed again before they can be displayed on the interface:

* **chain:** The chain ID on which the transaction is executed.
* **chainDecimal:** The decimal of the current currency on the chain where the transaction is executed.
* **aggregator:** The intermediary responsible for executing the transaction.
* **outAmount:** The total amount received after cross-chain transfer, including gasFee and serviceFee. Therefore, you need to deduct gasFee and serviceFee to get the actual amount received by the user.
* **outAmountUsd:** The estimated value in USDT.
* **minOutAmount:** Reserved field.
* **serviceFee:** More detailed documentation will be provided.
* **gasFee:** The gas fee for cross-chain transfer.
* **priceImpact:** Price impact.
* **routeSummary:** Transaction routing information.

[^1]:
