Skip to main content

Requesting swap data

Using the swap method, you can get a transaction data for swap, obtained on previous step. You can check available request params here. Here is an example of requesting data 1.05 ETH in Ethereum Blockchain for Matic in Polygon Blockchain
const quoteParams = {
    "dstTokenAddress": "0x0000000000000000000000000000000000000000",
    "dstTokenBlockchain": "POLYGON",
    "referrer": "rubic.exchange",
    "srcTokenAddress": "0x0000000000000000000000000000000000000000",
    "srcTokenAmount": "1.05",
    "srcTokenBlockchain": "ETH"
};
const bestTrade = await axios.post('https://api-v2.rubic.exchange/api/routes/quoteBest', {
  params: quoteParams
});
const swapParams = {
    ...quoteParams,
    id: bestTrade.id,
    fromAddress: "Your wallet address"
};
const tradeWithData = await axios.post('https://api-v2.rubic.exchange/api/routes/swap', {
  params: swapParams
});

console.log(tradeWithData.transaction);
/**
{
  data: 0x.....;
  to: 0x....;
  value: 0
}
*/
Open Rubic Swagger

Swap request params

Required params

FieldTypeDescriptionExample
srcTokenAddressstringSource token address0x0000000000000000000000000000000000000000
srcTokenBlockchainstringSource token blockchainETH
srcTokenAmountstringSource token amount with decimals1.05
dstTokenAddressstringDestination token address0x0000000000000000000000000000000000000000
dstTokenBlockchainstringDestination token blockchainPolygon
referrerstringReferrer addressrubic.exchange
fromAddressstringWallet address to make tx from0x0000000000000000000000000000000000000000
idstringTrade identifier obtained on quote step08df660f-49e5-42fd-a1f1-cdf0af5eac4c

Optional params

FieldTypeDescriptionExample
nativeBlackliststring[]Native providers to exclude from calculation[“xy”, “symbiosis”]
showFailedRoutesbooleanShow failed routes in response or notfalse
integratorAddressstringIntegrator address to set feesGet the address from our BD team
slippagenumber minimum: 0.01 maximum: 0.5Slippage tolerance in percents for trade, 0.01 equals 1%0.02
receiverstringWallet address to send tokens to on the destination blockchain0x000000…0000000
preferredProviderstringPreferred provider for calculationlifi
foreignBlacklist{lifi?: string[];rango?: string[]}Foreign providers to exclude from calculation{ lifi: ["stargate"] }
timeoutnumber minimum: 5 maximum: 60Calculation timeout in seconds32
enableTestnetsbooleanInclude testnet in calculationsfalse
enableChecksbooleanShould we perform transaction simulation and wallet checks or no default: truefalse

Swap Response params

FieldTypeDescriptionExample
idstringTrade identifier60e513d5-8a2d-4e0d-b513-6236d86bc7da
quoteQuoteRequestDtoQuote params that you send
swapTypecross-chain,on-chainType of swapcross-chain
providerTypeCrossChainTradeType | OnChainTradeTypeInner provider which we use to swapRango
feesFeesDtoDifferent fees used for swap
routingRoutingDto[]Path tokens take during the swap process
transactionTransactionDtoTransaction config to perform approve{ "approvalAddress": "string" }
warningsErrorDto[]Specific info about quote params provider{ "code": 301, "reason": "amountTooLow" }