What is the main purpose / family of use-cases for the existence of internal functions in solidity?

1 Answer 1


Internal Functions cannot be called by other external smart contract or wallet directly. But internal or public function within smart contract and call internal function.

Internal functions are used Mostly in below way.

We write a public function, which do some security checks.

After sucessful security checks the public function calls internal function.

For example:

Here in ERC20.sol transfer() (public) function do a security check of address owner = _msgSender(); (if sender is owner of tokens)

and then calls _transfer() internal function which transfers the token.

You could have done this in once public function. But this is how every code is written in standard format. As _transfer() is used many times i.e. in transferFrom() public function also calls _transfer() internal function.

  • I am wondering if what you have written isn't just about use case in which private function modifier could have been used. But as I have read 'internal' allows for usage in sub-contracts. So it seems that in example you have provided we anticipate that we will have some contracts inheriting from ERC20.sol that can use this internal function while it wouldn't be possible with private function.
    – bridgemnc
    Aug 11, 2022 at 19:37
  • Yes. Also quick tip dont use modifier instead use internal functions, this takes less gas fee. Aug 12, 2022 at 4:04

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.