getMyIntents
Retrieve user’s historical intents with pagination.
await sdk.getMyIntents(page?: number): Promise<RequestForFunds[]>
Parameters
Page number for pagination (1-based)
Returns
Array of user’s intentsShow RequestForFunds properties
Block explorer URL for this intent
Whether deposits have been made
Whether the intent has been fulfilled
Whether the intent has been refunded
Unix timestamp when the intent expires
Destination chain information
Destination token detailsShow array item properties
Source chain detailsShow array item properties
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);
});
// 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
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:
- Intent Expired: The intent has passed its expiry time without being fulfilled
- Stuck Intent: The intent has been pending for an unusually long time
- 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
Complete intent details with sources, destination, fees, and token info
Call to approve the intent
Call to reject the intent (throws USER_DENIED_INTENT error)
refresh
(selectedSources?: number[]) => Promise<ReadableIntent>
required
Call to refresh the intent with optionally different source chains
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