0

I have this errore:

TypeError: No matching declaration found after argument-dependent lookup.
--> Spaghetti Finance Rewards.sol:54:9:
|
54 | require(msg.sender.call{value: _value}("Transaction failed, check the fallback function, if it's payable or not."));
| ^^^^^^^
Note: Candidate: function require(bool)
Note: Candidate: function require(bool, string memory)

For this function:

function deposit(address _token, uint256 _value) public {
    require(whitelisted[_token], "Token not whitelisted.");
    require(_value > 0, "Deposit value must be greater than 0.");
    require(msg.sender.call{value: _value}("Transaction failed, check the fallback function, if it's payable or not."));
    userTransactions[msg.sender][_token] = true;
    userTransactionTimestamps[msg.sender][_token] = block.timestamp;
    tokenBalances[msg.sender] += _value;
    userLockedTokens[msg.sender][_token] += _value;
    emit Deposit(msg.sender, _token, _value);
}

Any help is appreciated. Thanks

2 Answers 2

1

The problem is require(msg.sender.call{value: _value}("Transaction failed, check the fallback function, if it's payable or not.")); is not a valid syntax anymore since solidity 0.5.0: the low level call will return (bool, bytes memory) instead of just (bool). Basically, the fix is to use the correct return values of msg.sender.call. Delete line 54 above and replace with this:

    (bool sent, ) = msg.sender.call{value: _value}("");
    require(sent, "Transaction failed, check the fallback function, if it's payable or not.");
1
  • alternative fix (not recommended due to security issue of old compiler): use older compiler version (e.g. 0.4.20) by changing solidity version pragma: docs.soliditylang.org/en/develop/…
    – minhhn2910
    Commented Jan 14, 2023 at 10:45
0

The first argument passed to require must be convertible to a bool. This is not satisfied by the line that produces the error.

It is unclear what the code is intended to do, but if the intent is to allow the user to deposit a certain amount of a certain token, then the code has multiple serious issues beyond the specific error quoted in the question.

1
  • In old version of solidity .call() returned a boolean to indicate the success of the call.
    – Ismael
    Commented Jan 14, 2023 at 16:53

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.