0

Here is my code

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

contract Test_Swap{

  address owner = msg.sender;     
  
  IUniswapV2Router02 uniswap = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
  
  address private token_address = 0x514910771AF9Ca656af840dff83E8264EcF986CA; //chainlink
  address private usdc = 0x0D9C8723B343A8368BebE0B5E89273fF8D712e3C;
  
  function getPathForETHtoToken() private view returns (address[] memory) {
     address[] memory path = new address[](2);
     path[0] = uniswap.WETH();
     path[1] = usdc;
   return path;
   }
   
  function swapContractEthToLink() external payable {  
  uniswap.swapExactETHForTokens{value: msg.value}(0,getPathForETHtoToken(), owner, block.timestamp + 15);  
  }
}

I'm trying to trade for my ethers for usdc, but I'm getting an error

I'm using a remix, deploying my contract on kovan

I apologize for my english (google translator) and maybe a stupid question, I'm a beginner, I will be grateful for your help

0

It doesn't work on Kovan because your USDC Token address is invalid on Kovan, you can see that the address 0x0D9C8723B343A8368BebE0B5E89273fF8D712e3C is an empty address on Kovan

https://kovan.etherscan.io/address/0x0D9C8723B343A8368BebE0B5E89273fF8D712e3C

while on Ropsten it is the valid USDC Token

https://ropsten.etherscan.io/address/0x0D9C8723B343A8368BebE0B5E89273fF8D712e3C

I guess the USDC team just didn't deploy their token on Kovan, so of course when you try to swap WETH to USDC on Kovan it is reverted.

1
  • I tried other tokens, apparently for the same reason it didn't work, thanks. – dustiwe May 8 at 15:44
0

It was necessary to change the test network to ropsten, it is strange because the same contracts are displayed and work in the test network kovan

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.