Lesson 1 Recap - cogeorg/teaching GitHub Wiki
The goal of lesson 1 is to create a smart contract that (1) allows you to create a new zombie comprised of a name and a DNA and that (2) stores all newly created zombies in an array.
-
Chapter 2: introduces the pragma and the concept of a smart contract
- pragma: ensures that the contract always compiles the way we intended it
- contract: fundamental building block, comparable to classes in other object-oriented programming languages
-
Chapter 3: introduces state variables and the data type
uint- state variable: variable defined within a smart contract but outside a function. They are permanently stored in contract storage, i.e. on the blockchain
uint: unsigned integer, synonym foruint256, can only be positive
-
Chapter 4: explains math operations possible in Solidity
- Addition:
a + b - Subtraction:
a - b - Multiplication:
a * b - Division:
a / b - Modulus:
a % b - Exponential operator:
a ** b
- Addition:
-
Chapter 5: introduces structs
struct: user-defined data structure that can hold data of different types, e.g.
struct Student { address addr; string name; uint age; } -
Chapter 6: introduces arrays
- an array is a collection of one data type
- it can be of fixed and dynamic size
string[5] fixedStringArray; address[] dynamicAddressArray;- public array: arrays are state variables and by default
internalbut can be explicitly set topublic, e.g.
address[] public publicDynamicAddressArray; -
Chapter 7: introduces functions
- a function is an executable unit of code
-
Chapter 8: practice the concepts struct and array
-
Chapter 9: introduces function visibility
public: everybody can call the functionprivate: the function is exclusive to contract (default)
-
Chapter 10: function return values and function modifiers
- return values in Solidity functions are declared, i.e.
function exampleFunction (uint _a) returns (uint) { //... }- modifiers:
view: function does not alter state variablespure: function does not access state variables
-
Chapter 11: conversion of data types
- typecasting: cast variable to different type to prevent problems, e.g.
uint a = 1; uint8 b = 2; uint8 c = uint8(a) + bkeccak256: a hashing algorithm that converts strings to 256-bit hexadecimal numbers
-
Chapter 12: practice functions
-
Chapter 13: introduces events *
event: is an easy way for a contract to communicate with the front-end. It is defined and later on triggered by using the keywordemitinside a function.