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.
async function executeRoute (
signer: Signer,
route: Route,
settings?: ExecutionSettings
): Promise<Route>
interface ExecutionSettings {
updateRouteHook?: 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,
executeRoute
takes an optional settings
object as a third parameter that can contain an updateCallback
function. This function will be called every time the SDK performs an action on the route. You can use this callback to keep track of the execution status. The switchChainHook
is explained in more detail here.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. 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.
function updateExecutionSettings (
settings: ExecutionSettings,
route: Route
): void
This function updates the execution settings of a route. Please see executeroute for the
ExecutionSettings
interface.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. // 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})
Last modified 2mo ago