Solidity – How to Use Delegatecall to an Internal Function

delegatecallevmsolidity

Let's say I have a Dispatcher contract that delegates all function calls to an Implementation contract using delegatecall (see for example https://gist.github.com/Arachnid/4ca9da48d51e23e5cfe0f0e14dd6318f).

To initialise the Dispatcher with some value uint value1 I want to (delegate)call, from the constructor of Dispatcher, an init() method of the Implementation and pass it value1. For security reasons I would like to mark the init() method of Implementation as internal… but it does not seem to work.

I know I can make the init() method of Implementation public with some custom modifier but I would like to understand why the delegatecall to the internal method is not working.

Best Answer

if you are trying to call the init() method in Implementation from Dispatcher using delegatecall , internal will not work. As the internal function visibility specifier only refers to that function being called from inside the contract. So if the delegatecall is in the constructor of the contract, then you will not need to specify anything as the constructor is only run once and that is when the contract is deployed. You cannot call the constructor after it has been deployed.

Related Topic