# Quick Start

This guide will help you get up and running with the Ferra Aggregator SDK in minutes.

### 1. Initialize the SDK

#### Mainnet Setup

```typescript
import { initFerraAggregatorSDK } from '@ferra-labs/aggregator'

const useAggreratorFerraSdk = (address: string) => {
  return useMemo(
    () =>
      initFerraAggregatorSDK({
        network: NETWORK,
        fullNodeUrl: FULL_NODE_URL,
        wallet: address,
      }),
    [address]
  );
};
```

### 2. Get Best Quotes

Find the best trading routes for your swap:

```typescript
import { InputFindBestQuotesParams } from '@ferra-labs/aggregator'

const quoteParams: InputFindBestQuotesParams = {
  from: '0x2::sui::SUI', // SUI token
  to: '0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN', // USDC token
  amount: '1000000000', // 1 SUI (9 decimals)
  slippageTolerance: 0.5 // 0.5% slippage tolerance
}

try {
  const routes = await sdk.Quoter.getBestQuotes(quoteParams)
  
  if (routes.length > 0) {
    console.log('Best route found:', routes[0])
  } else {
    console.log('No routes available')
  }
} catch (error) {
  console.error('Quote error:', error.message)
}
```

### 3. Execute Swap

Execute the swap using the best route:

```typescript
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)
}
```

### 4. Complete Example

Here's a complete working example:

```typescript
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()
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ferra.ag/integration/aggregator-internal-deprecated/typescript-sdk/quick-start.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
