Skip to content

V2SwapRouter

Solidity API

swapExactTokensForTokens

function swapExactTokensForTokens(uint256 amountIn, uint256 amountOutMin, address[] path, address to) external payable returns (uint256 amountOut)

Swaps amountIn of one token for as much as possible of another token

Setting amountIn to 0 will cause the contract to look up its own balance, and swap the entire amount, enabling contracts to send tokens before calling this function.

Parameters
NameTypeDescription
amountInuint256The amount of token to swap
amountOutMinuint256The minimum amount of output that must be received
pathaddress[]The ordered list of tokens to swap through
toaddressThe recipient address
Return Values
NameTypeDescription
amountOutuint256The amount of the received token

swapTokensForExactTokens

function swapTokensForExactTokens(uint256 amountOut, uint256 amountInMax, address[] path, address to) external payable returns (uint256 amountIn)

Swaps as little as possible of one token for an exact amount of another token

Parameters
NameTypeDescription
amountOutuint256The amount of token to swap for
amountInMaxuint256The maximum amount of input that the caller will pay
pathaddress[]The ordered list of tokens to swap through
toaddressThe recipient address
Return Values
NameTypeDescription
amountInuint256The amount of token to pay