4⃣
Execute a Route (Transfer)
We allow you to execute any on-chain or cross-chain swap and bridging process and a combination of both.
After fetching routes, you can execute one using executeRoute as described here.

executeRoute

async function executeRoute (
signer: Signer,
route: Route,
settings?: ExecutionSettings
): Promise<Route>
interface ExecutionSettings {
updateCallback?: CallbackFunction
switchChainHook?: SwitchChainHook
}
Executing a route requires a signer to send transactions to involved contracts. You can read more about signers in the official ethers documentation. Once you have the route and the signer, you call executeRoute.
const route = await LiFi.executeRoute(signer, route)
Note that the function will return the executed route once the execution has been completed.
In addition to the first two parameters, executeRoutetakes an optional settings object as a third parameter that can contain an updateCallback function. This function will be called every time an action has been performed on the route by the SDK. You can use this callback to keep track of the execution status. The switchChainHook is explained in more detail here.

Controlling the execution of a route

moveExecutionToBackground

function moveExecutionToBackground (route: Route): void
Once a route execution has started, it can be pushed "to the background" by calling this method. Once called, the execution will continue until it reaches a point where user interaction is required (i.e. signing a transaction). If such a point is reached, the execution will halt until resumeRoute is called with the same route object. The execution will then pick up where it halted.

stopExecution

function stopExecution (route: Route): Route
This method immediately stops the execution of a given route. If a transaction has already been signed and sent by the user, it will be executed on-chain.

updateExecutionSettings

function updateExecutionSettings (
settings: ExecutionSettings,
route: Route
): void
This function updates the execution settings of a route. Please see executeRoute for the ExecutionSettingsinterface.

resumeRoute

async function resumeRoute (
signer: Signer,
route: Route,
settings?: ExecutionSettings
): Promise<Route>
resumeRoute takes in the same parameters as executeRoute and will resume either a route that has been stopped or a route that has been moved to the background.
​

Example code snippet

Building on the code from Broken linkwe can now choose a route and execute it.
// getting routes
const routeOptions =Β { ... }
const routesRequest = { ... }
​
const result = await Lifi.getRoutes(routesRequest)
const routes = result.routes
const chosenRoute = routes[0]
​
const updateCallback = (updatedRoute: Route) => {
console.log('Ping! Everytime a status update is made!')
}
​
// executing a route
const route = await LiFi.executeRoute(signer, chosenRoute, {...updateCallback})
​