We allow you to execute any on-chain or cross-chain swap and bridging transfer and a combination of both..
executeRoute
function. Here is a simplified example of how to use it:
executeRoute
function internally manages allowance and balance checks, chain switching, transaction data retrieval, transactions submission, and transactions status tracking.
route
(Route
): The route to be executed.
executionOptions
(ExecutionOptions
, optional): An object containing settings and callbacks for execution.
Promise<RouteExtended>
: Resolves when execution is done or halted and rejects when it is failed.updateRouteHook
updatedRoute
(RouteExtended
): The updated route object.updateTransactionRequestHook
updatedTxRequest
(TransactionRequestParameters
): The transaction request parameters need to be updated.Promise<TransactionParameters>
: The modified transaction parameters.
acceptExchangeRateUpdateHook
true
. If this hook is not provided or if you return false
, the SDK will throw an error. This hook is an ideal place to prompt your users to accept the new exchange rate.
toToken
(Token
): The destination token.
oldToAmount
(string
): The previous amount of the target token.
newToAmount
(string
): The new amount of the target token.
Promise<boolean | undefined>
: Whether the update is accepted.
TransactionError: Exchange rate has changed!
switchChainHook
chainId
(number
): The ID of the chain to which to switch.Promise<WalletClient | undefined>
: The new wallet client after switching chains.
executeInBackground
boolean
false
disableMessageSigning
boolean
false
updateRouteExecution
function is used to update the settings of an ongoing route execution.
One common use case is to push the execution to the background, for example, when a user navigates away from the execution page in your dApp. When this function is called, the execution will continue until it requires user interaction (e.g., signing a transaction or switching the chain). At that point, the execution will halt, and the executeRoute
promise will be resolved.
To move the execution back to the foreground and make it active again, you can call resumeRoute
with the same route object. The execution will then resume from where it was halted.
route
(Route
): The active route to be updated.
executionOptions
(ExecutionOptions
, required): An object containing settings and callbacks for execution.
resumeRoute
function is used to resume a halted, aborted, or failed route execution from the point where it stopped. It is crucial to call resumeRoute
with the latest active route object returned from the executeRoute
function or the most recent version of the updated route object from the updateRouteHook
.
route
(Route
): The route to be resumed to execution.
executionOptions
(ExecutionOptions
, optional): An object containing settings and callbacks for execution.
Promise<RouteExtended>
: Resolves when execution is done or halted and rejects when it is failed.stopRouteExecution
function is used to stop the ongoing execution of an active route. It stops any remaining user interaction within the ongoing execution and removes the route from the execution queue. However, if a transaction has already been signed and sent by the user, it will be executed on-chain.
route
(Route
): The route that is currently being executed and needs to be stopped.Route
: The route object that was stopped.route
object includes multiple step
objects, each representing a set of transactions that should be completed in the specified order. Each step can include multiple transactions that require a signature, such as an allowance transaction followed by the main swap or bridge transaction. Read more LI.FI Terminology.
execution
objectstep
within a route
has an execution
object. This object contains all the necessary information to track the execution progress of that step. The execution
object has a process
array where each entry represents a sequential stage in the execution. The latest process entry contains the most recent information about the execution stage.
process
array within the execution
object details each step’s progression. Each process
object has a type and status and might also include a transaction hash and a link to a blockchain explorer after the user signs the transaction.
updateRouteHook
callback and iterate through the route steps, checking their execution
objects. Look at the process
array to get the latest information about the execution stage. The most recent entry in the process
array will contain the latest transaction hash, status, and other relevant details.
getActiveRoutes
and getActiveRoute
functions.
executeRoute
, you need to convert it to a route object first. We provide convertQuoteToRoute
helper function to transform quote objects to route objects. This applies to both standard and contract call quotes.
executeRoute
function, you can execute routes and quotes manually. This approach requires developers to handle the logic for obtaining transaction data, switching chains, sending transactions, and tracking transaction status independently.
Initially, when route objects are requested, they do not include transaction data. This is because multiple route options are provided, and generating transaction data for all options would substantially delay the response. Each route consists of multiple steps, and once a user selects a route, transaction data for each step should be requested individually using the getStepTransaction
function (see example below). Each step should be executed sequentially, as each step depends on the outcome of the previous one.
On the other hand, quote objects are returned with transaction data included, so the getStepTransaction
call is not necessary, and they can be executed immediately.
After sending a transaction using the obtained transaction data, you can track the status of the transaction using the getStatus
function. This function helps you monitor the progress and completion of each transaction. Read more Status of a Transaction.
Here’s a simplified example. For the sake of simplicity, this example omits balance checks, transaction replacements, error handling, chain switching, etc. However, in a real implementation, you should include these additional functionalities to have a robust solution and ensure reliability.
getStepTransaction
step
(LiFiStep
): The step object for which we need to get transaction data.
options
(RequestOptions
, optional): An object containing request options, such as AbortSignal
, which can be used to cancel the request if necessary.
Promise<LiFiStep>
: A promise that resolves to the step object containing the transaction data.getStatus
params
(GetStatusRequest
): The parameters for checking the status include the transaction hash, source and destination chain IDs, and the DEX or bridge name.
options
(RequestOptions
, optional): An object containing request options, such as AbortSignal
, which can be used to cancel the request if necessary.
Promise<StatusResponse>
: A promise that resolves to a status response containing all relevant information about the transfer.