Hi @matren,
Sorry for the delay in replying. Great questions!
I’ve given them a lot of thought, and rather than intending my following comments to be a definitive answer, I see them more as throwing out some ideas for further debate. So I’m also tagging my colleague @gabba, to ask for his input.
That’s exactly what I would use here if you want to prevent the smart contract from automatically creating a public getter enabling the owner’s address to be viewed externally by an end user from their front-end application. That of course doesn’t prevent you from writing your own public getter function to provide this functionality. But I think the key thing here is that by setting the visibility to internal
we at least give ourselves more control over our smart contract’s capabilities.
Good question! As you have said, my understanding is also that …
… and so private
doesn’t actually mean secret here. Rather than being about data privacy, I think visibility is more about how many checks and balances we as developers build into the code of our smart contract. In other words, visibility provides developers with more or less control over which parts of their smart contract are more readily accessible from other functions and user interfaces, both internally and externally.
However, I’m not entirely convinced that, by omitting the visibility marker, Solidity defaults to full public visibility, because when we do this, Remix doesn’t automatically provide a getter for the owner’s address like it does when visibility is expressly marked public
. But, as I’ve already mentioned above, even if we mark a state variable as private
, we can always just access it anyway by writing our own public getter function. Again, this would seem to support my theory that the importance of visibility is to provide us with different degrees of control over our smart contract’s capabilities, and is therefore also an important tool in helping to reduce the risk of bugs creeping in. And I think these are the reasons I would give in answer to your question:
Essentially, this is correct. External contracts and front-end users can only manipulate state variables indirectly, by invoking functions marked with public visibility (or public or external visibility in the case of external contracts).
I think that whether you are getting or setting the value of a state variable as a front-end user, you are always calling a smart contract function, and so always accessing the variable’s value indirectly, rather than directly.