Create Transaction (Swap)

Get final quote and create the transaction

Swap API

It's similar to the quote method but gives the actual transaction data in response besides the route.

const swapResponse = await rango.swap({
    from: {"blockchain": "BSC", "symbol": "BNB", "address": null},
    to: {"blockchain": "AVAX_CCHAIN", "symbol": "USDT.E", "address": "0xc7198437980c041c805a1edcba50c1ce5db95118"},
    amount: "100000000000000000",
    fromAddress: "0xeb2629a2734e272bcc07bda959863f316f4bd4cf",
    toAddress: "0xeb2629a2734e272bcc07bda959863f316f4bd4cf",
    disableEstimate: true,
    slippage: '1.0',
})

Swap Request

  • from * String

    • Description: The asset X that user likes to swap

    • Example: BSC.BNB

  • to * String

    • Description: The asset Y that user wants to swap X into that

    • Example: AVAX_CCHAIN.USDT.E--0xc7198437980c041c805a1edcba50c1ce5db95118

  • amount * String

    • Description: The machine-readable amount of asset X that is going to be swapped

    • Example: 100000000000000000

  • slippage * String

    • Description: User slippage for this swap

    • Example: 1.5 which means 1.5% slippage.

  • fromAddress * String

    • Description: User source wallet address

  • toAddress * String

    • Description: User destination wallet address

  • disableEstimate Boolean

    • Description: This field should be false when the client wants to preview the route to the user and true when the user accepts the swap. If it's true, the server will be much slower to respond but will check some prerequisites, including the balance of X and any required fees in the user's wallets. By default, when you call the swap method, Rango API performs some validations e.g. having enough balance for the input amount and the swap fee, and gives an error if doesn't meet the criteria. If you want to disable it and do it on your own side, you could pass true value for the disableEstimate argument.

    • Caution: If you are checking the balance and fee amount on your client side, it is recommended to set this parameter to true, as it will significantly reduce the response time.

  • referrerAddress String

    • Description: Referrer wallet address

  • referrerFee String

    • Description: Referrer fee in percent, (e.g. 0.3 means: 0.3% fee based on input amount)

    • Caution: By default, Rango does not charge a fee on your behalf unless you setreferrerAddress and referrerFee parameters when your dApp sends a request to the swap method. In this case, Rango charges an additional fee equal to (referrerFee / 100) x inputAmount and transfer it to your referrerAddress wallet as the referral reward. Please check our document on Basic API Monetization for more details on this.

  • referrerCode String

  • swappers String

    • Description: List of all accepted swappers, an empty list means no filter is required.

  • swappersExclude Boolean

    • Description: Defines the provided swappers as the include/exclude list. Default is false (include)

  • swapperGroups String

    • Description: The list of all included/excluded swappers based on tag, empty list means no filter is required.

  • swappersGroupsExclude Boolean

    • Description: Defines the provided swappers' tags as the include/exclude list. Default is false (include)

  • infiniteApprove Boolean

    • Description: Use this parameter if you want infinite approve from user

  • contractCall Boolean

    • Caution: set this parameter to true if you want to send transactions through a contract. It will filter swappers that are not possible to be called by another contract.

  • messagingProtocols String

    • Description: List of all messaging protocols, an empty list means no filter is required.

  • sourceContract String

    • Description: Address of your contract on source chain (will be called in case of refund in the source chain)

  • destinationContract String

    • Description: Address of your contract on destination chain (will be called in case of success/refund in the destination chain)

  • imMessage String

    • Description: The message that you want to pass to your contract on the destination chain. When transferring tokens using Rango cross-chain API, you could pass a random message from the source chain to the destination and call your contract on the destination. In order to do so, you need to pass your contracts on source & destination chains plus an arbitrary hex message. In order to do that, you should specify sourceContract, destinationContract and imMessage arguments in both quote and swap calls. You could also use messagingProtocols field to filter protocols used for message passing. You could read our message passing document for more details.

  • avoidNativeFee Boolean

    • Description: When this condition is true, swappers that charge fees in native tokens will be excluded. For instance, when called from an AA account.

    • Caution: Swappers like Stargate charge user fees in native tokens instead of the input amount, causing the transaction value to differ from the user's input amount. Alternatively, the user may need to transfer native tokens in a contract call to cover these protocol fees. Although you can disable these protocols using this flag, we do not recommend it as it reduces the coverage of single-step routes.

  • enableCentralizedSwappers Boolean

    • Description: Pass this flag true if you want to enable routing through the centralized solutions. Default is false.

    • Caution: To enable these swappers, you must pass the user's IP to the Rango API for compliance checks. Additionally, user funds may be held for KYC if their wallet is flagged as risky by the screening solutions implemented by these protocols.

Swap Response

  • requestId

    • Description: The unique request Id which is generated for this request by the server. It should be passed down to all other endpoints if this swap continues on.

    • Example: d10657ce-b13a-405c-825b-b47f8a5016ad

  • resultType

    • Description: Status of the route.

    • Possible Values:

      • OK => Best route found. Everything is OK.

      • HIGH_IMPACT => The route has high price impact, we recommend not proceeding with the next step. The Rango API may give you an error in the next step to prevent potential losses.

      • INPUT_LIMIT_ISSUE => There is a limit issue for the input amount. You could suggest user to increase or decrease the input amount based on amountRestrictions field in response.

      • NO_ROUTE => No routes found.

    • Caution: This is the status of route (similar to this field in quote response). If there was any error in creating tx, it will be appear in error field. So you could check (error !== null) && (status === 'OK') to make sure everything is ok before proceeding with the next step.

  • route

    • Description: The quote route object. Similar to the quote response.

  • error

    • Description: Error message (raw string) if there is any problem in creating transaction. error == null <=> tx != null

  • tx

Last updated