0

I have the following setup of two internal and external functions. Is such a setup correct?

address public addr;

function addValue() external payable {
   _addValue(msg.value);
}

function _addValue(uint256 value) internal payable {
   addr.send(value);
}
1
  • answer updated......... – Majd TL May 7 at 12:52
1

No internal and private function can't be declared as payable

you will get a compiler error

TypeError: "internal" and "private" functions cannot be payable

The idea of having payable modifier is "to permission or prevent intentional and accidental value transfers" and using it twice first in external/public function and then again in internal function which is called by that function does not make sense :)

but you can use msg.value inside the internal function so something like this

    function addValue() external payable {
       _addValue();
    }
    
    function _addValue() internal {
       payable(addr).transfer(msg.value);
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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