1

I am sending ether to another smart contract and calling its fallback function with higher gas as like:

contractAddress.call.value(1 ether).gas(53000)();

It was working in solidity version 0.4.25 but it stopped working in 0.5.0 giving me error:

TypeError: Wrong argument count for function call: 0 arguments given but expected 1. This function requires a single bytes argument. Use "" as argument to provide empty calldata.

If I try to add blank argument in call() as it says in the error, then it gives me another error:

TypeError: Member "value" not found or not visible after argument-dependent lookup in tuple(bool,bytes memory) - did you forget the "payable" modifier?

I studied the breaking change documentation but that still could not find the solution. Any help would be appreciated :)

3

Make sure contractAddress is of type address payable. And yes, you'll need to provide an argument. E.g.:

address payable contractAddress = ...;
contractAddress.call.value(1 ether).gas(53000)("");
  • This worked. Thanks again sir.. The mistake I was making was, that I was doing: contractAddress.call("").value(1 ether).gas(53000)(); means adding ("") after call which is incorrect. And as you suggested, I did: contractAddress.call.value(1 ether).gas(53000)(""); and that worked! – Yogesh - EtherAuthority.io Dec 1 '18 at 4:14
  • @smarx I am facing the same issue with the following code : require(msg.sender.call.value(rewardAmount).gas(36000)(""));. How would you specify the type of msg.sender ? Many thanks. – Stanislasdrg Reinstate Monica Dec 22 '18 at 17:26
0

Whoever comes here and sees the accepted answer should know that the approach by itself contains potential errors for the contract logic and provides a gateway for attackers.

Whenever you use call you should check the return value of the function called. It will return false if it reverts.

(bool success ,) = cA.call.value(1 ether).gas(xx)("");

Furthermore It's suggested to only do this with trusted addresses. Any contract can easily implement logic to do reentry attacks. If you want to do it with non-trusted addresses, add a mutex flag to any of your other functions.

Something like this:

contract XX {
    bool mutexFlag;

    function untrustedCall(address payable _untrusted) public {
        require(mutexFlag == false, "No reentry!");
        // do stuff
        mutexFlag = true; // set mutex
        (bool success, ) = _untrusted.call.value(xxx)(""); // transfer funds without breaking things
        mutexFlag = false;
        require(success, "Transfer failed!");

        // do some more stuff
    }
}

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.