Skip to content

Instantly share code, notes, and snippets.

@alexpanasUCLA
Last active June 27, 2022 12:36
Show Gist options
  • Save alexpanasUCLA/bcda557b07fdbf670d0050d0e86038ba to your computer and use it in GitHub Desktop.
Save alexpanasUCLA/bcda557b07fdbf670d0050d0e86038ba to your computer and use it in GitHub Desktop.
Private modifier lesson
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0;
contract check_private {
// Declaring private variable
uint private _number =2;
// Can you check what is private variable
// from the contract ?
function getter() public view returns(uint)
{
return _number; }
// Try to modify the value of private variable
// inside of the contract
function attempt_to_modify() public returns (uint){
return _number += 4;
}
}
contract child is check_private {
// By calling this function you can
// modify private variable
// Not much privacy, isn't?
function get_() public returns(uint)
{
return attempt_to_modify();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment