uint public timeout = 60;

Everything looked nice until now, because you trusted me. I told you about uint but nothing on public. It is the visibility attribute associated with the variable

What is visibility

Visibility represents the scope of a variable. You can choose to make them public or private. The formal way to express a variable declaration is

<type> <visibility> <name> = <value>;


When public, variables can be accessed from anywhere, either outside of the contract or internally. It is the most permissive visibility parameter.


A private variable will not be accessible from outside of the contract. It is the most restrictive permission you can set.


If you start looking out for code on the internet, you might notice that some people omit the visibility parameter. You won't! While being semantically valid, because a default visibility is automatically applied, it is harder to write and to spot errors.

Amiral tip

When performing tests on your contract, we won't be able to access private variables because we will be considered as an external user



Let's make the variable halfway private. Noone wants to know what is halfway anyway
pragma solidity ^0.4.24; contract SpacecryptFactory { uint public timeout = 60; uint public halfway = timeout / 2; bytes32 public name = 'SuperCryptor 2000'; // There is some code down there // You don't know yet what it is doing // So don't touch it // Cookies waiting on next page if you trust me function getHalfway() external view returns (uint) { return halfway; } }

Let's move on and grab those public cookies.

results matching ""

    No results matching ""