Suave SDK makes it easy to get and execute cross-chain swap routes.This includes examples of execution and what do to in case of failure.
All execution will happen on the client side via whatever wallet provider is currently connected.
import { SuaveSDK } from 'suave-sdk';const sdk = new SuaveSDK({ apiKey: 'your-api-key'});// Get the best routes to execute a swapawait sdk.getRoutes('tokenA','chainA',amount, 'tokenB','chainB').then(routes => { console.log('Best Routes:', routes); return routes[0]; //the first route is the best route});// Execute the routeawait sdk.executeRoute(route).then((txs)=>{ console.log('Txs:', txs);//List of tx receipts for the executed route.}).catch((error)=>{ console.error('Error:', error);});.on('step-update',(step)=>{ //OPTIONAL console.log('step-update:', step); //A change of state for the steps});.on('step-failed',(unexecutedSteps)=>{ console.log('step-failed:', unexecutedSteps); //A step failed //You can restart the execution in case of failure}//OPTIONAL) //Restart the execution from the failed stepawait sdk.executeRoute(unexecutedSteps,{ retry:2, //Retry the execution 2 more times onRetry:(retry)=>{ console.log('retry:', retry); //A retry is about to happen }});