2

I am trying to compile the following program:

pragma solidity ^0.5.1;

contract MKotET1_1{

    address payable king; uint public claimPrice = 100;

    function calculateCompensation() public returns(uint) {
    }

    function( ) external payable {
       if (msg.value  < claimPrice) revert();
           uint compensation = calculateCompensation();
           if(!king.call.value(compensation)("")) revert();
          king = msg.sender;
       }
    }

I am getting following syntax errors:

solc MKotET_stackExchange.sol MKotET_stackExchange.sol:12:14: Error: Unary operator ! cannot be applied to >type tuple(bool,bytes memory) if(!king.call.value(compensation)("")) revert(); ^--------------------------------^ MKotET_stackExchange.sol:12:14: Error: Type tuple(bool,bytes memory) is not implicitly convertible to expected type bool. if(!king.call.value(compensation)("")) revert(); ^--------------------------------^

Somebody please guide me how to remove the above syntax errors.

Zulfi.

1
  • Use require, revert() ist deprecated I think, that is not an answer
    – Majd TL
    Jun 22, 2019 at 19:07

2 Answers 2

3

Try with this:

pragma solidity ^0.5.1;

contract MKotET1_12{

    address payable king; uint public claimPrice = 100;

    function calculateCompensation() public returns(uint) {}

    function() external payable {
        if (msg.value  < claimPrice) revert();
            uint compensation = calculateCompensation();
            (bool success, ) = king.call.value(compensation)("");
            require(success);
            king = msg.sender;
        }
    }

From docs:

In order to interface with contracts that do not adhere to the ABI, or to get more direct control over the encoding, the functions call, delegatecall and staticcall are provided. They all take a single bytes memory parameter and return the success condition (as a bool) and the returned data (bytes memory).

2

You are getting a reversion because a call returns two values and you are treating it as one.

When performing king.call.value(compensation)(""), what you actually receive back is the success bool and the bytes response. As it stands, you are trying to check for the bool value, but ignoring the fact that it also returns a response. Your code should look as follows:

(bool success, bytes memory response) = king.call.value(compensation)("")
require(success);

Your Answer

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

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