try {
// Get trading routes
const routes = await sdk.Quoter.getBestQuotes(quoteParams)
if (routes.length === 0) {
throw new Error('No trading routes available')
}
// Execute swap with the best routes
const transaction = await sdk.AggSwap.swapWithTradingRoutes(routes)
console.log('Transaction prepared successfully!')
console.log('Transaction data:', transaction.serialize())
// Sign and execute the transaction with your wallet
// This depends on your wallet integration
} catch (error) {
console.error('Swap error:', error.message)
}
import { initMainnetSDK, InputFindBestQuotesParams } from '@ferra-labs/aggregator'
async function performSwap() {
// Initialize SDK
const sdk = useAggreratorFerraSdk(address)
// Define swap parameters
const swapParams: InputFindBestQuotesParams = {
from: '0x2::sui::SUI',
to: '0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN',
amount: '1000000000', // 1 SUI
slippageTolerance: 0.5
}
try {
// Step 1: Get best quotes
console.log('Finding best routes...')
const routes = await sdk.Quoter.getBestQuotes(swapParams)
if (routes.length === 0) {
console.log('No routes available for this swap')
return
}
console.log(`Found ${routes.length} routes`)
console.log('Best route output:', routes[0].outputAmount)
// Step 2: Execute swap
console.log('Preparing swap transaction...')
const transaction = await sdk.AggSwap.swapWithTradingRoutes(routes)
console.log('✅ Swap transaction prepared successfully!')
} catch (error) {
console.error('❌ Swap failed:', error.message)
}
}
// Run the example
performSwap()