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

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.

主站蜘蛛池模板: 怀柔区| 石屏县| 通辽市| 新河县| 富蕴县| 金华市| 南澳县| 绥阳县| 岢岚县| 嵊泗县| 龙州县| 斗六市| 泗洪县| 调兵山市| 永平县| 民勤县| 澜沧| 西乌珠穆沁旗| 涿鹿县| 营口市| 灵武市| 任丘市| 扶风县| 壶关县| 黑山县| 银川市| 甘孜县| 郸城县| 富平县| 年辖:市辖区| 晴隆县| 长沙市| 奈曼旗| 祁东县| 木里| 黔江区| 黔西| 沙坪坝区| 根河市| 玉山县| 孝义市|