Got the error Address call to non-contract

I'm trying to execute a swap with ETH and interacting with a function that call the swap function but I get error when I tried to send ETH to the contract,

E            */
E           function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
E               require(address(this).balance >= value, "Address: insufficient balance for call");
E               require(isContract(target), "Address: call to non-contract");
E       
E               // solhint-disable-next-line avoid-low-level-calls
E               (bool success, bytes memory returndata) = target.call{ value: value }(data);

Check that the function calling this functionCallWithValue has the payable modifier.

1 Like

Hi, welcome! :wave:

If possible, you can share your contract code at here!

    function zapIn(
        address _fromToken,
        address _toToken,
        address _curvePool,
        uint256 _amount,
        uint256 _minPoolAmount,
        address _swapTarget,
        address _vault,
        bytes calldata _swapData
    ) external payable returns (uint256 yearnLp) {

        if(_fromToken == address(0)) {
            _fromToken = ETHAddress;
        } else {
            require(_amount > 0, "amount can't be empty");
            require(approvedTokens[_fromToken] = true, "token doesn't allow");
            IERC20(_fromToken).safeTransferFrom(msg.sender, address(this), _amount);
        }

        // perform the curve process, add liquidity
        uint256 crvTokensBought = _performCurveZapIn(_fromToken, _toToken, _curvePool, _amount, _swapTarget, _swapData);
        

        require(crvTokensBought >= _minPoolAmount, "received less than expected");
        

        address curveTokenAddress = curveReg.getTokenAddress(_curvePool);

        uint256 iniBalance = IERC20(_vault).balanceOf(address(this));
        // approve vault deposit
        IERC20(curveTokenAddress).approve(address(vaultsavings), crvTokensBought);
        // deposit to yearn vault
        vaultsavings.deposit(_vault, crvTokensBought);

        // remove approval
        IERC20(curveTokenAddress).approve(address(vaultsavings), 0);

        yearnLp = IERC20(_vault).balanceOf(address(this)).sub(iniBalance);

        // transfer lp yearn to msg.sender
        require(yearnLp > 0, "zap failed");

        IERC20(_vault).transfer(msg.sender, yearnLp);

        emit ZapIn(msg.sender, _vault, yearnLp);
    }

This is the function I used to swap , note that it works with all ERC20 tokens, but when I try to use ETH, I have this error , and I'm using brownie for test

1 Like

Help me check the following:

  1. You're not forgetting to send the ether.
  2. In some contracts, they treat ETH as WETH so if WETH is used, make sure you've given allowance for WETH as well.

Can you also share which require statement is throwing?