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

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.

主站蜘蛛池模板: 肇庆市| 定远县| 东乌| 松滋市| 荆州市| 吕梁市| 宁武县| 五华县| 宁城县| 平安县| 廉江市| 株洲县| 上饶市| 丰镇市| 华宁县| 磐石市| 昆明市| 葵青区| 余江县| 伊吾县| 肥东县| 山阳县| 满洲里市| 衡山县| 贡觉县| 云阳县| 屯昌县| 大厂| 抚宁县| 丰镇市| 四子王旗| 交城县| 仲巴县| 正蓝旗| 贺兰县| 台湾省| 华蓥市| 武山县| 宜兰县| 彭州市| 富蕴县|