官术网_书友最值得收藏!

Visibility of variables

Every variable and function in Solidity has a specific visibility. The visibility is a keyword you use after the variable type to define who should have access to it:

  • Public: This means that the variable can be read or written by any contract, including external ones, as long as there's a function to update them.
  • Private: Private variables can't be accessed by a derived smart contract, those that implement your contract with the is keyword; for example, contract Example is Another {}, where Another is a smart contract with private variables that can't be accessed by Example.
  • External: These variables and functions are not accessible by the contract containing them. Only external contracts and users can use them.
  • Internal: These are variables and functions that can't be read or written by external entities, only by the contract itself or by inherited contracts, as you saw in the example for the private variable.

To keep things simple, I recommend you to always write public for your variables unless it's a special variable, which doesn't happen that often. If you don't define any visibility, the variable will be public by default, although it's better to just write the public keyword in every variable to make sure that you understand the visibility of the variable and it's not a mistake.

主站蜘蛛池模板: 新泰市| 宜宾县| 青川县| 聂荣县| 红桥区| 夏津县| 定安县| 苏尼特右旗| 剑河县| 澳门| 广昌县| 凉城县| 长武县| 怀来县| 当涂县| 尼木县| 上高县| 大厂| 瑞昌市| 天水市| 东丰县| 原平市| 岗巴县| 五家渠市| 视频| 吴旗县| 巴彦县| 伊吾县| 成都市| 德江县| 阳春市| 汝州市| 大荔县| 牙克石市| 亚东县| 合阳县| 峡江县| 若尔盖县| 合山市| 资兴市| 增城市|