-
Notifications
You must be signed in to change notification settings - Fork 0
/
SolidityCheatSheet.sol
78 lines (62 loc) · 1.96 KB
/
SolidityCheatSheet.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// A single line comment
/*
A multiline comment
*/
pragma solidity ^0.4.21; //Solidity version supported
contract ExampleContract {
// NUMBERS
uint8 public smallPublicInteger;
uint256 private bigPrivateInteger;
uint private alsoBigPrivateInteger;
int256 constant public constantBigSignedInteger = 34;
bool public booleanWithInitialisation = true;
// no floats :P
// STRINGS/BLOBS
string public variableLenghtString;
bytes12 public shortConstantLenghtString;
bytes32 public longConstantLenghtString;
// address
address public anAddress;
// ARRAYS
uint32[] public arrayOfIntegers;
// COLLECTIONS
// Note: collections are not iterable
mapping(address => uint32) mapOfAddressToUnsignedInteger;
mapping(address => mapping(uint32 => uint32)) mapOfMaps;
// ENUM
enum ExampleEnum {
EnumValue1,
EnumValue2
}
ExampleEnum public exampleEnum;
// CONSTRUCTOR
function ExampleContract(uint8 someParameter) public {
anAddress = msg.sender;
smallPublicInteger = someParameter;
bigPrivateInteger = 0;
}
// EVENT
event EventExample(uint256 someValue);
// FUNCTION MODIFIER
modifier onlyOwner() {
require(msg.sender == anAddress);
_; // the underscore represents the decorated function
}
// FUNCTION EXAMPLES
// public payable (includes founds) function
function takeEthereum() public payable {
bigPrivateInteger += msg.value;
emit EventExample(bigPrivateInteger);
}
// private and view (does not mofify state) function returning a boolean
function isIntegerInArray(uint32 someParameter) view returns(bool) {
// For loop
for (uint32 i = 0; i < arrayOfIntegers.length; ++i){
// A conditional
if (arrayOfIntegers[i] == someParameter) {
return true;
}
}
return false;
}
}