nexus-sdk-swap-flows

Implement swapWithExactIn, swapWithExactOut, and swapAndExecute flows with Nexus SDK. Use when wiring swap operations, swap intent hooks, or swap event progress updates.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "nexus-sdk-swap-flows" with this command: npx skills add availproject/nexus-sdk/availproject-nexus-sdk-nexus-sdk-swap-flows

Swap Flows

Call swapWithExactIn(input, options?)

  • Use when input amount is fixed and sources are known.
  • Signature:
    • sdk.swapWithExactIn(input, { onEvent? })
  • Params (ExactInSwapInput):
    • from: { chainId: number; amount: bigint; tokenAddress: Hex }[]
    • toChainId: number
    • toTokenAddress: Hex
  • Notes:
    • Ensure from amounts are in smallest units.
    • Use chain-specific token addresses (see TOKEN_CONTRACT_ADDRESSES).
  • Result (SwapResult):
    • { success: true; result: SuccessfulSwapResult }

Call swapWithExactOut(input, options?)

  • Use when desired output amount is fixed.
  • Signature:
    • sdk.swapWithExactOut(input, { onEvent? })
  • Params (ExactOutSwapInput):
    • toChainId: number
    • toTokenAddress: Hex
    • toAmount: bigint
    • toNativeAmount?: bigint (optional native token output)
    • fromSources?: { chainId: number; tokenAddress: Hex }[] (optional)
  • Notes:
    • If fromSources is omitted, SDK auto-selects sources.

Call swapAndExecute(input, options?)

  • Use to perform swap (if needed) and then execute a contract call.
  • Signature:
    • sdk.swapAndExecute(input, { onEvent? })
  • Params (SwapAndExecuteParams):
    • toChainId: number
    • toTokenAddress: Hex
    • toAmount: bigint
    • fromSources?: { chainId: number; tokenAddress: Hex }[]
    • execute: SwapExecuteParams
  • SwapExecuteParams:
    • to: Hex
    • data?: Hex
    • value?: bigint
    • gas: bigint
    • gasPrice?: 'low' | 'medium' | 'high'
    • tokenApproval?: { token: Hex; amount: bigint; spender: Hex }
  • Result (SwapAndExecuteResult):
    • swapResult: SuccessfulSwapResult | null (null if swap skipped)

Use token addresses and chains

  • Use SDK constants for addresses and chain IDs:
    • SUPPORTED_CHAINS
    • TOKEN_CONTRACT_ADDRESSES

Attach swap intent hook

  • Set sdk.setOnSwapIntentHook(...) and call allow() to proceed.
  • 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 sdk.utils.parseUnits(value, decimals) or
  • sdk.convertTokenReadableAmountToBigInt(value, tokenSymbol, chainId) when decimals vary by chain.

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

nexus-sdk-integration

No summary provided by upstream source.

Repository SourceNeeds Review
General

nexus-sdk-hooks-events

No summary provided by upstream source.

Repository SourceNeeds Review
General

nexus-sdk-setup

No summary provided by upstream source.

Repository SourceNeeds Review
General

nexus-sdk-balances-metadata-utils

No summary provided by upstream source.

Repository SourceNeeds Review