Skip to Content
Avail Nexus is now live! Check out our docs to get started.

swapWithExactOut()

SET UP THE SDK BEFORE YOU START:

  1. You can find the SDK setup instructions in the Quickstart page.
  2. We also created a tutorial to make it easier to understand how devs need to initialize the Nexus SDK in their project.

Use the swapWithExactOut() function to swap tokens with an exactly defined output amount. For example, if you want to get exactly 1 ETH on the destination but don’t care which funds are used to source the swap.

Method signature

Typescript
async swapWithExactOut( input: ExactOutSwapInput, options?: OnEventParam, ): Promise<SwapResult>

Parameters

Typescript
export interface ExactOutSwapInput { toChainId: number; toTokenAddress: Hex; toAmount: bigint; }
  • ExactOutSwapInput: Parameters for using the swapWithExactOut() function.

    • toChainId (number, required): The chain ID of the destination chain.
    • toTokenAddress (Hex, required): The address of the token to be swapped to.
    • toAmount (bigint, required): The amount of tokens to be swapped to.
  • options: Optional parameters for the event listener.

Example

Typescript
Last updated on