Git Product home page Git Product logo

smart-contract-practice's Introduction

Scrutinizer Code Quality Build StatusCode Intelligence Status codecov Travis_Build_Status

Deploy to Docker Cloud

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

Solidity data type 1

Solidity data type 2

Solidity data type 3

Solidity data type 4

Memory and storage data-location

Array in Solidity

avoid nested array Solidity note 1

static and dynamic array dynamic-static

Not allowed not-allowed

bytes and string are special arrays

bytes32 data; (~ byte[32] data ) bytes data (~ byte[] data ) String vss bytes string-vs-bytes

Functions

function

Function visibilities and modifier func-visibilities

Return multiple values func-return-multiple-values

To assign results from multiple returns function to variable, we use tupple tupple

Function overloading func-overloading

Constructor overloading is not supported

Variable initialization

Variables initialized to defaults at the beginning of functions variable-initialization

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:

global-var

Solidity global variable 1

Difference between msg.sender and tx.origin msg-sender-vs-tx-origin

Error handling in Solidity

No try-catch in Solidity

What happen if an exception is thrown

exception

Check and handle exception 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

difference-interface-abstrct-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

event

Contract design patterns

Contract destruction 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 mapping-itorator-pattern

Storage cost goes up

Cost of iteration goes up

Withdrawal pattern

Send vs transfer send-vs-transfer

Withdrawal pattern withdrawal-pattern

ERC-20 specification: 6 functions, 2 events

ERC-20

ERC-20-2

ERC-20-3

ERC-20-4

https://github.com/thanhnguyennguyen/ERC20-token

web3 knowledge

Send and Call

Send-vs-call

Filter object: web3.eth.filter

filter

Event vs filter event-vs-filter

smart-contract-practice's People

Contributors

thanhnguyennguyen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.