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 ![data-location](https://camo.githubusercontent.com/6b34b30f5f36160f9983a62f97ebe9dfd2a36f6b8bb6ea09013edf9d68d22fc4/68747470733a2f2f692e696d6775722e636f6d2f374832317031452e6a7067)
avoid nested array ![Solidity note 1](https://camo.githubusercontent.com/70b59b1f31e8deb5e80b7de7d9c76294a206863e72f52d3053451c9f27a8eaf4/68747470733a2f2f692e696d6775722e636f6d2f4f6b49495652622e706e67)
static and dynamic array ![dynamic-static](https://camo.githubusercontent.com/c3e2b2f524b1639c503e29c57a7913a68051acc047a7743dc28a3eae30092fd4/68747470733a2f2f692e696d6775722e636f6d2f566f684b5063742e6a7067)
Not allowed ![not-allowed](https://camo.githubusercontent.com/a32bf13aa6ce943197efd15ba1b9db26c6495c34aef7f2f0e50086a53bce319f/68747470733a2f2f692e696d6775722e636f6d2f554b4a38754f4d2e6a7067)
bytes and string are special arrays
bytes32 data; (~ byte[32] data )
bytes data (~ byte[] data )
String vss bytes ![string-vs-bytes](https://camo.githubusercontent.com/69c5750123482bdf5cc38e0ba2f6feeaa5696368e8ab63347317710281ef4a95/68747470733a2f2f692e696d6775722e636f6d2f777238764b544d2e6a7067)
![function](https://camo.githubusercontent.com/e3d743bf26a61c5371f3d5573109aca947b6288d3adff2969a4d1192396cfa56/68747470733a2f2f692e696d6775722e636f6d2f31353336434c662e6a7067)
Function visibilities and modifier ![func-visibilities](https://camo.githubusercontent.com/a5b29112cee386c9b730a7c30a8f167622ac22c111f97575fdb16f206d10fcc4/68747470733a2f2f692e696d6775722e636f6d2f616c4348326d612e6a7067)
Return multiple values ![func-return-multiple-values](https://camo.githubusercontent.com/23f097e5afc25b2a488a59b2318fcbbe83be2905a764681e1007c2c3cb87ee48/68747470733a2f2f692e696d6775722e636f6d2f4f786f54546a682e6a7067)
To assign results from multiple returns function to variable, we use tupple ![tupple](https://camo.githubusercontent.com/a1766f4c97f92a6fba018ab922b5e95bab60b90d58e511a0184321671b954fc7/68747470733a2f2f692e696d6775722e636f6d2f784e7378354d552e6a7067)
Function overloading ![func-overloading](https://camo.githubusercontent.com/e820df4362d60ad5f02494e6b2268f316cba02f1e6819a9ceabc31cfb06e07c7/68747470733a2f2f692e696d6775722e636f6d2f7252354c4b64682e6a7067)
Constructor overloading is not supported
Variables initialized to defaults at the beginning of functions
![variable-initialization](https://camo.githubusercontent.com/7e781f8a3594947bb770ee1ebed0c1ace75cc494693b5288a112727fac666701/68747470733a2f2f692e696d6775722e636f6d2f707342797162392e6a7067)
Difference between mapping and hashtable (of java) or object (of javascript) ![](https://camo.githubusercontent.com/58f8dda2c2e134ebdc708e14d862b3d8648eae4cbe5746f3edc1339bcaa60c63/68747470733a2f2f692e696d6775722e636f6d2f3149316f596243672e6a7067)
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
![global-var](https://camo.githubusercontent.com/d5edff6c5eaf1f01c984e4f7a1655def2c52090ecb8c3ad125ea974054e060b9/68747470733a2f2f692e696d6775722e636f6d2f737671504e474b2e6a7067)
Difference between msg.sender and tx.origin ![msg-sender-vs-tx-origin](https://camo.githubusercontent.com/86863d3c179dc6a771e057179f6ccb4af3a9382f6f479d1a125fd7eca0af00d3/68747470733a2f2f692e696d6775722e636f6d2f4b6678695062652e6a7067)
Error handling in Solidity
What happen if an exception is thrown
![exception](https://camo.githubusercontent.com/255bdb02626bd43297659881e04e4e8c4f785d428bf0224e55c8d43cc47b22dc/68747470733a2f2f692e696d6775722e636f6d2f6e476178566e622e6a7067)
Check and handle exception ![handle-exception](https://camo.githubusercontent.com/96a16d179e26d45cfb3e483ab1afa19592bf0712a19814f537dd6f8be6c2bf29/68747470733a2f2f692e696d6775722e636f6d2f7154666e796d35672e6a7067)
![](https://camo.githubusercontent.com/3124eca5b70a182297fb93bd1748224577572198235b582abf0dcf6a25d7b79b/68747470733a2f2f692e696d6775722e636f6d2f693163384e42792e6a7067)
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
![event](https://camo.githubusercontent.com/c2f4d42ee679ceec377cfdbcfcb93a2cd3d0cdc496c348f632c51461bb629961/68747470733a2f2f692e696d6775722e636f6d2f724644367343382e6a7067)
Contract destruction ![contract-destruction](https://camo.githubusercontent.com/0e7f5cfbb3150c0d5a8dc9bcaa526e441efd73a419aca4913715e38a51eaa6d8/68747470733a2f2f692e696d6775722e636f6d2f445432686644302e6a7067)
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 ![mapping-itorator-pattern](https://camo.githubusercontent.com/72307d7df3b6a2c2d2e359101fbd381245156038d2a4c43d42488d30096af5df/68747470733a2f2f692e696d6775722e636f6d2f465a5077423154672e6a7067)
Cost of iteration goes up
Send vs transfer ![send-vs-transfer](https://camo.githubusercontent.com/c4561409282409279cb8ef4409a7b9c4cd14b60c8e81aa78edeedff83c1307b6/68747470733a2f2f692e696d6775722e636f6d2f777a614367784f2e6a7067)
Withdrawal pattern ![withdrawal-pattern](https://camo.githubusercontent.com/c03ea86d6949c8d3e3f5bc83116aa4e00ef821d103482933618858ecd2b8b387/68747470733a2f2f692e696d6775722e636f6d2f306c59757563532e6a7067)
![](https://camo.githubusercontent.com/758699d96413bc66ebce4e3f9ebc49efc1265b18e45c9e5368a13f998cc0529a/68747470733a2f2f692e696d6775722e636f6d2f6d3577794644312e6a7067)
ERC-20 specification: 6 functions, 2 events
https://github.com/thanhnguyennguyen/ERC20-token
Filter object: web3.eth.filter
Event vs filter ![event-vs-filter](https://camo.githubusercontent.com/25f8943a0cd95d9aab19efafb6b2e95ee8dfb20f0cef2bc1f4f5dd3b32b64b38/68747470733a2f2f692e696d6775722e636f6d2f736231525662492e6a7067)