0

I deployed smart contract to testnet and i got error can someone help me debug this

Code:

pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "@openzeppelin/contracts/utils/Context.sol";
import "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol";

interface IERC3156FlashBorrower {
    function onFlashLoan(
        address initiator,
        address token,
        uint256 amount,
        uint256 fee,
        bytes calldata data
    ) external returns (bytes32);
}

contract FlashBorrower2 is Context, ReentrancyGuard, IERC3156FlashBorrower {
    using SafeERC20 for IERC20;

    address private owner;
    uint256 public constant MAX_INT = type(uint256).max;
    address USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;

    constructor() {
        owner = msg.sender;
    }

    modifier OnlyOwner() {
        require(msg.sender == owner);
        _;
    }

    function onFlashLoan(
        address initiator,
        address token,
        uint256 amount,
        uint256 fee,
        bytes calldata data
    ) external override nonReentrant returns (bytes32) {
        IERC20(token).approve(msg.sender, MAX_INT);
        uint256 amountOutExpected;
        uint256 amountOutExpected2;
        (amountOutExpected, amountOutExpected2) = abi.decode(
            data,
            (uint256, uint256)
        );
        address UNISWAP_ROUTER_ADDRESS = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
        address SUSHISWAP_ROUTER_ADDRESS = 0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F;

        IUniswapV2Router02 uniswapRouter = IUniswapV2Router02(
            UNISWAP_ROUTER_ADDRESS
        );
        IUniswapV2Router02 sushiSwapRouter = IUniswapV2Router02(
            SUSHISWAP_ROUTER_ADDRESS
        );

        address[] memory path = new address[](2);
        path[0] = token;
        path[1] = USDC;

        uniswapRouter.swapExactTokensForTokens(
            amount,
            amountOutExpected,
            path,
            address(this),
            block.timestamp
        );

        address[] memory path2 = new address[](2);
        path2[0] = USDC;
        path2[1] = token;

        sushiSwapRouter.swapExactTokensForTokens(
            IERC20(USDC).balanceOf(address(this)),
            amountOutExpected2,
            path2,
            address(this),
            block.timestamp
        );

        return keccak256("ERC3156FlashBorrower.onFlashLoan");
    }

    function withdrawWETH(address WETH) external OnlyOwner {
        require(
            IERC20(WETH).balanceOf(address(this)) > 0,
            "No funds to withdraw"
        );
        IERC20(WETH).transfer(owner, IERC20(WETH).balanceOf(address(this)));
    }
}

ERROR:

Error: transaction failed [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (transactionHash="0x05b56cf7dde5495ec7ff5ed13bf1a64f45481e19c20fd948b69f56a0669e9a7d", transaction={"type":2,"chainId":11155111,"nonce":21,"maxPriorityFeePerGas":{"type":"BigNumber","hex":"0x010aaeb4f1"},"maxFeePerGas":{"type":"BigNumber","hex":"0x010aaeb4f1"},"gasPrice":null,"gasLimit":{"type":"BigNumber","hex":"0x017d7840"},"to":"0xD6011CC83d2Be6db63105574e230D8314307518e","value":{"type":"BigNumber","hex":"0x00"},"data":"0x23e30c8b000000000000000000000000d6011cc83d2be6db63105574e230d8314307518e000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000001b1ae4d6e2ef500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","accessList":[],"hash":"0x05b56cf7dde5495ec7ff5ed13bf1a64f45481e19c20fd948b69f56a0669e9a7d","v":0,"r":"0x820c7007b97f38ff6bae728d1a10e73f952520545193d186acd53bc6c4690502","s":"0x57dd20396db78e0ef5ea6711610a40fd7517f0203403483f1df94cae7835139d","from":"0x52E48123Dd1d3A2DbFcf60670D5d4d192Fd0bd78","confirmations":0}, receipt={"to":"0xD6011CC83d2Be6db63105574e230D8314307518e","from":"0x52E48123Dd1d3A2DbFcf60670D5d4d192Fd0bd78","contractAddress":null,"transactionIndex":8,"gasUsed":{"type":"BigNumber","hex":"0x7d7d"},"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","blockHash":"0x45e6ea1c2bac4b5ce14fb7d44b41ed4efccb2cf829da5a673962e4b8c5f5be4d","transactionHash":"0x05b56cf7dde5495ec7ff5ed13bf1a64f45481e19c20fd948b69f56a0669e9a7d","logs":[],"blockNumber":4874132,"confirmations":1,"cumulativeGasUsed":{"type":"BigNumber","hex":"0x03885f"},"effectiveGasPrice":{"type":"BigNumber","hex":"0x010aaeb4f1"},"status":0,"type":2,"byzantium":true}, code=CALL_EXCEPTION, version=providers/5.7.2)
    at Logger.makeError (E:\TESTNETSANDWITCH\node_modules\@ethersproject\logger\src.ts\index.ts:269:28)
    at Logger.throwError (E:\TESTNETSANDWITCH\node_modules\@ethersproject\logger\src.ts\index.ts:281:20)
    at JsonRpcProvider.<anonymous> (E:\TESTNETSANDWITCH\node_modules\@ethersproject\providers\src.ts\base-provider.ts:1549:24)
    at step (E:\TESTNETSANDWITCH\node_modules\@ethersproject\providers\lib\base-provider.js:48:23)
    at Object.next (E:\TESTNETSANDWITCH\node_modules\@ethersproject\providers\lib\base-provider.js:29:53)
    at fulfilled (E:\TESTNETSANDWITCH\node_modules\@ethersproject\providers\lib\base-provider.js:20:58) {
  reason: 'transaction failed',
  code: 'CALL_EXCEPTION',
  transactionHash: '0x05b56cf7dde5495ec7ff5ed13bf1a64f45481e19c20fd948b69f56a0669e9a7d',
  transaction: {
    type: 2,
    chainId: 11155111,
    nonce: 21,
    maxPriorityFeePerGas: BigNumber { _hex: '0x010aaeb4f1', _isBigNumber: true },
    maxFeePerGas: BigNumber { _hex: '0x010aaeb4f1', _isBigNumber: true },
    gasPrice: null,
    gasLimit: BigNumber { _hex: '0x017d7840', _isBigNumber: true },
    to: '0xD6011CC83d2Be6db63105574e230D8314307518e',
    value: BigNumber { _hex: '0x00', _isBigNumber: true },
    data: '0x23e30c8b000000000000000000000000d6011cc83d2be6db63105574e230d8314307518e000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000001b1ae4d6e2ef500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
    accessList: [],
    hash: '0x05b56cf7dde5495ec7ff5ed13bf1a64f45481e19c20fd948b69f56a0669e9a7d',
    v: 0,
    r: '0x820c7007b97f38ff6bae728d1a10e73f952520545193d186acd53bc6c4690502',
    s: '0x57dd20396db78e0ef5ea6711610a40fd7517f0203403483f1df94cae7835139d',
    from: '0x52E48123Dd1d3A2DbFcf60670D5d4d192Fd0bd78',
    confirmations: 0,
    wait: [Function (anonymous)]
  },
  receipt: {
    to: '0xD6011CC83d2Be6db63105574e230D8314307518e',
    from: '0x52E48123Dd1d3A2DbFcf60670D5d4d192Fd0bd78',
    contractAddress: null,
    transactionIndex: 8,
    gasUsed: BigNumber { _hex: '0x7d7d', _isBigNumber: true },
    logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
    blockHash: '0x45e6ea1c2bac4b5ce14fb7d44b41ed4efccb2cf829da5a673962e4b8c5f5be4d',
    transactionHash: '0x05b56cf7dde5495ec7ff5ed13bf1a64f45481e19c20fd948b69f56a0669e9a7d',
    logs: [],
    blockNumber: 4874132,
    confirmations: 1,
    cumulativeGasUsed: BigNumber { _hex: '0x03885f', _isBigNumber: true },
    effectiveGasPrice: BigNumber { _hex: '0x010aaeb4f1', _isBigNumber: true },
    status: 0,
    type: 2,
    byzantium: true
  }
}
3
  • What testnet did you attempt to deploy to? The addresses in your contract all refer to ETH Mainnet network contracts.
    – red-swan
    Commented Dec 17, 2023 at 7:07
  • Looking at the doc for the error message, this transaction reverted. If we knew the network, we could look at the transaction hash on the network block explorer to really see what happened.
    – red-swan
    Commented Dec 17, 2023 at 7:12
  • I used sepolia testnet
    – Xardesso
    Commented Dec 18, 2023 at 9:20

1 Answer 1

0

Looking at the transaction hash on Sepolia, it looks like you called onFlashLoan on your contract with the following parameters:

| # | Name      | Type    | Data                                       |
|---|-----------|---------|--------------------------------------------|
| 0 | initiator | address | 0xD6011CC83d2Be6db63105574e230D8314307518e |
| 1 | asset     | address | 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 |
| 2 | amount    | uint256 | 500000000000000000000                      |
| 3 | fee       | uint256 | 0                                          |
| 4 | data      | bytes   | 0x                                         |

In your code, you call approve on the asset (token) parameter. However, looking at the specified asset address, we see it's an EOA. No code, and no approve method exists. I think you simply put your arguments in incorrectly.

1
  • this aprove is part of the equalizer finance flashloan but i think the error may cause uniswap v2 address which is set to mainnet and i testing this on spepolia testnet but its mu thoughts
    – Xardesso
    Commented Dec 18, 2023 at 21:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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