Loading...
Loading...
Configure Nexus SDK intent/allowance/swap intent hooks and event streaming. Use when integrating approval flows, intent previews, or real-time progress events (NEXUS_EVENTS).
npx skill4agent add availproject/nexus-sdk nexus-sdk-hooks-eventssdk.setOnIntentHook(callback)sdk.setOnAllowanceHook(callback)sdk.setOnSwapIntentHook(callback)allow(...)deny()sdk.setOnIntentHook((data) => {
// data: OnIntentHookData
});allow(): voiddeny(): voidintent: ReadableIntentrefresh(selectedSources?: number[]): Promise<ReadableIntent>dataallow()deny()refresh()deny()sdk.setOnAllowanceHook((data) => {
// data: OnAllowanceHookData
});allow(decisions): voiddecisionssources'min''max'bigintdeny(): voidsources: AllowanceHookSourcesdecisionssourcesallow(decisions)deny()decisions.length === sources.lengthINVALID_VALUES_ALLOWANCE_HOOKsdk.setOnSwapIntentHook((data) => {
// data: OnSwapIntentHookData
});allow(): voiddeny(): voidintent: SwapIntentrefresh(): Promise<SwapIntent>dataallow()deny(){ onEvent }NEXUS_EVENTS.STEPS_LISTBridgeStepType[]NEXUS_EVENTS.STEP_COMPLETEBridgeStepTypeNEXUS_EVENTS.SWAP_STEP_COMPLETESwapStepTypeSTEPS_LISTSTEP_COMPLETESWAP_STEP_COMPLETEdeny()allow()deny()NexusErrorimport { NexusError, ERROR_CODES } from '@avail-project/nexus-core'USER_DENIED_INTENTUSER_DENIED_ALLOWANCEUSER_DENIED_INTENT_SIGNATUREINVALID_VALUES_ALLOWANCE_HOOKdecisionsSDK_NOT_INITIALIZEDWALLET_NOT_CONNECTEDCONNECT_ACCOUNT_FAILEDsdk.initialize(...)INVALID_INPUTINVALID_ADDRESS_LENGTHINSUFFICIENT_BALANCENO_BALANCE_FOR_ADDRESSTOKEN_NOT_SUPPORTEDCHAIN_NOT_FOUNDQUOTE_FAILEDSWAP_FAILEDRATES_CHANGED_BEYOND_TOLERANCESLIPPAGE_EXCEEDED_ALLOWANCERFF_FEE_EXPIREDTRANSACTION_TIMEOUTLIQUIDITY_TIMEOUTTRANSACTION_REVERTEDCOSMOS_ERRORINTERNAL_ERRORerr.data?.detailsimport { NexusError, ERROR_CODES } from '@avail-project/nexus-core';
export function getReadableNexusError(err: unknown): string {
if (err instanceof NexusError) {
switch (err.code) {
case ERROR_CODES.USER_DENIED_INTENT:
case ERROR_CODES.USER_DENIED_ALLOWANCE:
case ERROR_CODES.USER_DENIED_INTENT_SIGNATURE:
return 'Transaction cancelled by user';
case ERROR_CODES.INSUFFICIENT_BALANCE:
return 'Insufficient balance';
case ERROR_CODES.SLIPPAGE_EXCEEDED_ALLOWANCE:
case ERROR_CODES.RATES_CHANGED_BEYOND_TOLERANCE:
return 'Price changed too much. Please try again.';
case ERROR_CODES.TRANSACTION_TIMEOUT:
return 'Transaction timed out. Please retry.';
default:
return err.message;
}
}
if (err instanceof Error) return err.message;
return 'Unknown error';
}intentRef.current = null; allowanceRef.current = null; swapIntentRef.current = null;