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, 2021 at 12:52

1 Answer 1

3

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);
    }
1
  • So we can still transfer/call{value} even we don't have payable modifier on the internal function?
    – b.ben
    Oct 25, 2021 at 7:21

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.