nexus-sdk-swap-flows
Original:🇺🇸 English
Translated
Implement swapWithExactIn, swapWithExactOut, and swapAndExecute flows with Nexus SDK. Use when wiring swap operations, swap intent hooks, or swap event progress updates.
12installs
Added on
NPX Install
npx skill4agent add availproject/nexus-elements nexus-sdk-swap-flowsTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Swap Flows
Call swapWithExactIn(input, options?)
- Use when input amount is fixed and sources are known.
- Signature:
sdk.swapWithExactIn(input, { onEvent? })
- Params ():
ExactInSwapInputfrom: { chainId: number; amount: bigint; tokenAddress: Hex }[]toChainId: numbertoTokenAddress: Hex
- Notes:
- Ensure amounts are in smallest units.
from - Use chain-specific token addresses (see ).
TOKEN_CONTRACT_ADDRESSES
- Ensure
- Result ():
SwapResult{ success: true; result: SuccessfulSwapResult }
Call swapWithExactOut(input, options?)
- Use when desired output amount is fixed.
- Signature:
sdk.swapWithExactOut(input, { onEvent? })
- Params ():
ExactOutSwapInputtoChainId: numbertoTokenAddress: HextoAmount: bigint- (optional native token output)
toNativeAmount?: bigint - (optional)
fromSources?: { chainId: number; tokenAddress: Hex }[]
- Notes:
- If is omitted, SDK auto-selects sources.
fromSources
- If
Call swapAndExecute(input, options?)
- Use to perform swap (if needed) and then execute a contract call.
- Signature:
sdk.swapAndExecute(input, { onEvent? })
- Params ():
SwapAndExecuteParamstoChainId: numbertoTokenAddress: HextoAmount: bigintfromSources?: { chainId: number; tokenAddress: Hex }[]execute: SwapExecuteParams
- :
SwapExecuteParamsto: Hexdata?: Hexvalue?: bigintgas: bigintgasPrice?: 'low' | 'medium' | 'high'tokenApproval?: { token: Hex; amount: bigint; spender: Hex }
- Result ():
SwapAndExecuteResult- (null if swap skipped)
swapResult: SuccessfulSwapResult | null
Use token addresses and chains
- Use SDK constants for addresses and chain IDs:
SUPPORTED_CHAINSTOKEN_CONTRACT_ADDRESSES
Attach swap intent hook
- Set and call
sdk.setOnSwapIntentHook(...)to proceed.allow() - If the hook is not set, the SDK auto-approves.
Stream swap events
- Listen for .
NEXUS_EVENTS.SWAP_STEP_COMPLETE - Handle special cases like swap skipped (e.g., already on destination token).
Convert amounts to bigint
- Use or
sdk.utils.parseUnits(value, decimals) - when decimals vary by chain.
sdk.convertTokenReadableAmountToBigInt(value, tokenSymbol, chainId)