Router01
UniswapV2Router01 should not be used any longer, because of the discovery of a low severity bug and the fact that some methods do not work with tokens that take fees on transfer. The current recommendation is to use UniswapV2Router02.
Code
Address
UniswapV2Router01
is deployed at 0xf164fC0Ec4E93095b804a4795bBe1e041497b92a
on the Ethereum mainnet, and the Ropsten, Rinkeby, GΓΆrli, and Kovan testnets. It was built from commit 2ad7da2.
Read-Only Functions
factory
Returns factory address.
WETH
Returns the canonical WETH address on the Ethereum mainnet, or the Ropsten, Rinkeby, GΓΆrli, or Kovan testnets.
State-Changing Functions
addLiquidity
Adds liquidity to an ERC-20βERC-20 pool.
To cover all possible scenarios,
msg.sender
should have already given the router an allowance of at least amountADesired/amountBDesired on tokenA/tokenB.Always adds assets at the ideal ratio, according to the price when the transaction is executed.
If a pool for the passed tokens does not exists, one is created automatically, and exactly amountADesired/amountBDesired tokens are added.
addLiquidityETH
Adds liquidity to an ERC-20βWETH pool with ETH.
To cover all possible scenarios,
msg.sender
should have already given the router an allowance of at least amountTokenDesired on token.Always adds assets at the ideal ratio, according to the price when the transaction is executed.
msg.value
is treated as a amountETHDesired.Leftover ETH, if any, is returned to
msg.sender
.If a pool for the passed token and WETH does not exists, one is created automatically, and exactly amountTokenDesired/
msg.value
tokens are added.
removeLiquidity
Removes liquidity from an ERC-20βERC-20 pool.
msg.sender
should have already given the router an allowance of at least liquidity on the pool.
removeLiquidityETH
Removes liquidity from an ERC-20βWETH pool and receive ETH.
msg.sender
should have already given the router an allowance of at least liquidity on the pool.
removeLiquidityWithPermit
Removes liquidity from an ERC-20βERC-20 pool without pre-approval, thanks to permit.
removeLiquidityETHWithPermit
Removes liquidity from an ERC-20βWETTH pool and receive ETH without pre-approval, thanks to permit.
swapExactTokensForTokens
Swaps an exact amount of input tokens for as many output tokens as possible, along the route determined by the path. The first element of path is the input token, the last is the output token, and any intermediate elements represent intermediate pairs to trade through (if, for example, a direct pair does not exist).
msg.sender
should have already given the router an allowance of at least amountIn on the input token.
swapTokensForExactTokens
Receive an exact amount of output tokens for as few input tokens as possible, along the route determined by the path. The first element of path is the input token, the last is the output token, and any intermediate elements represent intermediate pairs to trade through (if, for example, a direct pair does not exist).
msg.sender
should have already given the router an allowance of at least amountInMax on the input token.
swapExactETHForTokens
Swaps an exact amount of ETH for as many output tokens as possible, along the route determined by the path. The first element of path must be WETH, the last is the output token, and any intermediate elements represent intermediate pairs to trade through (if, for example, a direct pair does not exist).
swapTokensForExactETH
Receive an exact amount of ETH for as few input tokens as possible, along the route determined by the path. The first element of path is the input token, the last must be WETH, and any intermediate elements represent intermediate pairs to trade through (if, for example, a direct pair does not exist).
msg.sender
should have already given the router an allowance of at least amountInMax on the input token.If the to address is a smart contract, it must have the ability to receive ETH.
swapExactTokensForETH
Swaps an exact amount of tokens for as much ETH as possible, along the route determined by the path. The first element of path is the input token, the last must be WETH, and any intermediate elements represent intermediate pairs to trade through (if, for example, a direct pair does not exist).
If the to address is a smart contract, it must have the ability to receive ETH.
swapETHForExactTokens
Receive an exact amount of tokens for as little ETH as possible, along the route determined by the path. The first element of path must be WETH, the last is the output token and any intermediate elements represent intermediate pairs to trade through (if, for example, a direct pair does not exist).
Leftover ETH, if any, is returned to
msg.sender
.
quote
See quote.
getAmountOut
See getAmountOut.
getAmountIn
This function contains a low severity bug, do not use.
getAmountsOut
See getAmountsOut.
getAmountsIn
See getAmountsIn.
Interface
ABI
https://unpkg.com/@uniswap/v2-periphery@1.0.0-beta.0/build/IUniswapV2Router01.json