EPT Slide
EPT Slide
EPT Slide
Day 1 - 2
Documents Database (NoSql)
Implement document database (nosql)
Given interface are just guideline.
Feel free to change but keep these functionaliy:
Can add document to collection
Update all documents in collection that have provided ‘key’
Read all value in documents in collection that have provided ‘key’
Delete all value in documents in collection that have provided ‘key’
A bit of Evm
Language Data types
Control structure & Contract (Class-like) structure
A bit of toolings
Ethereum virtual machine (roughly)
Data types
Variable
Control structure
Syntax Composed
Function/Method in others many languages
Expression/Operators
Contract oriented (Class-like)
Solidity as just another language
And with new paradigm and a lot of new concept you will learn and applied in next
session will likely benefit you most when you got some ground on the language first
Solidity as just another language
Types
Value Types
Variables will always be passed by value, i.e. they are always copied when they are used as function arguments or in
assignments
Bool
Intergers
Fixed-size byte arrays
Literals
Enums
Address
Contract type
Solidity as just another language
Division
alway result in the same type so it will be rounding (towards zero)
i.e. int(-5)/int(2) will be -2
Solidity as just another language
Operators:
Most are like integers
Index access: If x is of type bytesI, then x[k] for 0 <= k < I returns the k-th byte (read-only).
.length return the fixed length of the byte array
<0.8 byte used to be an alias for bytes1
Byte is a 8-bit represent of 0 or 1 default value is 0x00
Function
function (<parameter types>) {internal|external|private|public} [pure|view|payable] [returns (<return types>)]
public visible everywhere (within the contract itself and other contracts or addresses).
private visible only by the contract it is defined in, not derived contracts.
internal visible by the contract itself and contracts deriving from it.
external visible only by external contracts / addresses.
View functions can read contract’s storage, but can’t modify the contract storage. Therefore, they are used for getters.
Pure functions can neither read, nor modify the contract’s storage. They are used for pure computation, like functions
that perform mathematic or cryptographic operations.
Solidity as just another language
More on functions
Solidity as just another language
Reference Types
Current reference types support:
Mapping
Array
Struct
Unlike Value types where its store data in its own variable, but reference types only store its reference to the data
Solidity as just another language
Data Location
where the data is stored. There are three data locations:
memory non-persistent
storage persistent
calldata like memory but non-modifiable and non-persistent it’s area where function args stored
Think this way, how it differentiate between persistent data and transient data during execution?
Solidity as just another language
Data Location
Where you must specify the data location?
Function parameter
Local variable inside function
Return value
Some of rules:
Storage cannot be newly created, it
need pre-allocated on contract storage
to refer to
Memory can be newly created or
copied from a storage variable
Function parameter and return can be
only memory and calldata
Solidity as just another language
Array
Special array types
String and bytes
string doesn’t have .length
Structs
Struct field can be
Value Types (uint / int, bool, address,
string, etc…)
Reference Types like mapping array
but not struct itself
It can be array of struct
Solidity as just another language
Mapping
Similar to HashMap or Dict
Don’t have length and can’t iterate
Solidity as just another language
Hash, typecasting
Solidity as just another language
Inheritance Import
Solidity as just another language
Multiple Return
Foundry
More on https://book.getfoundry.sh/
OrderPreservedMapping
Can be iterate in mapping and getting list of value by order insertion
i.e.
set(“keyA”, 10)
set(“keyB”, 20)
set(“keyC”, 30)
set(“keyB”, 10)