Skip to main content

getMyIntents

Retrieve user’s historical intents with pagination.
await sdk.getMyIntents(page?: number): Promise<RequestForFunds[]>

Parameters

page
number
default:"1"
Page number for pagination (1-based)

Returns

RequestForFunds[]
array
Array of user’s intents

Example

const intents = await sdk.getMyIntents(1);

console.log(`Found ${intents.length} intents`);

intents.forEach(intent => {
  console.log('\nIntent #', intent.id);
  console.log('Status:', {
    deposited: intent.deposited,
    fulfilled: intent.fulfilled,
    refunded: intent.refunded,
  });
  console.log('Destination:', intent.destinationChain.name);
  console.log('Explorer:', intent.explorerUrl);
});

Pagination

// Fetch multiple pages
async function getAllIntents() {
  const allIntents = [];
  let page = 1;
  let hasMore = true;
  
  while (hasMore) {
    const intents = await sdk.getMyIntents(page);
    
    if (intents.length === 0) {
      hasMore = false;
    } else {
      allIntents.push(...intents);
      page++;
    }
  }
  
  return allIntents;
}

const allIntents = await getAllIntents();
console.log(`Total intents: ${allIntents.length}`);

refundIntent

Request a refund for a failed or stuck intent. This triggers the refund process if not already initiated by the system.
await sdk.refundIntent(intentID: number): Promise<void>

Parameters

intentID
number
required
Intent ID to refund (obtained from getMyIntents())

Example

// Get intent ID from history
const intents = await sdk.getMyIntents(1);
const stuckIntent = intents.find(i => !i.fulfilled && !i.refunded);

if (stuckIntent) {
  const intentID = stuckIntent.id;
  
  try {
    await sdk.refundIntent(intentID);
    console.log(`Refund initiated for intent #${intentID}`);
  } catch (error) {
    console.error('Refund failed:', error);
  }
}

When to Request Refund

Request a refund when:
  1. Intent Expired: The intent has passed its expiry time without being fulfilled
  2. Stuck Intent: The intent has been pending for an unusually long time
  3. Failed Transaction: Source deposits were made but fulfillment failed
Only unfulfilled intents can be refunded. Fulfilled intents cannot be reversed.

Intent Hooks

Set up hooks to handle intent approvals:

setOnIntentHook

Called when the SDK needs user approval for a bridge/transfer intent.
sdk.setOnIntentHook(callback: OnIntentHook): void

Example

sdk.setOnIntentHook(({ intent, allow, deny }) => {
  // Display intent details
  console.log('Intent Preview:');
  console.log('Sources:', intent.sources);
  console.log('Destination:', intent.destination);
  console.log('Fees:', intent.fees);
  
  // User confirmation
  const confirmed = confirm(
    `Bridge ${intent.sourcesTotal} ${intent.token.symbol} to ${intent.destination.chainName}?`
  );
  
  if (confirmed) {
    allow();
  } else {
    deny(); // Throws USER_DENIED_INTENT error
  }
});

Intent Hook Data

OnIntentHookData
object

Tracking Intent Progress

Monitor intent status in real-time:
import { NEXUS_EVENTS } from '@avail-project/nexus-core';

let currentIntentId: number | null = null;

sdk.setOnIntentHook(({ intent, allow }) => {
  console.log('Intent created');
  allow();
});

const result = await sdk.bridge(
  {
    token: 'USDC',
    amount: 100_000_000n,
    toChainId: 137,
  },
  {
    onEvent: (event) => {
      if (event.name === NEXUS_EVENTS.STEP_COMPLETE) {
        const step = event.args;
        
        if (step.type === 'INTENT_SUBMITTED') {
          currentIntentId = step.data?.intentID || null;
          console.log('Intent ID:', currentIntentId);
          console.log('Track at:', step.data?.explorerURL);
        }
        
        if (step.type === 'INTENT_FULFILLED') {
          console.log('Intent fulfilled!');
        }
      }
    },
  }
);

// Later, check status
if (currentIntentId) {
  const intents = await sdk.getMyIntents();
  const intent = intents.find(i => i.id === currentIntentId);
  console.log('Intent status:', intent);
}

Error Handling

import { NexusError, ERROR_CODES } from '@avail-project/nexus-core';

try {
  const intents = await sdk.getMyIntents();
  
  // Try to refund an intent
  if (intents.length > 0) {
    await sdk.refundIntent(intents[0].id);
  }
} catch (error) {
  if (error instanceof NexusError) {
    switch (error.code) {
      case ERROR_CODES.REFUND_FAILED:
        console.error('Refund request failed');
        break;
      case ERROR_CODES.REFUND_CHECK_ERROR:
        console.error('Error checking refund status');
        break;
      case ERROR_CODES.SDK_NOT_INITIALIZED:
        console.error('SDK not initialized');
        break;
      default:
        console.error('Error:', error.message);
    }
  }
}

Bridge Operations

Learn about bridge operations

Events & Steps

Track operation progress

Build docs developers (and LLMs) love