1

Why I am getting the error in the modifier function its showing red underline under the _amount variable name.

I also want to ask about whether the require function works inside the modifier because when I wrote my statement "require(_checkOwner() || allowance[msg.sender] >_amount,"You are not allowed!");" inside the modifier it showed me error. So now I am trying with defining the above require statement inside a function and then calling it in modifier. Is this the correct way?? Also please answer about why I am getting error for _amount in the statement which is being called inside modifier function "requiredCondition(uint _amount);".

pragma solidity ^0.8.16;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol";

contract SharedWallet is Ownable{

    mapping(address => uint) public allowance;

    fallback () external payable{
        
    }
    
    receive () external payable {

    }

    modifier ownerOrAllowed(uint _amount) {
        requiredCondition(uint _amount);
        _;
    }

    function requiredCondition(uint _amount) public {
        require(_checkOwner() || allowance[msg.sender] >_amount,"You are not allowed!");
    }

    function addAllowance(address _who, uint _amount) public onlyOwner{
        allowance[_who] = _amount;
    }

    function withdrawMoney(address payable _to, uint _amount) public ownerOrAllowed(_amount){
        _to.transfer(_amount);
    }
}

2 Answers 2

1

you are (re)declaring a variable name that has already been used/declared as a parameter. take out the second uint

modifier ownerOrAllowed(uint _amount) {
    requiredCondition(_amount);
    _;
}

also, _checkOwner() doesn't return bool. you can't use it like this. it just reverts if msg.sender isn't owner

2
  • Oh thank you but still it didn't reolve my error actually now it says that from solidity: TypeError: Operator || not compatible with types tuple() and bool. --> Project/SharedWallet.sol:23:17: | 23 | require(_checkOwner() || allowance[msg.sender] >_amount,"You are not allowed!"); | Commented Sep 10, 2022 at 16:17
  • _checkOwner() doesn't return bool. you can't use it like this. it just reverts if msg.sender isn't owner
    – sola24
    Commented Sep 10, 2022 at 16:19
1

You are getting the error in the modifier function its showing red underline under the _amount variable name because you wrote the data type "uint" before "_amount". In addition, you are getting an error in your statement "require(_checkOwner() || allowance[msg.sender] >_amount,"You are not allowed!");" because the operator || is not compatible with types tuple() and bool.

1
  • So how should I correct this?? Commented Sep 10, 2022 at 16:18

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.