SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais procurados

Ethereum in a nutshell
Ethereum in a nutshellEthereum in a nutshell
Ethereum in a nutshellDaniel Chan
 
DeFi - Decentralized Finance - Wallstreet Meets Blockchain
DeFi - Decentralized Finance - Wallstreet Meets BlockchainDeFi - Decentralized Finance - Wallstreet Meets Blockchain
DeFi - Decentralized Finance - Wallstreet Meets BlockchainThatCrypto
 
How To Become A Blockchain Engineer
How To Become A Blockchain EngineerHow To Become A Blockchain Engineer
How To Become A Blockchain Engineer101 Blockchains
 
Decentralised Exchanges - An Introduction
Decentralised Exchanges - An IntroductionDecentralised Exchanges - An Introduction
Decentralised Exchanges - An IntroductionPriyab Satoshi
 
Kafka Tutorial - DevOps, Admin and Ops
Kafka Tutorial - DevOps, Admin and OpsKafka Tutorial - DevOps, Admin and Ops
Kafka Tutorial - DevOps, Admin and OpsJean-Paul Azar
 
Programming smart contracts in solidity
Programming smart contracts in solidityProgramming smart contracts in solidity
Programming smart contracts in solidityEmanuel Mota
 
Open vSwitch와 Mininet을 이용한 가상 네트워크 생성과 OpenDaylight를 사용한 네트워크 제어실험
Open vSwitch와 Mininet을 이용한 가상 네트워크 생성과 OpenDaylight를 사용한 네트워크 제어실험Open vSwitch와 Mininet을 이용한 가상 네트워크 생성과 OpenDaylight를 사용한 네트워크 제어실험
Open vSwitch와 Mininet을 이용한 가상 네트워크 생성과 OpenDaylight를 사용한 네트워크 제어실험Seung-Hoon Baek
 
How to Avoid the Top 5 NGINX Configuration Mistakes
How to Avoid the Top 5 NGINX Configuration MistakesHow to Avoid the Top 5 NGINX Configuration Mistakes
How to Avoid the Top 5 NGINX Configuration MistakesNGINX, Inc.
 
Blockchain and DeFi: Overview
Blockchain and DeFi: OverviewBlockchain and DeFi: Overview
Blockchain and DeFi: OverviewSvetlin Nakov
 
List of 10 Most Expensive NFTs Ever Sold
List of 10 Most Expensive NFTs Ever SoldList of 10 Most Expensive NFTs Ever Sold
List of 10 Most Expensive NFTs Ever Sold101 Blockchains
 
What is NFT? | A Complete Use-Cases of Non-Fungible Token (NFT)
What is NFT? | A Complete Use-Cases of Non-Fungible Token (NFT)What is NFT? | A Complete Use-Cases of Non-Fungible Token (NFT)
What is NFT? | A Complete Use-Cases of Non-Fungible Token (NFT)Linda John
 
하이퍼레저 패브릭 실습자료
하이퍼레저 패브릭 실습자료하이퍼레저 패브릭 실습자료
하이퍼레저 패브릭 실습자료TIMEGATE
 
Understanding blockchain
Understanding blockchainUnderstanding blockchain
Understanding blockchainPriyab Satoshi
 

Mais procurados (20)

Ethereum in a nutshell
Ethereum in a nutshellEthereum in a nutshell
Ethereum in a nutshell
 
DeFi - Decentralized Finance - Wallstreet Meets Blockchain
DeFi - Decentralized Finance - Wallstreet Meets BlockchainDeFi - Decentralized Finance - Wallstreet Meets Blockchain
DeFi - Decentralized Finance - Wallstreet Meets Blockchain
 
How To Become A Blockchain Engineer
How To Become A Blockchain EngineerHow To Become A Blockchain Engineer
How To Become A Blockchain Engineer
 
Hyperledger Fabric
Hyperledger FabricHyperledger Fabric
Hyperledger Fabric
 
Decentralised Exchanges - An Introduction
Decentralised Exchanges - An IntroductionDecentralised Exchanges - An Introduction
Decentralised Exchanges - An Introduction
 
Top 5 DeFi Applications
Top 5 DeFi ApplicationsTop 5 DeFi Applications
Top 5 DeFi Applications
 
Kafka Tutorial - DevOps, Admin and Ops
Kafka Tutorial - DevOps, Admin and OpsKafka Tutorial - DevOps, Admin and Ops
Kafka Tutorial - DevOps, Admin and Ops
 
Programming smart contracts in solidity
Programming smart contracts in solidityProgramming smart contracts in solidity
Programming smart contracts in solidity
 
Open vSwitch와 Mininet을 이용한 가상 네트워크 생성과 OpenDaylight를 사용한 네트워크 제어실험
Open vSwitch와 Mininet을 이용한 가상 네트워크 생성과 OpenDaylight를 사용한 네트워크 제어실험Open vSwitch와 Mininet을 이용한 가상 네트워크 생성과 OpenDaylight를 사용한 네트워크 제어실험
Open vSwitch와 Mininet을 이용한 가상 네트워크 생성과 OpenDaylight를 사용한 네트워크 제어실험
 
All About Ethereum
All About EthereumAll About Ethereum
All About Ethereum
 
Ethereum 2.0
Ethereum 2.0Ethereum 2.0
Ethereum 2.0
 
How to Avoid the Top 5 NGINX Configuration Mistakes
How to Avoid the Top 5 NGINX Configuration MistakesHow to Avoid the Top 5 NGINX Configuration Mistakes
How to Avoid the Top 5 NGINX Configuration Mistakes
 
Blockchain and DeFi: Overview
Blockchain and DeFi: OverviewBlockchain and DeFi: Overview
Blockchain and DeFi: Overview
 
Blockchain Introduction
Blockchain IntroductionBlockchain Introduction
Blockchain Introduction
 
List of 10 Most Expensive NFTs Ever Sold
List of 10 Most Expensive NFTs Ever SoldList of 10 Most Expensive NFTs Ever Sold
List of 10 Most Expensive NFTs Ever Sold
 
How NFT Works
How NFT WorksHow NFT Works
How NFT Works
 
What is NFT? | A Complete Use-Cases of Non-Fungible Token (NFT)
What is NFT? | A Complete Use-Cases of Non-Fungible Token (NFT)What is NFT? | A Complete Use-Cases of Non-Fungible Token (NFT)
What is NFT? | A Complete Use-Cases of Non-Fungible Token (NFT)
 
하이퍼레저 패브릭 실습자료
하이퍼레저 패브릭 실습자료하이퍼레저 패브릭 실습자료
하이퍼레저 패브릭 실습자료
 
Blockchain concepts
Blockchain conceptsBlockchain concepts
Blockchain concepts
 
Understanding blockchain
Understanding blockchainUnderstanding blockchain
Understanding blockchain
 

Semelhante a 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
 
Functions in C++ programming language.pptx
Functions in  C++ programming language.pptxFunctions in  C++ programming language.pptx
Functions in C++ programming language.pptxrebin5725
 
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
 

Semelhante a 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
 
Functions in C++ programming language.pptx
Functions in  C++ programming language.pptxFunctions in  C++ programming language.pptx
Functions in C++ programming language.pptx
 
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
 

Mais de 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
 

Mais de 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
 

Último

Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 

Último (20)

Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 

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