Router02
Because routers are stateless and do not hold token balances, they can be replaced safely and trustlessly, if necessary. This may happen if more efficient smart contract patterns are discovered, or if additional functionality is desired. For this reason, routers have release numbers, starting at 01. This is currently recommended release, 02.
Code
Address
UniswapV2Router02 is deployed at 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D on the Ethereum mainnet, and the Ropsten, Rinkeby, Görli, and Kovan testnets. It was built from commit 6961711.
Read-Only Functions
factory
function factory() external pure returns (address);
Returns factory address.
WETH
function WETH() external pure returns (address);
Returns the canonical WETH address on the Ethereum mainnet, or the Ropsten, Rinkeby, Görli, or Kovan testnets.
quote
See quote.
getAmountOut
See getAmountOut.
getAmountIn
See getAmountIn.
getAmountsOut
function getAmountsOut(uint amountIn, address[] memory path) public view returns (uint[] memory amounts);
See getAmountsOut.
getAmountsIn
function getAmountsIn(uint amountOut, address[] memory path) public view returns (uint[] memory amounts);
See getAmountsIn.
State-Changing Functions
addLiquidity
function addLiquidity(
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
Adds liquidity to an ERC-20⇄ERC-20 pool.
- To cover all possible scenarios,
msg.sendershould 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.
| Name | Type | |
|---|---|---|
| tokenA | address | A pool token. |
| tokenB | address | A pool token. |
| amountADesired | uint | The amount of tokenA to add as liquidity if the B/A price is <= amountBDesired/amountADesired (A depreciates). |
| amountBDesired | uint | The amount of tokenB to add as liquidity if the A/B price is <= amountADesired/amountBDesired (B depreciates). |
| amountAMin | uint | Bounds the extent to which the B/A price can go up before the transaction reverts. Must be <= amountADesired. |
| amountBMin | uint | Bounds the extent to which the A/B price can go up before the transaction reverts. Must be <= amountBDesired. |
| to | address | Recipient of the liquidity tokens. |
| deadline | uint | Unix timestamp after which the transaction will revert. |
| amountA | uint | The amount of tokenA sent to the pool. |
| amountB | uint | The amount of tokenB sent to the pool. |
| liquidity | uint | The amount of liquidity tokens minted. |