https://github.com/thanhnguyennguyen/smart-contract-practice
Practicing with smart contract and Ethereum network using solidity
https://github.com/thanhnguyennguyen/smart-contract-practice
blockchain blockchain-demos erc20 erc20-tokens ethereum-contract ethereum-dapp nguyennguyen smartcontract-dapp smartcontracts thanhnguyennguyen
Last synced: 26 days ago
JSON representation
Practicing with smart contract and Ethereum network using solidity
- Host: GitHub
- URL: https://github.com/thanhnguyennguyen/smart-contract-practice
- Owner: thanhnguyennguyen
- Created: 2018-06-10T15:32:04.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-03-02T01:47:34.000Z (over 2 years ago)
- Last Synced: 2025-07-30T16:21:13.300Z (3 months ago)
- Topics: blockchain, blockchain-demos, erc20, erc20-tokens, ethereum-contract, ethereum-dapp, nguyennguyen, smartcontract-dapp, smartcontracts, thanhnguyennguyen
- Language: JavaScript
- Size: 4.44 MB
- Stars: 9
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [](https://scrutinizer-ci.com/g/thanhnguyennguyen/smart-contract-practice/?branch=master) [](https://scrutinizer-ci.com/g/thanhnguyennguyen/smart-contract-practice/build-status/master)[](https://scrutinizer-ci.com/code-intelligence) [](https://codecov.io/gh/thanhnguyennguyen/smart-contract-practice) [](https://travis-ci.com/thanhnguyennguyen/smart-contract-practice)
# [](https://cloud.docker.com/stack/deploy/?repo=https://github.com/thanhnguyennguyen/smart-contract-practice/)
# Smart Contract practices
# Copyright © 2018 Nguyen Nguyen
# Please never write code without tests
## Lottery game
### Designs can be found here
https://github.com/thanhnguyennguyen/smart-contract-practice/tree/master/contracts/lottery/design
### Contract url
https://rinkeby.etherscan.io/address/0xa0a5566cb16c16384f3b7b3a3a67cbbe0bf2f137# Solidity basic knowledge
## Solidity data type
### 
### 
### 
### ## Memory and storage 
## Array in Solidity
### 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 
## Functions

### 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## Variable initialization
Variables initialized to defaults at the beginning of functions
## Mapping
### 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
## Global variable:

### 
### Difference between msg.sender and tx.origin ## Error handling in Solidity
### No try-catch in Solidity
### What happen if an exception is thrown

### Check and handle exception 
## OOP Support
No keyword *abstract contract*, function declared but no body provided. That class can not be deployed
### Inheritance: multiple inheritance is supported
### Polimorphism
### Overloading (except constructor)## Interface and abstract contract

to implement an interface, use keywork *is*, similar for extending abstract contract## Events and Logs
### Events are part of ABI definition
### Only indexed event arguments can be used in Filter, maximum 3 indices are allowed
## Contract design patterns
### Contract destruction 
#### Sending tracsaction to dead contract: fail
#### ALl fund send to dead contract will be lost
### Factory contract
### Name registry pattern
Using a registry Contract to manage all contracts, then using contract name to access instance of a particular contract
### Mapping iterator pattern
#### Use another array to keep keys 
#### Storage cost goes up
#### Cost of iteration goes up
### Withdrawal pattern
#### Send vs transfer 
#### Withdrawal pattern 
# ERC-20 specification: 6 functions, 2 events
## 
## 
## 
## https://github.com/thanhnguyennguyen/ERC20-token
# web3 knowledge
## Send and Call
### 
## Filter object: web3.eth.filter
### 
### Event vs filter 