Copyright © 2018 Nguyen Nguyen
Please never write code without tests
Designs can be found here
https://github.com/thanhnguyennguyen/smart-contract-practice/tree/master/contracts/lottery/design
https://rinkeby.etherscan.io/address/0xa0a5566cb16c16384f3b7b3a3a67cbbe0bf2f137
Memory and storage
avoid nested array
static and dynamic array
Not allowed
bytes and string are special arrays
bytes32 data; (~ byte[32] data )
bytes data (~ byte[] data )
String vss bytes
Function visibilities and modifier
Return multiple values
To assign results from multiple returns function to variable, we use tupple
Function overloading
Constructor overloading is not supported
Variables initialized to defaults at the beginning of functions
Difference between mapping and hashtable (of java) or object (of javascript)
Mapping is defined as state , storage only, not allowed in function
Enum and struct are not a part of ABI definition, not available for external function call
Difference between msg.sender and tx.origin
Error handling in Solidity
What happen if an exception is thrown
Check and handle exception
No keyword abstract contract , function declared but no body provided. That class can not be deployed
Inheritance: multiple inheritance is supported
Overloading (except constructor)
Interface and abstract contract
to implement an interface, use keywork is , similar for extending abstract contract
Events are part of ABI definition
Only indexed event arguments can be used in Filter, maximum 3 indices are allowed
Contract destruction
Sending tracsaction to dead contract: fail
ALl fund send to dead contract will be lost
Using a registry Contract to manage all contracts, then using contract name to access instance of a particular contract
Use another array to keep keys
Cost of iteration goes up
Send vs transfer
Withdrawal pattern
ERC-20 specification: 6 functions, 2 events
https://github.com/thanhnguyennguyen/ERC20-token
Filter object: web3.eth.filter
Event vs filter