Solidity’s Cheap Public Face
This article discusses automatic storage getters provided by Solidity, the defacto smart contract language for the Ethereum blockchain.
Background
During the development and testing of Datona Labs’ Solidity Smart-Data-Access-Contract (S-DAC) templates, we wanted to publish values of some storage variables, for example:
contract ExampleSDA is ... {
// SDA data
address public requester;
uint public duration_Days;
uint public start_Sec;
bool public activated; ...
}
ExampleSDA is the example contract for this article and contains 4 variables which are referred to as the SDA data in the discussion below.
Discussion
Solidity contracts conveniently provide automatic getters for storage variables declared as public. See the Solidity documentation here. These getters are functions that enable read access to the variables externally. Thus in the ExampleSDA above, the automatically generated getters are the equivalent of:
contract ExampleSDA is ... { ... function requester() public returns (address) {
return requester;
}