Solidity
Going threw https://cryptozombies.io to learn Solidity
Contracts
Solidity code is encapsulated in contracts which are the building blocks of Ethreum applications. All variables and functions belong to a contract
contract HelloWorld {
}Version Pragma
All code should include the version pragma which tells the version of the Solidiy compiler our code uses.
pragma solidity >=0.5.0 <0.6.0;
contract HelloWorld {
}State Variables
Are variables that are permanently stored to contract storage. Which means they are written to the Ethereum Blockchain
contract Example {
// This will be stored permanently in the blockchain
uint myUnsignedInteger = 100;
}Math Operations
Work similar to most programming languages +, -, /, *
if you want to do say 5^2 you would do 5 ** 2
Structs
struct Person {
uint age;
string name;
}Arrays
Both fixed and dynamic
unit[5] fixedArray;
string[] dynamicArray;
Person[] people //Array of structsyou can make an array public which will automatically give an array a getter method
Person[] public people;Function Declartion
function eatHamburgers(string memory _name, uint _amount) public {
}
in the above method we are using a reference type variable (string) when we do this we want to state where the data location is memory
There are three data location types. memory, storage, and calldata
It is also best practice to add an _ to the beginning of function parameter variables
by default functions are public
When making a private function it is convention to give the function the _ naming
function _eatHamburgers(string memory _name, uint _amount) private {
}There are 2 method modifiers view - Can only view data but not modify it pure - No accessing data in the app
Example of a view function:
string greeting = 'Hello';
function sayHello() public view returns (string memory) {
return greeting;
}
Example of a pure function:
function _multiply(uint a, uint b) private pure returns (uint) {
return a * b;
}left off at https://cryptozombies.io/en/lesson/1/chapter/11