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

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.

主站蜘蛛池模板: 安吉县| 蚌埠市| 绥宁县| 辽阳县| 玉门市| 兰溪市| 黑水县| 长子县| 巫溪县| 张家口市| 凌云县| 德阳市| 峨眉山市| 阜城县| 阜城县| 汾阳市| 潞城市| 肃北| 黎川县| 吴旗县| 贵溪市| 汶上县| 济源市| 东宁县| 霍州市| 道真| 华池县| 富宁县| 江门市| 永泰县| 安国市| 旅游| 会理县| 镇赉县| 尼玛县| 辽阳市| 墨竹工卡县| 雅安市| 井冈山市| 卓尼县| 兴国县|