How to develop Decentralized
Apps on Ethereum
Thien Nguyen
About me
• Native name: Nguyễn Lê Quỳnh Thiện
• From: Vietnam
• Engineering Manager at NashTech
• Founder of SimplCommerce
• Microsoft MVP
• @thiennlq
Agenda
• Blockchain – Key points
• Ethereum – Introduction
• DApp – Environment development
• DApp – General architecture
• DApp – Demo building auction application
Bitcoin History
• “Bitcoin: A Peer-to-Peer Electronic Cash System” Nov, 2008 by Satoshi
Nakamoto https://bitcoin.org/bitcoin.pdf
• First implementation released in Jan 2009 by Satoshi Nakamoto
How bitcoin works
DB
Digital Signature
Hash Function
• Arbitrary input
• Same length output
• Unlikely that two inputs share
the same output
Merkle Trees (Hashes of hashes)
https://www.youtube.com/watch?v=-SMliFtoPn8
Blocks
Proof of Work
https://www.youtube.com/watch?v=bBC-nXj3Ng4
Blockchains
• Distributed (Everybody keep their own copy of the ledger)
• Transaction immutability achieved by way of blocks & chaining
• Leverages consensus mechanism for validating the transactions
• Uses cryptography for trust, accountability, security
• There is no single point of failure
Blockchain – Innovation Journey
https://www.youtube.com/watch?v=-SMliFtoPn8
Ethereum Accounts
• Has an address
• Controlled by a private key
• Has an address
• No private key
• Holds and run code
External Owned Account
Contract Account
Go Etherum Client
Geth
ÐΞVp2p [TCP, 30303]
> JS API Console
IPC-RPC
WS-RPC [8546]
JSON-RPC [HTTP, 8545]
Disabled by default
Disabled by default
Ethereum Networks
• Network Id = 1
• Morden: Network Id = 2 (retired)
• Ropsten: Network Id = 3
• Rinkerby: Network Id = 4
• Kovan: Network Id = 42
• Network Id = Assigned
Live Network
Testnet
Private Network
DEMO
Setup a private Ethereum network
https://github.com/devcafevn/ethereum-auction-app/tree/master/private-network
Using Ethereum Wallet and MetaMask
Ethereum Wallet MetaMask
You can install the MetaMask add-on in Chrome, Firefox,
Opera
https://github.com/ethereum/mist/releases
Denominations
Unit Wei Value Wei
wei 1 wei 1
Kwei (babbage) 1e3 wei 1,000
Mwei (lovelace) 1e6 wei 1,000,000
Gwei (shannon) 1e9 wei 1,000,000,000
microether (szabo) 1e12 wei 1,000,000,000,000
milliether (finney) 1e15 wei 1,000,000,000,000,000
ether 1e18 wei 1,000,000,000,000,000,000
GAS
• Gas is the unit in which EVM resource usage is measured
• Gas limit (start gas): max amount of gas you willing to spend
• Gas price: price of gas on ether you willing to pay. Miners decides the
minimal acceptable price
Transaction Fee = Gas used * Gas price
Gas used < Gas limit
=> Refund
Gas used > Gas limit
=> Out of gas exception, no change made
Remix - https://remix.ethereum.org
• Writing your first smart contract
pragma solidity ^0.4.0;
contract MyAccount {
uint private myBalance;
function MyAccount(uint _myBalance) public{
myBalance = _myBalance;
}
function getBalance() public constant returns(uint){
return myBalance;
}
function add(uint _amount) public returns(uint){
myBalance += _amount;
return myBalance;
}
}
DApp - General Architecture
Network
JSON-RPC / WS-RPC
DApp - General Architecture 2
Network
DB
Server
REST API
Demo
Online Auction Application
Online Auction App
• Everyone can send their bids to a
contract
• The highest current bid is visible
to every one
• At the end of the bidding period
• The highest bid is sent to the
beneficiary
• Other bidders can withdraw their
bids
Image source: https://kryptomoney.com/italian-auction-house-now-accepting-payments-
bitcoins/
Source code: https://github.com/devcafevn/ethereum-auction-app
References
• https://bitcoin.org/bitcoin.pdf
• https://www.ethereum.org/
• http://www.ethdocs.org/en/latest/
• https://solidity.readthedocs.io/en/v0.4.25/
• https://www.youtube.com/watch?v=bBC-nXj3Ng4
• https://www.youtube.com/watch?v=-SMliFtoPn8
• https://github.com/devcafevn/ethereum-auction-app
Thank you!

B4uConference_ethereum

  • 1.
    How to developDecentralized Apps on Ethereum Thien Nguyen
  • 2.
    About me • Nativename: Nguyễn Lê Quỳnh Thiện • From: Vietnam • Engineering Manager at NashTech • Founder of SimplCommerce • Microsoft MVP • @thiennlq
  • 3.
    Agenda • Blockchain –Key points • Ethereum – Introduction • DApp – Environment development • DApp – General architecture • DApp – Demo building auction application
  • 4.
    Bitcoin History • “Bitcoin:A Peer-to-Peer Electronic Cash System” Nov, 2008 by Satoshi Nakamoto https://bitcoin.org/bitcoin.pdf • First implementation released in Jan 2009 by Satoshi Nakamoto
  • 5.
  • 6.
  • 7.
    Hash Function • Arbitraryinput • Same length output • Unlikely that two inputs share the same output
  • 8.
    Merkle Trees (Hashesof hashes) https://www.youtube.com/watch?v=-SMliFtoPn8
  • 9.
  • 10.
  • 11.
    Blockchains • Distributed (Everybodykeep their own copy of the ledger) • Transaction immutability achieved by way of blocks & chaining • Leverages consensus mechanism for validating the transactions • Uses cryptography for trust, accountability, security • There is no single point of failure
  • 12.
  • 14.
  • 15.
    Ethereum Accounts • Hasan address • Controlled by a private key • Has an address • No private key • Holds and run code External Owned Account Contract Account
  • 16.
    Go Etherum Client Geth ÐΞVp2p[TCP, 30303] > JS API Console IPC-RPC WS-RPC [8546] JSON-RPC [HTTP, 8545] Disabled by default Disabled by default
  • 17.
    Ethereum Networks • NetworkId = 1 • Morden: Network Id = 2 (retired) • Ropsten: Network Id = 3 • Rinkerby: Network Id = 4 • Kovan: Network Id = 42 • Network Id = Assigned Live Network Testnet Private Network
  • 18.
    DEMO Setup a privateEthereum network https://github.com/devcafevn/ethereum-auction-app/tree/master/private-network
  • 19.
    Using Ethereum Walletand MetaMask Ethereum Wallet MetaMask You can install the MetaMask add-on in Chrome, Firefox, Opera https://github.com/ethereum/mist/releases
  • 20.
    Denominations Unit Wei ValueWei wei 1 wei 1 Kwei (babbage) 1e3 wei 1,000 Mwei (lovelace) 1e6 wei 1,000,000 Gwei (shannon) 1e9 wei 1,000,000,000 microether (szabo) 1e12 wei 1,000,000,000,000 milliether (finney) 1e15 wei 1,000,000,000,000,000 ether 1e18 wei 1,000,000,000,000,000,000
  • 21.
    GAS • Gas isthe unit in which EVM resource usage is measured • Gas limit (start gas): max amount of gas you willing to spend • Gas price: price of gas on ether you willing to pay. Miners decides the minimal acceptable price Transaction Fee = Gas used * Gas price Gas used < Gas limit => Refund Gas used > Gas limit => Out of gas exception, no change made
  • 22.
    Remix - https://remix.ethereum.org •Writing your first smart contract pragma solidity ^0.4.0; contract MyAccount { uint private myBalance; function MyAccount(uint _myBalance) public{ myBalance = _myBalance; } function getBalance() public constant returns(uint){ return myBalance; } function add(uint _amount) public returns(uint){ myBalance += _amount; return myBalance; } }
  • 23.
    DApp - GeneralArchitecture Network JSON-RPC / WS-RPC
  • 24.
    DApp - GeneralArchitecture 2 Network DB Server REST API
  • 25.
  • 26.
    Online Auction App •Everyone can send their bids to a contract • The highest current bid is visible to every one • At the end of the bidding period • The highest bid is sent to the beneficiary • Other bidders can withdraw their bids Image source: https://kryptomoney.com/italian-auction-house-now-accepting-payments- bitcoins/ Source code: https://github.com/devcafevn/ethereum-auction-app
  • 27.
    References • https://bitcoin.org/bitcoin.pdf • https://www.ethereum.org/ •http://www.ethdocs.org/en/latest/ • https://solidity.readthedocs.io/en/v0.4.25/ • https://www.youtube.com/watch?v=bBC-nXj3Ng4 • https://www.youtube.com/watch?v=-SMliFtoPn8 • https://github.com/devcafevn/ethereum-auction-app
  • 28.