SlideShare ist ein Scribd-Unternehmen logo
1 von 53
Training
nuuneoi
Agenda
• Introduction to Blockchain
• Introduction to Smart Contract Platform
• Smart Contract 101
• Coding with Solidity
• Deploy to Ethereum Network
• Work with Ethereum’s Smart Contract though web3
• Extras
Introduction to
Blockchain
nuuneoi
What is Blockchain? (Speedy Version)
“The Decentralized Database”
What is Blockchain? (Speedy Version)
“The Decentralized Database”
What is Blockchain? (Speedy Version)
“The Decentralized Database”
What is Blockchain? (Speedy Version)
“The Decentralized Database”
What is Blockchain? (Speedy Version)
“The Decentralized Database”
What is Blockchain? (Speedy Version)
“The Decentralized Database”
Introduction to
Smart Contract Platform
nuuneoi
What is Smart Contract Platform?
• Since Blockchain is the decentralized database. How about we let it keep the
“executable code” inside instead than just a simple transaction?
What is Smart Contract Platform?
• Everyone hold the same source code in the decentralized way.
How the code is executed?
• Same as the way transaction is made in Blockchain 1.0 we make a
transaction to call the code instead of making a money transferring tx.
• We call it “Blockchain 2.0”
What else Smart Contract could do?
• Store the variables (States)
• Transaction 1: a = 10
• Transaction 2: a = 20
Ethereum
nuuneoi
Ethereum Networks
Main Net
Network ID: 1
Consensus: PoW
Ropsten
Network ID: 3
Consensus: PoW
Client: Cross-Client
Rinkeby
Network ID: 4
Consensus: PoA
Client: Geth
Kovan
Network ID: 42
Consensus: PoA
Client: Parity
• Since the Ethereum is open sourced. There could be unlimited number of
networks out there and each of them are run separately.
Creating a Wallet
• Install MetaMask
• Chrome plugin
Faucet
• Get Ethereum for FREE! … (Sort of)
• https://faucet.kovan.network/ (Github account required)
Creating another Wallet
• Do it in MetaMask
Make the first transaction
• Let’s transfer some Ethereum from first account to the second one.
• Learn more a bit about Etherscan.
Smart Contract
Programming with
Solidity
nuuneoi
Ethereum Smart Contract
pragma solidity ^0.4.18;
contract SimpleContract {
uint balance;
constructor() public {
// Set initial balance as 1000
balance = 1000;
}
function setBalance(uint newBalance) public {
// Cap balance to be [0, 10000]
require(newBalance <= 10000);
// Set new balance
balance = newBalance;
}
function getBalance() public view returns(uint) {
return balance;
}
}
IDE: Remix
• https://remix.ethereum.org/
Solidity Helloworld
pragma solidity ^0.4.18;
contract SimpleContract {
uint balance;
constructor() public {
// Set initial balance as 1000
balance = 1000;
}
function setBalance(uint newBalance) public {
// Set new balance
balance = newBalance;
}
function getBalance() public view returns(uint) {
return balance;
}
}
Coding: Constructor
pragma solidity ^0.4.18;
contract SimpleContract {
uint balance;
constructor() public {
// Set initial balance as 1000
balance = 1000;
}
function setBalance(uint newBalance) public {
// Set new balance
balance = newBalance;
}
function getBalance() public view returns(uint) {
return balance;
}
}
constructor will be called
only once when deployed
Deploying
• Live Demo: Do it on remix
Working with Smart Contract through web3
• ABI
• BYTECODE
Working with Smart Contract through web3
• ABI
[ { "constant": false, "inputs": [ { "name": "newBalance", "type":
"uint256" } ], "name": "setBalance", "outputs": [], "payable": false,
"stateMutability": "nonpayable", "type": "function" }, { "inputs": [],
"payable": false, "stateMutability": "nonpayable", "type": "constructor" },
{ "constant": true, "inputs": [], "name": "getBalance", "outputs": [ {
"name": "", "type": "uint256" } ], "payable": false, "stateMutability":
"view", "type": "function" } ]
• BYTECODE
608060405234801561001057600080fd5b506103e860005560bf806100256000396000f3006
0806040526004361060485763ffffffff7c0100000000000000000000000000000000000000
00000000000000000060003504166312065fe08114604d578063fb1669ca146071575b60008
0fd5b348015605857600080fd5b50605f6088565b60408051918252519081900360200190f3
5b348015607c57600080fd5b506086600435608e565b005b60005490565b6000555600a1656
27a7a72305820cf77c0639acc98ef9acefd6386fe697d2d71d7478f3b9d459d8778557e3061
4a0029
Working with Smart Contract through web3
ABI
Working with Smart Contract through web3
• Live Coding: HTML + Javascript + jquery + web3.js + MetaMask
• Boilerplate: https://goo.gl/jychkY
Testing
$ npm install –g http-server
$ http-server .
Understand Gas Price
• See it on etherscan
Coding: Types
• Live Coding:
• bool
• int, uint, int8, uint8, int16, uint16, …, int256, uint256
• address
• fixed, ufixed
• byte, bytes
• string
• struct
• mapping
• enum
• []
Coding: Inheritance
• “is” contract A {
uint a;
function getA() public view returns(uint) {
return a;
}
}
contract B is A {
uint b;
function getBsumA() public view returns(uint) {
return b + a;
}
}
Coding: pure function
function func(uint x, uint y) public pure returns (uint) {
return x * (y + 42);
}
Coding: view function
uint a;
function func() public view returns (uint) {
return a;
}
Coding: pure & view function through read fn
uint a;
function func() public view returns (uint) {
return a;
}
Coding: pure & view function through read fn
uint a;
function func() public view returns (uint) {
return a;
}
function func2() public view returns (uint) {
return func();
}
Coding: pure & view function through write fn
uint a;
uint b;
function func() public view returns (uint) {
return a;
}
function func3(uint someVal) public returns (uint) {
b = someVal;
return func() + b;
}
Coding: require
function setBalance(uint newBalance) public {
// Check if newBalance is in [0, 10000]
require(newBalance <= 10000);
// Set new balance
balance = newBalance;
}
Coding: Visibility
• public – Can be either called internally or via messages.
• private – Only visible for the contract they are defined and
not in the derived contract.
• internal – Can only be accessed internally (i.e. from within
the current contract or contracts deriving from it)
• external - Can be called from other contracts and via
transactions. Cannot be called internally.
Coding: modifier
contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
function Ownable() public {
owner = msg.sender;
}
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
https://goo.gl/ZLThph
Coding: modifier
pragma solidity ^0.4.18;
contract SimpleContract is Ownable {
uint balance;
constructor() public {
// Set initial balance as 1000
balance = 1000;
}
function setBalance(uint newBalance) public onlyOwner {
// Set new balance
balance = newBalance;
}
function getBalance() public view returns(uint) {
return balance;
}
}
contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
function Ownable() public {
owner = msg.sender;
}
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
https://goo.gl/ZLThph
Coding: Events
pragma solidity ^0.4.18;
contract SimpleContract is Ownable {
event BalancedUpdated(uint balance);
uint balance;
constructor() public {
// Set initial balance as 1000
balance = 1000;
}
function setBalance(uint newBalance) public onlyOwner {
// Set new balance
balance = newBalance;
// Fire Event
emit BalanceUpdated(newBalance);
}
function getBalance() public view returns(uint) {
return balance;
}
}
Coding: Events
pragma solidity ^0.4.18;
contract SimpleContract is Ownable {
event BalancedUpdated(uint balance);
uint balance;
constructor() public {
// Set initial balance as 1000
balance = 1000;
}
function setBalance(uint newBalance) public onlyOwner {
// Set new balance
balance = newBalance;
// Fire Event
emit BalanceUpdated(newBalance);
}
function getBalance() public view returns(uint) {
return balance;
}
}
var event = SimpleContract.BalanceUpdated();
event.watch(function(error, result) {
// Will be called once there is new event emittted
});
Coding: payable
function register() public payable {
registeredAddresses[msg.sender] = true;
}
Redeploying
• Live Demo: See the difference [new contract address].
• Test the event.
Extras
nuuneoi
What is ERC-20?
// https://github.com/ethereum/EIPs/issues/20
interface ERC20Interface {
function totalSupply() public view returns (uint supply);
function balanceOf(address _owner) public view returns (uint balance);
function transfer(address _to, uint _value) public returns (bool success);
function transferFrom(address _from, address _to, uint _value) public returns (bool success);
function approve(address _spender, uint _value) public returns (bool success);
function allowance(address _owner, address _spender) public view returns (uint remaining);
function decimals() public view returns(uint digits);
event Approval(address indexed _owner, address indexed _spender, uint _value);
}
• ERC-20 is just a contract implemented the interface defined by ERC-20
standard.
Truffle: Solidity Framework
• Highly recommended
• Testable code
• Incremental deployment
• etc.
Store file on IPFS
• https://ipfs.io/
• Upload through Infura
Alternative Public Blockchain
• EOSIO: Smart Contract
• TomoChain: Smart Contract (Ethereum-Forked)
• NEM: Smart Contract
• Stellar: Payment (Non Turing Completed)
Create your own Smart Contract blockchain
• Hyperledger Fabric
• Use Golang to write Smart Contract

Weitere ähnliche Inhalte

Was ist angesagt?

FreeSWITCH Cluster by K8s
FreeSWITCH Cluster by K8sFreeSWITCH Cluster by K8s
FreeSWITCH Cluster by K8sChien Cheng Wu
 
Introduction to Corda Blockchain for Developers
Introduction to Corda Blockchain for DevelopersIntroduction to Corda Blockchain for Developers
Introduction to Corda Blockchain for DevelopersR3
 
Ethereum Solidity Fundamentals
Ethereum Solidity FundamentalsEthereum Solidity Fundamentals
Ethereum Solidity FundamentalsEno Bassey
 
Hexagonal architecture with Spring Boot
Hexagonal architecture with Spring BootHexagonal architecture with Spring Boot
Hexagonal architecture with Spring BootMikalai Alimenkou
 
Hyperledger Fabric in a Nutshell
Hyperledger Fabric in a NutshellHyperledger Fabric in a Nutshell
Hyperledger Fabric in a NutshellDaniel Chan
 
"Decentralized Finance (DeFi)" by Brendan Forster, Dharma | Fluidity 2019
"Decentralized Finance (DeFi)" by Brendan Forster, Dharma | Fluidity 2019"Decentralized Finance (DeFi)" by Brendan Forster, Dharma | Fluidity 2019
"Decentralized Finance (DeFi)" by Brendan Forster, Dharma | Fluidity 2019Fluidity
 
Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners HubSpot
 
Programming smart contracts in solidity
Programming smart contracts in solidityProgramming smart contracts in solidity
Programming smart contracts in solidityEmanuel Mota
 
Write Smart Contract with Solidity on Ethereum
Write Smart Contract with Solidity on EthereumWrite Smart Contract with Solidity on Ethereum
Write Smart Contract with Solidity on Ethereum劉 維仁
 
Beginner's guide to git and github
Beginner's guide to git and github Beginner's guide to git and github
Beginner's guide to git and github SahilSonar4
 
What is decentralized finance ( de fi )
What is decentralized finance ( de fi )What is decentralized finance ( de fi )
What is decentralized finance ( de fi )Celine George
 
Finally, easy integration testing with Testcontainers
Finally, easy integration testing with TestcontainersFinally, easy integration testing with Testcontainers
Finally, easy integration testing with TestcontainersRudy De Busscher
 
Git Lab Introduction
Git Lab IntroductionGit Lab Introduction
Git Lab IntroductionKrunal Doshi
 
Introduction To Solidity
Introduction To SolidityIntroduction To Solidity
Introduction To Solidity101 Blockchains
 
Introduction to GitHub Actions
Introduction to GitHub ActionsIntroduction to GitHub Actions
Introduction to GitHub ActionsBo-Yi Wu
 

Was ist angesagt? (20)

FreeSWITCH Cluster by K8s
FreeSWITCH Cluster by K8sFreeSWITCH Cluster by K8s
FreeSWITCH Cluster by K8s
 
Introduction to Corda Blockchain for Developers
Introduction to Corda Blockchain for DevelopersIntroduction to Corda Blockchain for Developers
Introduction to Corda Blockchain for Developers
 
Ethereum Solidity Fundamentals
Ethereum Solidity FundamentalsEthereum Solidity Fundamentals
Ethereum Solidity Fundamentals
 
Hexagonal architecture with Spring Boot
Hexagonal architecture with Spring BootHexagonal architecture with Spring Boot
Hexagonal architecture with Spring Boot
 
Hyperledger Fabric in a Nutshell
Hyperledger Fabric in a NutshellHyperledger Fabric in a Nutshell
Hyperledger Fabric in a Nutshell
 
"Decentralized Finance (DeFi)" by Brendan Forster, Dharma | Fluidity 2019
"Decentralized Finance (DeFi)" by Brendan Forster, Dharma | Fluidity 2019"Decentralized Finance (DeFi)" by Brendan Forster, Dharma | Fluidity 2019
"Decentralized Finance (DeFi)" by Brendan Forster, Dharma | Fluidity 2019
 
Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners
 
Programming smart contracts in solidity
Programming smart contracts in solidityProgramming smart contracts in solidity
Programming smart contracts in solidity
 
Write Smart Contract with Solidity on Ethereum
Write Smart Contract with Solidity on EthereumWrite Smart Contract with Solidity on Ethereum
Write Smart Contract with Solidity on Ethereum
 
Beginner's guide to git and github
Beginner's guide to git and github Beginner's guide to git and github
Beginner's guide to git and github
 
What is decentralized finance ( de fi )
What is decentralized finance ( de fi )What is decentralized finance ( de fi )
What is decentralized finance ( de fi )
 
Jenkins with SonarQube
Jenkins with SonarQubeJenkins with SonarQube
Jenkins with SonarQube
 
Jenkins CI presentation
Jenkins CI presentationJenkins CI presentation
Jenkins CI presentation
 
Finally, easy integration testing with Testcontainers
Finally, easy integration testing with TestcontainersFinally, easy integration testing with Testcontainers
Finally, easy integration testing with Testcontainers
 
Jenkins presentation
Jenkins presentationJenkins presentation
Jenkins presentation
 
Git Lab Introduction
Git Lab IntroductionGit Lab Introduction
Git Lab Introduction
 
Smart contract
Smart contractSmart contract
Smart contract
 
Introduction To Solidity
Introduction To SolidityIntroduction To Solidity
Introduction To Solidity
 
Introduction to GitHub Actions
Introduction to GitHub ActionsIntroduction to GitHub Actions
Introduction to GitHub Actions
 
Devops maturity model
Devops maturity modelDevops maturity model
Devops maturity model
 

Ähnlich wie Smart Contract programming 101 with Solidity #PizzaHackathon

Solidity Security and Best Coding Practices
Solidity Security and Best Coding PracticesSolidity Security and Best Coding Practices
Solidity Security and Best Coding PracticesGene Leybzon
 
Solidity Simple Tutorial EN
Solidity Simple Tutorial ENSolidity Simple Tutorial EN
Solidity Simple Tutorial ENNicholas Lin
 
Score (smart contract for icon)
Score (smart contract for icon) Score (smart contract for icon)
Score (smart contract for icon) Doyun Hwang
 
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
A GWT Application with MVP Pattern Deploying to CloudFoundry using  Spring Roo A GWT Application with MVP Pattern Deploying to CloudFoundry using  Spring Roo
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo Ali Parmaksiz
 
From object oriented to functional domain modeling
From object oriented to functional domain modelingFrom object oriented to functional domain modeling
From object oriented to functional domain modelingCodemotion
 
From object oriented to functional domain modeling
From object oriented to functional domain modelingFrom object oriented to functional domain modeling
From object oriented to functional domain modelingMario Fusco
 
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...GITS Indonesia
 
4Developers 2018: Evolution of C++ Class Design (Mariusz Łapiński)
4Developers 2018: Evolution of C++ Class Design (Mariusz Łapiński)4Developers 2018: Evolution of C++ Class Design (Mariusz Łapiński)
4Developers 2018: Evolution of C++ Class Design (Mariusz Łapiński)PROIDEA
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?Doug Hawkins
 
That’s My App - Running in Your Background - Draining Your Battery
That’s My App - Running in Your Background - Draining Your BatteryThat’s My App - Running in Your Background - Draining Your Battery
That’s My App - Running in Your Background - Draining Your BatteryMichael Galpin
 
From CRUD to messages: a true story
From CRUD to messages: a true storyFrom CRUD to messages: a true story
From CRUD to messages: a true storyAlessandro Melchiori
 
09 Application Design
09 Application Design09 Application Design
09 Application DesignRanjan Kumar
 
Durable functions 2.0 (2019-10-10)
Durable functions 2.0 (2019-10-10)Durable functions 2.0 (2019-10-10)
Durable functions 2.0 (2019-10-10)Paco de la Cruz
 
NHibernate Configuration Patterns
NHibernate Configuration PatternsNHibernate Configuration Patterns
NHibernate Configuration PatternsLuca Milan
 
“Create your own cryptocurrency in an hour” - Sandip Pandey
“Create your own cryptocurrency in an hour” - Sandip Pandey“Create your own cryptocurrency in an hour” - Sandip Pandey
“Create your own cryptocurrency in an hour” - Sandip PandeyEIT Digital Alumni
 

Ähnlich wie Smart Contract programming 101 with Solidity #PizzaHackathon (20)

Solidity Security and Best Coding Practices
Solidity Security and Best Coding PracticesSolidity Security and Best Coding Practices
Solidity Security and Best Coding Practices
 
Solidity Simple Tutorial EN
Solidity Simple Tutorial ENSolidity Simple Tutorial EN
Solidity Simple Tutorial EN
 
Score (smart contract for icon)
Score (smart contract for icon) Score (smart contract for icon)
Score (smart contract for icon)
 
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
A GWT Application with MVP Pattern Deploying to CloudFoundry using  Spring Roo A GWT Application with MVP Pattern Deploying to CloudFoundry using  Spring Roo
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
 
From object oriented to functional domain modeling
From object oriented to functional domain modelingFrom object oriented to functional domain modeling
From object oriented to functional domain modeling
 
From object oriented to functional domain modeling
From object oriented to functional domain modelingFrom object oriented to functional domain modeling
From object oriented to functional domain modeling
 
Dex and Uniswap
Dex and UniswapDex and Uniswap
Dex and Uniswap
 
Mvc 4
Mvc 4Mvc 4
Mvc 4
 
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...
 
4Developers 2018: Evolution of C++ Class Design (Mariusz Łapiński)
4Developers 2018: Evolution of C++ Class Design (Mariusz Łapiński)4Developers 2018: Evolution of C++ Class Design (Mariusz Łapiński)
4Developers 2018: Evolution of C++ Class Design (Mariusz Łapiński)
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?
 
Hems
HemsHems
Hems
 
Thread
ThreadThread
Thread
 
Textile
TextileTextile
Textile
 
That’s My App - Running in Your Background - Draining Your Battery
That’s My App - Running in Your Background - Draining Your BatteryThat’s My App - Running in Your Background - Draining Your Battery
That’s My App - Running in Your Background - Draining Your Battery
 
From CRUD to messages: a true story
From CRUD to messages: a true storyFrom CRUD to messages: a true story
From CRUD to messages: a true story
 
09 Application Design
09 Application Design09 Application Design
09 Application Design
 
Durable functions 2.0 (2019-10-10)
Durable functions 2.0 (2019-10-10)Durable functions 2.0 (2019-10-10)
Durable functions 2.0 (2019-10-10)
 
NHibernate Configuration Patterns
NHibernate Configuration PatternsNHibernate Configuration Patterns
NHibernate Configuration Patterns
 
“Create your own cryptocurrency in an hour” - Sandip Pandey
“Create your own cryptocurrency in an hour” - Sandip Pandey“Create your own cryptocurrency in an hour” - Sandip Pandey
“Create your own cryptocurrency in an hour” - Sandip Pandey
 

Mehr von Sittiphol Phanvilai

Firebase Dev Day Bangkok: Keynote
Firebase Dev Day Bangkok: KeynoteFirebase Dev Day Bangkok: Keynote
Firebase Dev Day Bangkok: KeynoteSittiphol Phanvilai
 
Introduction to Firebase [Google I/O Extended Bangkok 2016]
Introduction to Firebase [Google I/O Extended Bangkok 2016]Introduction to Firebase [Google I/O Extended Bangkok 2016]
Introduction to Firebase [Google I/O Extended Bangkok 2016]Sittiphol Phanvilai
 
What’s new in aNdroid [Google I/O Extended Bangkok 2016]
What’s new in aNdroid [Google I/O Extended Bangkok 2016]What’s new in aNdroid [Google I/O Extended Bangkok 2016]
What’s new in aNdroid [Google I/O Extended Bangkok 2016]Sittiphol Phanvilai
 
I/O Rewind 215: What's new in Android
I/O Rewind 215: What's new in AndroidI/O Rewind 215: What's new in Android
I/O Rewind 215: What's new in AndroidSittiphol Phanvilai
 
I/O Rewind 2015 : Android Design Support Library
I/O Rewind 2015 : Android Design Support LibraryI/O Rewind 2015 : Android Design Support Library
I/O Rewind 2015 : Android Design Support LibrarySittiphol Phanvilai
 
The way Tech World is heading to and how to survive in this fast moving world
The way Tech World is heading to and how to survive in this fast moving worldThe way Tech World is heading to and how to survive in this fast moving world
The way Tech World is heading to and how to survive in this fast moving worldSittiphol Phanvilai
 
Mobile Dev Talk #0 Keynote & Mobile Trend 2015
Mobile Dev Talk #0 Keynote & Mobile Trend 2015Mobile Dev Talk #0 Keynote & Mobile Trend 2015
Mobile Dev Talk #0 Keynote & Mobile Trend 2015Sittiphol Phanvilai
 
Mobile Market : Past Present Now and Then
Mobile Market : Past Present Now and ThenMobile Market : Past Present Now and Then
Mobile Market : Past Present Now and ThenSittiphol Phanvilai
 
How to deal with Fragmentation on Android
How to deal with Fragmentation on AndroidHow to deal with Fragmentation on Android
How to deal with Fragmentation on AndroidSittiphol Phanvilai
 
GTUG Bangkok 2011 Android Ecosystem Session
GTUG Bangkok 2011 Android Ecosystem SessionGTUG Bangkok 2011 Android Ecosystem Session
GTUG Bangkok 2011 Android Ecosystem SessionSittiphol Phanvilai
 

Mehr von Sittiphol Phanvilai (11)

Firebase Dev Day Bangkok: Keynote
Firebase Dev Day Bangkok: KeynoteFirebase Dev Day Bangkok: Keynote
Firebase Dev Day Bangkok: Keynote
 
Introduction to Firebase [Google I/O Extended Bangkok 2016]
Introduction to Firebase [Google I/O Extended Bangkok 2016]Introduction to Firebase [Google I/O Extended Bangkok 2016]
Introduction to Firebase [Google I/O Extended Bangkok 2016]
 
What’s new in aNdroid [Google I/O Extended Bangkok 2016]
What’s new in aNdroid [Google I/O Extended Bangkok 2016]What’s new in aNdroid [Google I/O Extended Bangkok 2016]
What’s new in aNdroid [Google I/O Extended Bangkok 2016]
 
I/O Rewind 215: What's new in Android
I/O Rewind 215: What's new in AndroidI/O Rewind 215: What's new in Android
I/O Rewind 215: What's new in Android
 
I/O Rewind 2015 : Android Design Support Library
I/O Rewind 2015 : Android Design Support LibraryI/O Rewind 2015 : Android Design Support Library
I/O Rewind 2015 : Android Design Support Library
 
The way Tech World is heading to and how to survive in this fast moving world
The way Tech World is heading to and how to survive in this fast moving worldThe way Tech World is heading to and how to survive in this fast moving world
The way Tech World is heading to and how to survive in this fast moving world
 
Mobile Dev Talk #0 Keynote & Mobile Trend 2015
Mobile Dev Talk #0 Keynote & Mobile Trend 2015Mobile Dev Talk #0 Keynote & Mobile Trend 2015
Mobile Dev Talk #0 Keynote & Mobile Trend 2015
 
Tech World 2015
Tech World 2015Tech World 2015
Tech World 2015
 
Mobile Market : Past Present Now and Then
Mobile Market : Past Present Now and ThenMobile Market : Past Present Now and Then
Mobile Market : Past Present Now and Then
 
How to deal with Fragmentation on Android
How to deal with Fragmentation on AndroidHow to deal with Fragmentation on Android
How to deal with Fragmentation on Android
 
GTUG Bangkok 2011 Android Ecosystem Session
GTUG Bangkok 2011 Android Ecosystem SessionGTUG Bangkok 2011 Android Ecosystem Session
GTUG Bangkok 2011 Android Ecosystem Session
 

Kürzlich hochgeladen

Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsJean Silva
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?Alexandre Beguel
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxRTS corp
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolsosttopstonverter
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonApplitools
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingShane Coughlan
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesVictoriaMetrics
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...OnePlan Solutions
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfRTS corp
 

Kürzlich hochgeladen (20)

Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero results
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration tools
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 Updates
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
 

Smart Contract programming 101 with Solidity #PizzaHackathon

  • 2. Agenda • Introduction to Blockchain • Introduction to Smart Contract Platform • Smart Contract 101 • Coding with Solidity • Deploy to Ethereum Network • Work with Ethereum’s Smart Contract though web3 • Extras
  • 4. What is Blockchain? (Speedy Version) “The Decentralized Database”
  • 5. What is Blockchain? (Speedy Version) “The Decentralized Database”
  • 6. What is Blockchain? (Speedy Version) “The Decentralized Database”
  • 7. What is Blockchain? (Speedy Version) “The Decentralized Database”
  • 8. What is Blockchain? (Speedy Version) “The Decentralized Database”
  • 9. What is Blockchain? (Speedy Version) “The Decentralized Database”
  • 10. Introduction to Smart Contract Platform nuuneoi
  • 11. What is Smart Contract Platform? • Since Blockchain is the decentralized database. How about we let it keep the “executable code” inside instead than just a simple transaction?
  • 12. What is Smart Contract Platform? • Everyone hold the same source code in the decentralized way.
  • 13. How the code is executed? • Same as the way transaction is made in Blockchain 1.0 we make a transaction to call the code instead of making a money transferring tx. • We call it “Blockchain 2.0”
  • 14. What else Smart Contract could do? • Store the variables (States) • Transaction 1: a = 10 • Transaction 2: a = 20
  • 16. Ethereum Networks Main Net Network ID: 1 Consensus: PoW Ropsten Network ID: 3 Consensus: PoW Client: Cross-Client Rinkeby Network ID: 4 Consensus: PoA Client: Geth Kovan Network ID: 42 Consensus: PoA Client: Parity • Since the Ethereum is open sourced. There could be unlimited number of networks out there and each of them are run separately.
  • 17. Creating a Wallet • Install MetaMask • Chrome plugin
  • 18. Faucet • Get Ethereum for FREE! … (Sort of) • https://faucet.kovan.network/ (Github account required)
  • 19. Creating another Wallet • Do it in MetaMask
  • 20. Make the first transaction • Let’s transfer some Ethereum from first account to the second one. • Learn more a bit about Etherscan.
  • 22. Ethereum Smart Contract pragma solidity ^0.4.18; contract SimpleContract { uint balance; constructor() public { // Set initial balance as 1000 balance = 1000; } function setBalance(uint newBalance) public { // Cap balance to be [0, 10000] require(newBalance <= 10000); // Set new balance balance = newBalance; } function getBalance() public view returns(uint) { return balance; } }
  • 24. Solidity Helloworld pragma solidity ^0.4.18; contract SimpleContract { uint balance; constructor() public { // Set initial balance as 1000 balance = 1000; } function setBalance(uint newBalance) public { // Set new balance balance = newBalance; } function getBalance() public view returns(uint) { return balance; } }
  • 25. Coding: Constructor pragma solidity ^0.4.18; contract SimpleContract { uint balance; constructor() public { // Set initial balance as 1000 balance = 1000; } function setBalance(uint newBalance) public { // Set new balance balance = newBalance; } function getBalance() public view returns(uint) { return balance; } } constructor will be called only once when deployed
  • 26. Deploying • Live Demo: Do it on remix
  • 27. Working with Smart Contract through web3 • ABI • BYTECODE
  • 28. Working with Smart Contract through web3 • ABI [ { "constant": false, "inputs": [ { "name": "newBalance", "type": "uint256" } ], "name": "setBalance", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "payable": false, "stateMutability": "nonpayable", "type": "constructor" }, { "constant": true, "inputs": [], "name": "getBalance", "outputs": [ { "name": "", "type": "uint256" } ], "payable": false, "stateMutability": "view", "type": "function" } ] • BYTECODE 608060405234801561001057600080fd5b506103e860005560bf806100256000396000f3006 0806040526004361060485763ffffffff7c0100000000000000000000000000000000000000 00000000000000000060003504166312065fe08114604d578063fb1669ca146071575b60008 0fd5b348015605857600080fd5b50605f6088565b60408051918252519081900360200190f3 5b348015607c57600080fd5b506086600435608e565b005b60005490565b6000555600a1656 27a7a72305820cf77c0639acc98ef9acefd6386fe697d2d71d7478f3b9d459d8778557e3061 4a0029
  • 29. Working with Smart Contract through web3 ABI
  • 30. Working with Smart Contract through web3 • Live Coding: HTML + Javascript + jquery + web3.js + MetaMask • Boilerplate: https://goo.gl/jychkY
  • 31. Testing $ npm install –g http-server $ http-server .
  • 32. Understand Gas Price • See it on etherscan
  • 33. Coding: Types • Live Coding: • bool • int, uint, int8, uint8, int16, uint16, …, int256, uint256 • address • fixed, ufixed • byte, bytes • string • struct • mapping • enum • []
  • 34. Coding: Inheritance • “is” contract A { uint a; function getA() public view returns(uint) { return a; } } contract B is A { uint b; function getBsumA() public view returns(uint) { return b + a; } }
  • 35. Coding: pure function function func(uint x, uint y) public pure returns (uint) { return x * (y + 42); }
  • 36. Coding: view function uint a; function func() public view returns (uint) { return a; }
  • 37. Coding: pure & view function through read fn uint a; function func() public view returns (uint) { return a; }
  • 38. Coding: pure & view function through read fn uint a; function func() public view returns (uint) { return a; } function func2() public view returns (uint) { return func(); }
  • 39. Coding: pure & view function through write fn uint a; uint b; function func() public view returns (uint) { return a; } function func3(uint someVal) public returns (uint) { b = someVal; return func() + b; }
  • 40. Coding: require function setBalance(uint newBalance) public { // Check if newBalance is in [0, 10000] require(newBalance <= 10000); // Set new balance balance = newBalance; }
  • 41. Coding: Visibility • public – Can be either called internally or via messages. • private – Only visible for the contract they are defined and not in the derived contract. • internal – Can only be accessed internally (i.e. from within the current contract or contracts deriving from it) • external - Can be called from other contracts and via transactions. Cannot be called internally.
  • 42. Coding: modifier contract Ownable { address public owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); function Ownable() public { owner = msg.sender; } modifier onlyOwner() { require(msg.sender == owner); _; } function transferOwnership(address newOwner) public onlyOwner { require(newOwner != address(0)); emit OwnershipTransferred(owner, newOwner); owner = newOwner; } } https://goo.gl/ZLThph
  • 43. Coding: modifier pragma solidity ^0.4.18; contract SimpleContract is Ownable { uint balance; constructor() public { // Set initial balance as 1000 balance = 1000; } function setBalance(uint newBalance) public onlyOwner { // Set new balance balance = newBalance; } function getBalance() public view returns(uint) { return balance; } } contract Ownable { address public owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); function Ownable() public { owner = msg.sender; } modifier onlyOwner() { require(msg.sender == owner); _; } function transferOwnership(address newOwner) public onlyOwner { require(newOwner != address(0)); emit OwnershipTransferred(owner, newOwner); owner = newOwner; } } https://goo.gl/ZLThph
  • 44. Coding: Events pragma solidity ^0.4.18; contract SimpleContract is Ownable { event BalancedUpdated(uint balance); uint balance; constructor() public { // Set initial balance as 1000 balance = 1000; } function setBalance(uint newBalance) public onlyOwner { // Set new balance balance = newBalance; // Fire Event emit BalanceUpdated(newBalance); } function getBalance() public view returns(uint) { return balance; } }
  • 45. Coding: Events pragma solidity ^0.4.18; contract SimpleContract is Ownable { event BalancedUpdated(uint balance); uint balance; constructor() public { // Set initial balance as 1000 balance = 1000; } function setBalance(uint newBalance) public onlyOwner { // Set new balance balance = newBalance; // Fire Event emit BalanceUpdated(newBalance); } function getBalance() public view returns(uint) { return balance; } } var event = SimpleContract.BalanceUpdated(); event.watch(function(error, result) { // Will be called once there is new event emittted });
  • 46. Coding: payable function register() public payable { registeredAddresses[msg.sender] = true; }
  • 47. Redeploying • Live Demo: See the difference [new contract address]. • Test the event.
  • 49. What is ERC-20? // https://github.com/ethereum/EIPs/issues/20 interface ERC20Interface { function totalSupply() public view returns (uint supply); function balanceOf(address _owner) public view returns (uint balance); function transfer(address _to, uint _value) public returns (bool success); function transferFrom(address _from, address _to, uint _value) public returns (bool success); function approve(address _spender, uint _value) public returns (bool success); function allowance(address _owner, address _spender) public view returns (uint remaining); function decimals() public view returns(uint digits); event Approval(address indexed _owner, address indexed _spender, uint _value); } • ERC-20 is just a contract implemented the interface defined by ERC-20 standard.
  • 50. Truffle: Solidity Framework • Highly recommended • Testable code • Incremental deployment • etc.
  • 51. Store file on IPFS • https://ipfs.io/ • Upload through Infura
  • 52. Alternative Public Blockchain • EOSIO: Smart Contract • TomoChain: Smart Contract (Ethereum-Forked) • NEM: Smart Contract • Stellar: Payment (Non Turing Completed)
  • 53. Create your own Smart Contract blockchain • Hyperledger Fabric • Use Golang to write Smart Contract