[Ethereum] No matching declaration found after argument-dependent lookup in remix IDE

contract-debuggingremixsolidity

I'm getting this error in remix:

"TypeError: No matching declaration found after argument-dependent lookup. require(_spender.call.value(msg.value)(_data));
^-----^ "

function approveAndCall(address payable _spender, uint256 _value, bytes memory _data) public payable returns (bool) {    
  require(_spender != address(this));   
  this.approve(_spender, _value);    
  require(_spender.call.value(msg.value)(_data));    
  return true;   
}

Please I need help on how to resolve this. Thanks

Best Answer

When you use the call function, you can control the returned success condition as a bool and check if the call succeed or not.

function approveAndCall(address payable _spender, uint256 _value, bytes memory _data) public payable returns (bool) {    
    require(_spender != address(this));   
    this.approve(_spender, _value);    
    (bool success, ) = _spender.call.value(msg.value)(_data);
    require(success);
    return true;   
}

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