23

Does the internal keyword in a function definition such as:

function doSomeThing(uint _param) internal {...}

work similar to designating a method as private in other languages and thus makes the function only callable from within the contract?

17

The internal modifier can be better compared with protected in object-oriented programming languages. Internal functions of the contract C are visible to the code running at the current address (i.e. the current contract instance) but also to contracts derived from C.

Note that due to the architecture of the EVM, visibility is something that can be strictly enforced at the machine level: There is no way to call a function at another address unless it is explicitly available (i.e. you cannot just "cast" the contract to another type). It is also impossible to call internal or private functions of the same contract type at a different address.

  • Well...there is no direct way to do those last things. But an elaborate deposit-challenge-verify mechanism could technically let you circumvent this restriction within another contract. After all, the function's publicly visible in the blockchain. – Jeff Coleman Jan 26 '16 at 8:30
  • 1
    Yes, there are mechanisms to execute another contract's function (with EXTCODECOPY you do not even need an external service), but not in the context of the other contract. – chriseth Jan 27 '16 at 17:20
17

Yes. The internal modifer means that the function can only be called within the contract itself and any derived contracts.

private functions are not available in derived contracts.

From the docs:

internal:

Those functions and state variables can only be accessed internally (i.e. from within the current contract or contracts deriving from it), without using this.

private:

Private functions and state variables are only visible for the contract they are defined in and not in derived contracts.

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.