├── README.md ├── Code ├── Solidity Basics │ ├── Special Variables and Functions │ │ └── example.sol │ ├── Variable Literals │ │ └── example.sol │ ├── Comments │ │ └── example.sol │ ├── Data Types │ │ └── example.sol │ ├── Enums │ │ └── example.sol │ ├── Function Calls │ │ └── example.sol │ ├── Arrays │ │ └── example.sol │ ├── Structs │ │ └── example.sol │ ├── Loops │ │ └── example.sol │ ├── Conditional Statements │ │ └── example.sol │ └── Ether and Time Units │ │ └── example.sol └── Solidity Advanced │ ├── Events │ └── example.sol │ ├── Accessor Functions │ └── example.sol │ ├── Esoteric Functions │ └── example.sol │ ├── Abstract Contracts │ └── example.sol │ ├── Interfacing With Other Contracts │ └── example.sol │ ├── Contract Inheritance │ └── example.sol │ ├── Function Modifiers │ └── example.sol │ ├── Constructor Arguments │ └── example.sol │ ├── Multiple Inheritance and Linearization │ └── example.sol │ └── Visibility Specifiers │ └── example.sol └── LICENSE /README.md: -------------------------------------------------------------------------------- 1 | # Solidity Tutorials 2 | 3 | -------------------------------------------------------------------------------- /Code/Solidity Basics/Special Variables and Functions/example.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.6; 2 | 3 | contract SimpleStorage 4 | { 5 | uint storedData = 0; 6 | 7 | function set(uint x) 8 | { 9 | storedData = block.number; 10 | } 11 | 12 | function get() constant returns (uint retVal) 13 | { 14 | return storedData; 15 | } 16 | } -------------------------------------------------------------------------------- /Code/Solidity Basics/Variable Literals/example.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.6; 2 | 3 | contract SimpleStorage 4 | { 5 | uint storedData; 6 | 7 | function set(uint x) 8 | { 9 | storedData = x; 10 | var var1 = "hello"; 11 | } 12 | 13 | function get() constant returns (uint retVal) 14 | { 15 | return storedData; 16 | } 17 | } -------------------------------------------------------------------------------- /Code/Solidity Advanced/Events/example.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.6; 2 | 3 | contract SimpleStorage 4 | { 5 | event LogEvent(uint); 6 | 7 | uint storedData = 0; 8 | 9 | function set(uint x) 10 | { 11 | LogEvent(x); 12 | storedData = x; 13 | } 14 | 15 | function get() constant returns (uint retVal) 16 | { 17 | return storedData; 18 | } 19 | } -------------------------------------------------------------------------------- /Code/Solidity Basics/Comments/example.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.6; 2 | 3 | contract SimpleStorage 4 | { 5 | uint storedData; 6 | 7 | // hello world, this is a method 8 | /*function set(uint x) 9 | { 10 | storedData = x; 11 | }*/ 12 | 13 | /// @dev This is a natspec comment 14 | function get() constant returns (uint retVal) 15 | { 16 | return storedData; 17 | } 18 | } -------------------------------------------------------------------------------- /Code/Solidity Basics/Data Types/example.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.6; 2 | 3 | contract SimpleStorage 4 | { 5 | int storedData; 6 | bool var1; 7 | string var2; 8 | 9 | function set(string x) 10 | { 11 | //storedData = x; 12 | //storedData = -7; 13 | //var1 = x; 14 | var2 = x; 15 | } 16 | 17 | function get() constant returns (string retVal) 18 | { 19 | return var2; 20 | } 21 | } -------------------------------------------------------------------------------- /Code/Solidity Advanced/Accessor Functions/example.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.6; 2 | 3 | contract Simple 4 | { 5 | uint public Hello = 5; 6 | } 7 | 8 | contract SimpleStorage 9 | { 10 | uint storedData = 0; 11 | Simple s1 = new Simple(); 12 | 13 | function set(uint x) 14 | { 15 | storedData = s1.Hello(); 16 | } 17 | 18 | function get() constant returns (uint retVal) 19 | { 20 | return storedData; 21 | } 22 | } -------------------------------------------------------------------------------- /Code/Solidity Basics/Enums/example.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.6; 2 | 3 | contract SimpleStorage 4 | { 5 | uint storedData = 0; 6 | 7 | enum SpecialType { one, two, three, four, five } 8 | SpecialType var1; 9 | 10 | function set(uint x) 11 | { 12 | var1 = SpecialType.four; 13 | storedData = x; 14 | } 15 | 16 | function get() constant returns (SpecialType retVal) 17 | { 18 | return var1; 19 | } 20 | } -------------------------------------------------------------------------------- /Code/Solidity Basics/Function Calls/example.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.6; 2 | 3 | contract SimpleStorage 4 | { 5 | uint storedData = 0; 6 | 7 | function set(uint x) 8 | { 9 | storedData = AwesomeFunction(x, 7); 10 | } 11 | 12 | function get() constant returns (uint retVal) 13 | { 14 | return storedData; 15 | } 16 | 17 | function AwesomeFunction(uint x, uint y) returns (uint retVal) 18 | { 19 | return x*y; 20 | } 21 | } -------------------------------------------------------------------------------- /Code/Solidity Advanced/Esoteric Functions/example.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.6; 2 | 3 | contract SimpleStorage 4 | { 5 | uint storedData = 0; 6 | 7 | function Maybe() constant returns (uint retVal) 8 | { 9 | return 9; 10 | } 11 | 12 | function set(uint x) 13 | { 14 | var frahaan = Maybe; 15 | storedData = frahaan(); 16 | } 17 | 18 | function get() constant returns (uint retVal) 19 | { 20 | return storedData; 21 | } 22 | } -------------------------------------------------------------------------------- /Code/Solidity Advanced/Abstract Contracts/example.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.6; 2 | 3 | contract Simple 4 | { 5 | function Hello() constant returns (uint retVal); 6 | } 7 | 8 | contract SimpleStorage is Simple 9 | { 10 | uint storedData = 0; 11 | 12 | function Hello() constant returns (uint retVal) 13 | { 14 | return 8; 15 | } 16 | 17 | function set(uint x) 18 | { 19 | storedData = x; 20 | } 21 | 22 | function get() constant returns (uint retVal) 23 | { 24 | return storedData; 25 | } 26 | } -------------------------------------------------------------------------------- /Code/Solidity Basics/Arrays/example.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.6; 2 | 3 | contract SimpleStorage 4 | { 5 | uint storedData = 0; 6 | 7 | uint[4] arrayOne; 8 | uint[2][10] arrayTwo; 9 | 10 | function set(uint x) 11 | { 12 | arrayOne[0] = 5; 13 | arrayOne[1] = 5; 14 | arrayOne[2] = 5; 15 | arrayOne[3] = 5; 16 | 17 | arrayTwo[9][1] = 8; 18 | 19 | storedData = x; 20 | } 21 | 22 | function get() constant returns (uint retVal) 23 | { 24 | return arrayOne.length; 25 | } 26 | } -------------------------------------------------------------------------------- /Code/Solidity Basics/Structs/example.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.6; 2 | 3 | contract SimpleStorage 4 | { 5 | uint storedData = 0; 6 | 7 | struct Car 8 | { 9 | uint speed; 10 | uint weight; 11 | int age; 12 | string name; 13 | } 14 | 15 | Car var1; 16 | Car var2; 17 | Car var3; 18 | Car var4; 19 | 20 | function set(uint x) 21 | { 22 | var1.speed = 90; 23 | storedData = x; 24 | } 25 | 26 | function get() constant returns (uint retVal) 27 | { 28 | return var1.speed; 29 | } 30 | } -------------------------------------------------------------------------------- /Code/Solidity Advanced/Interfacing With Other Contracts/example.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.6; 2 | 3 | contract Awesome 4 | { 5 | uint hello = 5; 6 | 7 | function getHello() constant returns (uint retVal) 8 | { 9 | return hello; 10 | } 11 | } 12 | 13 | contract SimpleStorage 14 | { 15 | uint storedData = 0; 16 | Awesome awesomeObj = new Awesome(); 17 | 18 | function set(uint x) 19 | { 20 | storedData = awesomeObj.getHello(); 21 | } 22 | 23 | function get() constant returns (uint retVal) 24 | { 25 | return storedData; 26 | } 27 | } -------------------------------------------------------------------------------- /Code/Solidity Advanced/Contract Inheritance/example.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.6; 2 | 3 | contract Simple 4 | { 5 | function Function1() constant returns (uint retVal) 6 | { 7 | return 7; 8 | } 9 | 10 | function Function2(uint value) constant returns (uint retVal) 11 | { 12 | return value * value; 13 | } 14 | } 15 | 16 | contract SimpleStorage is Simple 17 | { 18 | uint storedData = 0; 19 | 20 | function set(uint x) 21 | { 22 | storedData = x; 23 | } 24 | 25 | function get() constant returns (uint retVal) 26 | { 27 | return Function1(); 28 | } 29 | } -------------------------------------------------------------------------------- /Code/Solidity Basics/Loops/example.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.6; 2 | 3 | contract SimpleStorage 4 | { 5 | int storedData = 0; 6 | 7 | function set(int x) 8 | { 9 | /*for (int i = x; i < 10; i++) 10 | { 11 | storedData++; 12 | }*/ 13 | 14 | int i = x; 15 | 16 | while ( i < 10) 17 | { 18 | //break; 19 | //continue; 20 | 21 | storedData++; 22 | 23 | i++; 24 | } 25 | } 26 | 27 | function get() constant returns (int retVal) 28 | { 29 | return storedData; 30 | } 31 | } -------------------------------------------------------------------------------- /Code/Solidity Advanced/Function Modifiers/example.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.6; 2 | 3 | contract Simple 4 | { 5 | uint public hello = 0; 6 | 7 | modifier mod 8 | { 9 | require (hello < 5); 10 | _; 11 | } 12 | 13 | function SetHello(uint value) mod 14 | { 15 | hello = value; 16 | } 17 | } 18 | 19 | contract SimpleStorage 20 | { 21 | uint storedData = 0; 22 | Simple s1 = new Simple(); 23 | 24 | function set(uint x) 25 | { 26 | s1.SetHello(x); 27 | //storedData = x; 28 | } 29 | 30 | function get() constant returns (uint retVal) 31 | { 32 | return s1.hello(); 33 | } 34 | } -------------------------------------------------------------------------------- /Code/Solidity Advanced/Constructor Arguments/example.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.6; 2 | 3 | contract Awesome 4 | { 5 | uint hello; 6 | 7 | function Awesome(uint value) 8 | { 9 | hello = value; 10 | } 11 | 12 | function getHello() constant returns (uint retVal) 13 | { 14 | return hello; 15 | } 16 | } 17 | 18 | contract SimpleStorage 19 | { 20 | uint storedData = 0; 21 | Awesome awesomeObj = new Awesome(89); 22 | 23 | function set(uint x) 24 | { 25 | storedData = awesomeObj.getHello(); 26 | } 27 | 28 | function get() constant returns (uint retVal) 29 | { 30 | return storedData; 31 | } 32 | } -------------------------------------------------------------------------------- /Code/Solidity Advanced/Multiple Inheritance and Linearization/example.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.6; 2 | 3 | contract Simple 4 | { 5 | function Function1() constant returns (uint retVal) 6 | { 7 | return 7; 8 | } 9 | 10 | function Function2(uint value) constant returns (uint retVal) 11 | { 12 | return value * value; 13 | } 14 | } 15 | 16 | contract Simple2 is Simple 17 | { 18 | function Function3() constant returns (uint retVal) 19 | { 20 | return 9; 21 | } 22 | 23 | function Function4(uint value) constant returns (uint retVal) 24 | { 25 | return value * 2; 26 | } 27 | } 28 | 29 | contract SimpleStorage is Simple2 30 | { 31 | uint storedData = 0; 32 | 33 | function set(uint x) 34 | { 35 | storedData = x; 36 | } 37 | 38 | function get() constant returns (uint retVal) 39 | { 40 | return Function3(); 41 | } 42 | } -------------------------------------------------------------------------------- /Code/Solidity Basics/Conditional Statements/example.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.6; 2 | 3 | contract SimpleStorage 4 | { 5 | uint storedData; 6 | 7 | function set(uint x) 8 | { 9 | /*if (x == 5) 10 | { 11 | x = x * 4; 12 | }*/ 13 | 14 | /* 15 | if (x == 5) 16 | { 17 | return; 18 | }*/ 19 | 20 | /* 21 | if (x != 5) 22 | { 23 | return; 24 | }*/ 25 | 26 | /* 27 | if (x >= 5) 28 | { 29 | return; 30 | }*/ 31 | 32 | /* 33 | if (x < 5) 34 | { 35 | return; 36 | }*/ 37 | 38 | if (x >= 5) 39 | { 40 | x = 10; 41 | } 42 | else 43 | { 44 | x = 1; 45 | } 46 | 47 | storedData = x; 48 | } 49 | 50 | function get() constant returns (uint retVal) 51 | { 52 | return storedData; 53 | } 54 | } -------------------------------------------------------------------------------- /Code/Solidity Advanced/Visibility Specifiers/example.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.6; 2 | 3 | contract Simple 4 | { 5 | function Function1() public 6 | { 7 | Function2(); 8 | } 9 | 10 | function Function2() private 11 | { 12 | Function1(); 13 | Function3(); 14 | } 15 | 16 | function Function3() internal 17 | { 18 | this.Function4(); 19 | } 20 | 21 | function Function4() external 22 | { 23 | 24 | } 25 | } 26 | 27 | contract SimpleInherit is Simple 28 | { 29 | function FunctionAlpha() 30 | { 31 | Function1(); 32 | //Function2(); 33 | Function3(); 34 | this.Function4(); 35 | } 36 | } 37 | 38 | contract SimpleStorage 39 | { 40 | uint storedData = 0; 41 | Simple s1 = new Simple(); 42 | 43 | function set(uint x) 44 | { 45 | storedData = x; 46 | 47 | s1.Function1(); 48 | //s1.Function3(); 49 | s1.Function4(); 50 | } 51 | 52 | function get() constant returns (uint retVal) 53 | { 54 | return storedData; 55 | } 56 | } -------------------------------------------------------------------------------- /Code/Solidity Basics/Ether and Time Units/example.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.6; 2 | 3 | contract SimpleStorage 4 | { 5 | uint storedData = 0; 6 | 7 | function set(uint x) 8 | { 9 | //storedData = x; 10 | 11 | /* 12 | ETHER UNITS 13 | ----------- 14 | Wei 15 | Finney 16 | Szabo 17 | Ether 18 | */ 19 | /* 20 | if (2000000000000000000 == 2 ether) 21 | { 22 | storedData = 2; 23 | } 24 | else 25 | { 26 | storedData = 3; 27 | }*/ 28 | 29 | /* 30 | TIME UNITS 31 | ---------- 32 | seconds 33 | minutes 34 | hours 35 | days 36 | weeks 37 | months 38 | years 39 | */ 40 | if (120 seconds == 2 minutes) 41 | { 42 | storedData = 6; 43 | } 44 | else 45 | { 46 | storedData = 9; 47 | } 48 | } 49 | 50 | function get() constant returns (uint retVal) 51 | { 52 | return storedData; 53 | } 54 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | --------------------------------------------------------------------------------