Troubleshooting

Common issues and their solutions when working with the Aori TypeScript SDK.

Common Issues

Installation Issues

Module Resolution Errors

Error

Cannot find module '@aori/aori-ts' or its corresponding type declarations

Solution:

# Clear npm cache
npm cache clean --force

# Reinstall dependencies
rm -rf node_modules package-lock.json
npm install @aori/aori-ts

TypeScript Errors

Error

Type 'string | number | bigint' is not assignable to type 'string'

Solution:

// Always convert inputAmount to string
const quote = await getQuote({
  // ... other params
  inputAmount: amount.toString() // Convert to string
});

WebSocket Issues

Connection Failures

Error

WebSocket connection failed: ECONNREFUSED

Solution:

const ws = new AoriWebSocket('wss://api.aori.io', {
  onError: (error) => {
    console.error('WebSocket error:', error);
    // Implement reconnection logic
    setTimeout(() => ws.connect(), 5000);
  },
  onDisconnect: (event) => {
    if (!event.wasClean) {
      // Unexpected disconnect, try to reconnect
      setTimeout(() => ws.connect(), 1000);
    }
  }
});

Message Handling

Robust Message Handling

const ws = new AoriWebSocket('wss://api.aori.io', {
  onMessage: (event) => {
    try {
      // Validate event structure
      if (!event.eventType || !event.order) {
        console.warn('Invalid event structure:', event);
        return;
      }
      
      // Process event
      handleOrderEvent(event);
    } catch (error) {
      console.error('Error processing WebSocket message:', error);
    }
  }
});

Chain-Specific Issues

Gas Estimation Errors

Error

Error: Gas estimation failed

Solution:

// Add buffer to gas estimates for cross-chain operations
const CROSS_CHAIN_GAS_BUFFER = 1.2; // 20% buffer

// When interacting with contracts after swap
const gasEstimate = await contract.estimateGas.method();
const gasLimit = Math.floor(Number(gasEstimate) * CROSS_CHAIN_GAS_BUFFER);

Chain ID Mismatches

Chain Validation

import { getChainInfoByKey } from '@aori/aori-ts';

function validateChains(inputChain: string, outputChain: string) {
  const inputInfo = getChainInfoByKey(inputChain);
  const outputInfo = getChainInfoByKey(outputChain);
  
  if (!inputInfo) {
    throw new Error(`Unsupported input chain: ${inputChain}`);
  }
  
  if (!outputInfo) {
    throw new Error(`Unsupported output chain: ${outputChain}`);
  }
  
  return { inputInfo, outputInfo };
}

Best Practices

Comprehensive Error Handling

class AoriService {
  async executeSwapWithRetry(request: QuoteRequest, signer: any) {
    const errors = [];
    
    for (let attempt = 1; attempt <= 3; attempt++) {
      try {
        // Step 1: Get quote
        const quote = await this.getQuoteWithFallback(request);
        
        // Step 2: Sign order
        const signature = await this.signWithTimeout(quote, signer);
        
        // Step 3: Submit swap
        const swap = await this.submitWithValidation({
          orderHash: quote.orderHash,
          signature
        });
        
        return swap;
        
      } catch (error) {
        errors.push({ attempt, error: error.message });
        
        if (this.isRetryableError(error) && attempt < 3) {
          await this.delay(1000 * attempt);
          continue;
        }
        
        throw new Error(`Failed after ${attempt} attempts: ${JSON.stringify(errors)}`);
      }
    }
  }
  
  private isRetryableError(error: any): boolean {
    const retryableMessages = [
      'ECONNRESET',
      'ETIMEDOUT',
      'rate limit',
      'temporarily unavailable'
    ];
    
    return retryableMessages.some(msg => 
      error.message?.toLowerCase().includes(msg.toLowerCase())
    );
  }
  
  private async delay(ms: number) {
    return new Promise(resolve => setTimeout(resolve, ms));
  }
}

Environment Configuration

# Environment Variables
AORI_API_URL=https://api.aori.io
AORI_WS_URL=wss://api.aori.io
AORI_API_KEY=your_prod_api_key

Environment Usage

const config = {
  apiUrl: process.env.AORI_API_URL || 'https://api.aori.io',
  wsUrl: process.env.AORI_WS_URL || 'wss://api.aori.io',
  apiKey: process.env.AORI_API_KEY,
};

// Use configuration
const quote = await getQuote(request, config.apiUrl, config.apiKey);

Getting Help

If you continue to experience issues:

  1. Check the GitHub Issues: github.com/aori-io/aori-ts/issues
  2. Join our Telegram
  3. Review the Examples: Check the advanced examples for working implementations
  4. API Status: Check status.aori.io for any ongoing issues