1

I am getting following error message with require statement:

Error: 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.

        require(msg.sender.call.value(address(this).balance)());
                ^--------------------------------------------^ : 

Error: No matching declaration found after argument-dependent lookup.

        require(msg.sender.call.value(address(this).balance)());
        ^-----^

The require statement is:

require(msg.sender.call.value(address(this).balance)());

Somebody please guide me.

Zulfi.

2 Answers 2

3

Your problem is not in the require statement, but in the addr1.call.value(addr2)() function call inside it.

In solc 0.4.x, this function would take no input arguments and return one output value of type bool, so your code would actually compile successfully.

In solc 0.5.x, this function takes one input argument of type bytes and returns one output value of type bool and one output value of type bytes.

In short, just change this:

require(msg.sender.call.value(address(this).balance)());

To this:

(bool success,) = msg.sender.call.value(address(this).balance)("");
require(success);

Or to this if you want to do something with the second output value:

(bool success, bytes memory returnData) = msg.sender.call.value(address(this).balance)("");
require(success);
... // do something with `returnData`
1

The require function should be used to ensure valid conditions that cannot be detected until execution time as specified in the solidity read the docs.

In your case:

require(msg.sender.call.value(address(this).balance)());

It returns two values one is of type bool and the other of type bytes, whereas require expects a Boolean (single parameter) value for execution. Thus, you are getting the above error.

Correct syntax for require:

require("Anything that returns a boolean (Be it an expression/a function call/external call etc)")

Example:
require(msg.value % 2 == 0, "Even value required.");
2
  • @balajipachi, sorry your explanation is not clear. On the other hand the answer above your's clearly bifurcates require into two parts. Sorry I can't understand what you mean by "It" in your sentence " It returns two values one is of type bool .....".
    – zak100
    Commented Mar 21, 2020 at 1:58
  • You can find more details about require here: solidity.readthedocs.io/en/v0.6.4/… Commented Mar 21, 2020 at 6:35

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.