...by Daniel Szego
quote
"On a long enough timeline we will all become Satoshi Nakamoto.."
Daniel Szego

Wednesday, December 20, 2017

Solidity and Truffle Tips and Tricks - public, internal and private


General visibilities in solidity both for variables and functions mean the following:

- public: it can be called from overall, from outside the smart contract, from inside or from a descendant class. With variables it is a little bit special, at properties public means that a special getter function is generated that makes possible to read out the value of the property from outside. It must be paid attention however, because this is an automatically generated function that must be called in some scenarios, like from another contract or web3.js as function and not as a property.   

- internal: internal can be used / called only from the same contract or if there is an inheritance from descendant contracts. 

- private: can be called only from the contract itself. Not even a descendant contract is able to access the property or the function.

In functions there is one more option to take into considerations, using public or external. See the previous blog about the consideration of distinguishing the two modifiers.