Skip to content

Instantly share code, notes, and snippets.

@aalu1418
Last active January 4, 2021 22:43
Show Gist options
  • Save aalu1418/3d41f8f4c27192f79cdab12923a134fd to your computer and use it in GitHub Desktop.
Save aalu1418/3d41f8f4c27192f79cdab12923a134fd to your computer and use it in GitHub Desktop.
Variable Types + Visibility
pragma solidity >=0.5.0 <0.7.0;
contract Test {
// Variable Example
// Unsigned integer that is visibile to derived contracts equal to 10
uint256 internal _demoOne = 10;
// boolean equal to true that is visible to everyone
bool public _demoTwo = true;
// Arrays & Mapping Example
// Mapping (like objects/dictionaries/etc) from address to integer
mapping (address => uint) public _demoMapping;
// Array of addresses (can be an array of any variable type)
address[] public _demoArray;
// ------------ MISSION OBJECTIVES ----------------------
// Create the following:
// integer equal to 10 that is visible to internal and external contracts
// boolean equal to true that is only visible to itself
// address equal to 0x15fd1E4F13502b1a8BE110F100EC001d0270552d that is visible to everyone
uint256 _int;
bool _bool;
address _address;
// Create the following:
// a mapping from integer to bool
// an array of booleans
public _mapping;
public _boolArray = [false, true];
// ------------------------------------------------------
// DO NOT MODIFY BELOW - USED FOR TESTING
function test() public returns (bool) {
_mapping[100] = true;
require(_int == 10, "Integer correct");
require(_bool == true, "Boolean correct");
require(_address == 0x15fd1E4F13502b1a8BE110F100EC001d0270552d, "Address correct");
require(_mapping[100] == true, "Mapping correct");
require(_boolArray[1] == true, "Array correct");
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment