4⃣
Build Swap Transaction
get
https://aggregator-api.xy.finance/v1
/buildTx
Get Build Tx
When building transaction, there are 6 additional parameters along with quote input.
Field name | Requirement |
---|---|
receiver | Required |
srcSwapProvider | Required when srcSwapDescription is presented in quote result |
dstSwapProvider | Required when dstSwapDescription is presented in quote result |
bridgeProvider | Required when bridgeDescription is presented in quote result |
srcBridgeTokenAddress | Required when bridgeDescription is presented in quote result |
dstBridgeTokenAddress | Required when bridgeDescription is presented in quote result |
To build transaction, please fill the corresponding fields (
srcSwapDescription
, bridgeDescription
and dstSwapDescription
) from quote response's route to buildTx input . If parameters are not filled properly, it may not return the desired routing result. You can review the transaction calldata route by checking route
field in buildTx response.For example, following response is quote result of Arbitrum USDT to KCC native token.
// quote response
{
"success": true,
"routes": [
{
"srcChainId": 42161,
"srcQuoteTokenAddress": "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
"srcQuoteTokenAmount": "10000000",
"dstChainId": 321,
"dstQuoteTokenAddress": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"srcSwapDescription": null,
"bridgeDescription": {
"provider": "Ypool",
// ...
},
"dstSwapDescription": {
"provider": "XY DexAggregator",
// ...
},
// ...
}
],
}
srcSwapDescription
is null because these is no source chain swap needed in this route, so we don't have to fillsrcSwapProvider
when calling buildTx.- We have a non-empty
bridgeDescription
because it's a cross-chain quote. We need to fill correspondingbridgeProvider
,srcBridgeTokenAddress
anddstBridgeTokenAddress
when calling buildTx. For single chain quote, we can skip these parameters. dstSwapDescription
is needed in this route. So we need to filldstSwapProvider
when calling buildTx.
Therefore, we can create the following buildTx request from above information:
// buildTx request
curl -G \
-d 'srcChainId=42161' \
-d 'srcQuoteTokenAddress=0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9' \
-d 'srcQuoteTokenAmount=10000000' \
-d 'dstChainId=321' \
-d 'dstQuoteTokenAddress=0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE' \
-d 'slippage=1' \
-d 'receiver=YOUR_DESTINATION_CHAIN_RECEIVER_ADDRESS' \
-d 'bridgeProvider=Ypool' \
-d 'srcBridgeTokenAddress=0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9' \
-d 'dstBridgeTokenAddress=0x0039f574eE5cC39bdD162E9A88e3EB1f111bAF48' \
-d 'dstSwapProvider=XY%20DexAggregator' \
https://aggregator-api.xy.finance/v1/buildTx
bridgeProvider
currently supports 3 bridges
CBridge
Ypool
TokenBridge
dstSwapProvider
&srcSwapProvider
currently support 3 DEX Aggregators
OneInch V4 DexAggregator
OpenOcean V3 DexAggregator
XY DexAggregator
$ curl https://aggregator-api.xy.finance/v1/buildTx?srcChainId=10&srcQuoteTokenAddress=0x7F5c764cBc14f9669B88837ca1490cCa17c31607&srcQuoteTokenAmount=100000000&dstChainId=56&dstQuoteTokenAddress=0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE&slippage=1&receiver=0xb6EFA1C3679f1943f8aC4Fc9463Cc492435c6C92&bridgeProvider=Ypool&srcBridgeTokenAddress=0x94b008aA00579c1307B0EF2c499aD98a8ce58e58&dstBridgeTokenAddress=0x55d398326f99059fF775485246999027B3197955&affiliate=0x90d67a9eaC7324A1a2942D6Dea9f6174Ad6048c9&commission_rate=0&srcSwapProvider=OneInch+V4+DexAggregator&dstSwapProvider=OpenOcean+V3+DexAggregator
This request is asking a quote of 100 USDC.e on Optimism to BNB on BNB Chain.
IMPORTANT:
Note that the amount parameter should be padded with zeroes. For example, pass
100000000
instead of
100
if the decimals of the token is 6.
If you would like to know more about commissionRate fields and fee collection function, please refer to Monetization / Take Fees
Last modified 12d ago