Professional Documents
Culture Documents
2 2 Deep Dive Into Solidity 6398726974f32871835034 PDF
2 2 Deep Dive Into Solidity 6398726974f32871835034 PDF
WELCOME
KEVIN JONES
AGENDA
WHAT IS SOLIDITY?
STANDARDS
EXAMPLES
HOMEWORK
CLOSING Q&A
2
WHAT IS
SOLIDITY?
LET’S DIVE IN
3
SOLIDITY
• Current version is 0.8.17
// SPDX-License-Identifier: GPL-3.0
• Object-oriented, high-level pragma solidity ^0.8.14;
language
• Static typed, Curly-braces
contract a {
• Optimization is important uint256 b;
function c() public {
• Source compiled into lower-level b = 2;
Bytecode }
• ABI is needed to encode contract }
calls and read data from
transactions
EXAMPLE.SOL > EVM BYTECODE > EVM READS AS ASSEMBLY (OPCODES)
6
STANDARDS
ERC
PROTOCOL STANDARDS
TOKENS
Some examples…
• ERC-20 (FUNGIBLE TOKEN)
• ERC-721 (NON-FUNGIBLE TOKEN)
• ERC-1155 (SEMI-FUNGIBLE TOKEN)
10
ERC-20 TOKEN STANDARD
11
12
ERC-20 VS ERC-721
FUNGIBLE NON-FUNGIBLE
1 =1
13
ERC-721 VS ERC-1155
ERC-721 ERC-1155
14
15
16
17
EXAMPLES
SOLIDITY
HELLO WORLD
// SPDX-License-Identifier: MIT
contract HelloWorld {
string public greet = "Hello World!";
}
19
STATE
contract Counter {
uint public count;
20
STATE
21
FUNCTIONS
contract HelloWorld {
22
VARIABLES
•local
• declared inside a function
• not stored on the blockchain
•state
• declared outside a function
• stored on the blockchain
•global
•provides information about the
blockchain
23
VARIABLES
contract Variables {
// state variables
// stored on the blockchain.
string public text = "Hello";
uint public num = 123;
// local variables
// not saved to the blockchain
uint i = 456;
// global variables
uint timestamp = block.timestamp; // Current block timestamp
address sender = msg.sender; // address of the caller
}
}
24
FUNCTION MODIFIER
25
DATA VALUE TYPES
• Signed/Unsigned integers - Integer data • Byte arrays - Byte arrays, declared with the
types store whole numbers, with signed keyword “bytes”, is a fixed-size array used to
integers storing both positive and negative store a predefined number of bytes up to 32,
values and unsigned integers storing usually declared along with the keyword
non-negative values. (bytes1, bytes2).
• Booleans - Boolean data type is declared with • Literals - Literals are immutable values such
the bool keyword, and can hold only two as addresses, rationals and integers, strings,
possible constant values, true or false. unicode and hexadecimals, which can be
stored in a variable.
• Addresses - The address type is used to store
Ethereum wallet or smart contract addresses, • Enums - Enums, short for Enumerable, are a
typically around 20 bytes. An address type user-defined data type, that restrict the value
can be suffixed with the keyword “payable”, of the variable to a particular set of constants
which restricts it to store only wallet defined within the program.
addresses and use the transfer and send
crypto functions.
26
PRIMITIVE DATA TYPES
uint8 public u8 = 1;
uint public u256 = 456;
uint public u = 123;
27
DEFAULT VALUES
28
CONSTANTS
29
IMMUTABLE
constructor(uint _supply) {
OWNER = msg.sender;
SUPPLY = _supply;
}
30
ENUMS
• Mappings - Mappings store data in
key-value pairs similar to dictionaries in
other object-oriented languages, with the
key being a value data type, and value being
any type.
32
MAPPINGS
33
STRUCTS
struct Todo {
string text;
bool completed;
}
contract Import {
// Initialize Foo.sol
Foo public foo = new Foo();
35
INHERRITENCE
// import remotely
import "https://github.com/owner/repo/blob/branch/path/to/Contract.sol";
36
OTHER FUNCTIONALITY
• If / Else
• For and While
Loops
• Array
37
HOMEWORK
KEEP GOING!
38
BOOKMARK AND READ…
39
BOOKMARK AND WATCH…
40
THANK YOU
kevin@kevinjonescreates.com