I recently read a smart contract from Openzepplin with the following code in it

    uint256 private certainAmount;

    function getCertainAmount() public returns (uint256){
        return certainAmount;

    function usesCertainAmount() public {
        uint256 calculation = getCertainAmount() + 200;

as you can see they are using the getter of the private function even inside the same contract, and I can't seem to understand why?

1 Answer 1


The main reason is that if those are functions, you can override them in inheriting contracts more easily. If they were just variables in a function, you would need to rewrite the whole function - now you just need to rewrite the variable part.

This is a quite common pattern with OpenZeppelin: they make their contracts "pluggable", so you can easily inject your own functionality in places. They even have sometimes empty function implementations just because of this.


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.