Solidity Errors – Fixing Syntax Error: Type Tuple(bool,bytes Memory) Not Convertible to Expected Type bool

contract-designcontract-developmenterrorsoliditytransactions

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.

Best Answer

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).

Related Topic