SwapTokensForExactTokens

Uniswap Action Plugin - SwapTokensForExactTokens

Description

Swaps an exact amount of tokens for as much ETH as possible, along the route determined by the path.

Method

swapTokensForExactTokens(uint256, uint256, address[], address, uint256)

Input Parameters

NamePlugin TypeDescription

to

FctAddress

Uniswap V2 Router address

Method Parameters

NamePlugin TypeDescription

amountOut

FctValue

The amount of output tokens to receive.

amountInMax

FctValue

The maximum amount of input tokens that can be required before the transaction reverts.

path

FctAddressList

An array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.

to

FctAddress

Recipient of the output tokens.

deadline

FctValue

Unix timestamp after which the transaction will revert.

Example

Example with initParams

const swapTokensForExactTokens = new Uniswap.actions.SwapTokensForExactTokens({
 chainId: 1,
 initParams: {
   to: "0x..." // Uniswap V2 Router
   methodParams: {
     amountOut: "...",
     amountInMax: "...",
     path: ["0x...", "0x..."],
     to: "0x...",
     deadline: "..."
   }
 }
})

Example without initParams

const swapTokensForExactTokens = new Uniswap.actions.SwapTokensForExactTokens({ 
  chainId: 1
})

swapTokensForExactTokens.input.set({
   to: "0x..." // Uniswap V2 Router
   methodParams: {
     amountOut: "...",
     amountInMax: "...",
     path: ["0x...", "0x..."],
     to: "0x...",
     deadline: "..."
   }
})

Learn more

Learn more about Uniswap SwapTokensForExactTokens function here

Last updated