1

After 5 days of tests and research I couldn't find the solution.

Develop a simple Contract in Remix.

I manage to do the Deploy in Polygon via Metamask, OK. (TH: 0xedbe038a94c26636dbe275821655e302394df424c19438dcaebbdf5eb6f2cf09)

When I try to carry out in Remix the execution of the only function that the Contract has, it returns the following Error:

Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? Internal JSON-RPC error.

If I force it, it takes me to Metamask, where when confirming the transaction it mines, but with an error: Warning! Error encountered during contract execution [execution reverted]

(TH: 0x2f3fa2036c846a2cdc4b02c8763cd4f81abf56892a66bb3200af240dab888062)

What can be the reason?

Code Smart Contract:

**// SPDX-License-Identifier: MIT
pragma solidity 0.8.0;
import '@openzeppelin/contracts/token/ERC20/ERC20.sol';
contract Router {
 
  function swapExactTokensForTokens(
    uint amountIn,
    uint amountOutMin,
    address[] calldata path,
    address to,
    uint deadline
  ) external returns (uint[] memory amounts)  {}
}
contract Swapper
{
  Router router = Router(0xa5E0829CaCEd8fFDD4De3c43696c57F7D7A678ff);
  
  ERC20 USDC_token = ERC20(0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174);
  ERC20 DAI_token  = ERC20(0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063);
  
  ERC20 WETH_token = ERC20(0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619);
  
  ERC20 MATIC_token = ERC20(0x0000000000000000000000000000000000001010);
function swapMATICToUSDC(uint amount) public
  {
    MATIC_token.transferFrom(
     msg.sender,
     address(this),
     amount
    );
    address[] memory path = new address[](2);
    path[0] = address(MATIC_token);
    path[1] = address(USDC_token);

    MATIC_token.approve(address(router), amount);

    router.swapExactTokensForTokens(
      amount,
      0,
      path,
      msg.sender,
      block.timestamp
    );
  }
}**

Thanks.

Julio Sarda
  • 29
  • 1
  • 3

2 Answers2

0

you might want to try to use an interface instead of a Contract. Especially since your contract doesn't do anything at the current state.

BalGu
  • 53
  • 1
  • 7
0

maybe the network that you're trying to deploy on, is not at the same network as your addresses is:

0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174 0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063 0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619