"uniswap liquidity provider demo dapp" Code Answer's

You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "uniswap liquidity provider demo dapp" answered properly. Developers are finding an appropriate answer about uniswap liquidity provider demo dapp related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like uniswap liquidity provider demo dapp. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on uniswap liquidity provider demo dapp. 

uniswap liquidity provider demo dapp

By Tired TigerTired Tiger on Nov 05, 2020
pragma solidity 0.7.1;

import "https://github.com/Uniswap/uniswap-v2-periphery/blob/master/contracts/interfaces/IUniswapV2Router02.sol";

contract UniswapExample {
  address internal constant UNISWAP_ROUTER_ADDRESS = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D ;

  IUniswapV2Router02 public uniswapRouter;
  address private multiDaiKovan = 0x4F96Fe3b7A6Cf9725f59d353F723c1bDb64CA6Aa;

  constructor() {
    uniswapRouter = IUniswapV2Router02(UNISWAP_ROUTER_ADDRESS);
  }

  function convertEthToDai(uint daiAmount) public payable {
    uint deadline = block.timestamp + 15; // using 'now' for convenience, for mainnet pass deadline from frontend!
    uniswapRouter.swapETHForExactTokens{ value: msg.value }(daiAmount, getPathForETHtoDAI(), address(this), deadline);
    
    // refund leftover ETH to user
    (bool success,) = msg.sender.call{ value: address(this).balance }("");
    require(success, "refund failed");
  }
  
  function getEstimatedETHforDAI(uint daiAmount) public view returns (uint[] memory) {
    return uniswapRouter.getAmountsIn(daiAmount, getPathForETHtoDAI());
  }

  function getPathForETHtoDAI() private view returns (address[] memory) {
    address[] memory path = new address[](2);
    path[0] = uniswapRouter.WETH();
    path[1] = multiDaiKovan;
    
    return path;
  }
  
  // important to receive ETH
  receive() payable external {}
}

Source: soliditydeveloper.com

Add Comment

0

All those coders who are working on the Whatever based application and are stuck on uniswap liquidity provider demo dapp can get a collection of related answers to their query. Programmers need to enter their query on uniswap liquidity provider demo dapp related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about uniswap liquidity provider demo dapp for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of uniswap liquidity provider demo dapp while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "uniswap liquidity provider demo dapp". Visit this developer's friendly online web community, CodeProZone, and get your queries like uniswap liquidity provider demo dapp resolved professionally and stay updated to the latest Whatever updates. 

Whatever answers related to "uniswap liquidity provider demo dapp"

View All Whatever queries

Whatever queries related to "uniswap liquidity provider demo dapp"

Browse Other Code Languages

CodeProZone