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.
Swap Request
from
* StringDescription: The asset X that user likes to swap
Example:
BSC.BNB
to
* StringDescription: The asset Y that user wants to swap X into that
Example:
AVAX_CCHAIN.USDT.E--0xc7198437980c041c805a1edcba50c1ce5db95118
amount
* StringDescription: The machine-readable amount of asset X that is going to be swapped
Example:
100000000000000000
slippage
* StringDescription: User slippage for this swap
Example:
1.5
which means 1.5% slippage.
fromAddress
* StringDescription: User source wallet address
toAddress
* StringDescription: User destination wallet address
disableEstimate
BooleanDescription: 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 thedisableEstimate
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
StringDescription: Referrer wallet address
referrerFee
StringDescription: 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 set
referrerAddress
andreferrerFee
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 yourreferrerAddress
wallet as the referral reward. Please check our document on Basic API Monetization for more details on this.
referrerCode
StringDescription: Referrer code
swappers
StringDescription: List of all accepted swappers, an empty list means no filter is required.
swappersExclude
BooleanDescription: Defines the provided swappers as the include/exclude list. Default is false (include)
swapperGroups
StringDescription: The list of all included/excluded swappers based on tag, empty list means no filter is required.
swappersGroupsExclude
BooleanDescription: Defines the provided swappers' tags as the include/exclude list. Default is false (include)
infiniteApprove
BooleanDescription: Use this parameter if you want infinite approve from user
contractCall
BooleanCaution: 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
StringDescription: List of all messaging protocols, an empty list means no filter is required.
sourceContract
StringDescription: Address of your contract on source chain (will be called in case of refund in the source chain)
destinationContract
StringDescription: Address of your contract on destination chain (will be called in case of success/refund in the destination chain)
imMessage
StringDescription: 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
andimMessage
arguments in both quote and swap calls. You could also usemessagingProtocols
field to filter protocols used for message passing. You could read our message passing document for more details.
avoidNativeFee
BooleanDescription: 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
BooleanDescription: 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 onamountRestrictions
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
Description: Transaction data for this route.
Example: Sample Basic Transactions
Last updated