Introduction to
Ethereum Blockchain
Smart Contract
Thanh Nguyen
https://www.linkedin.com/in/nguyennhatthanh
1. BLOCKCHAIN OVERVIEW
§ 1.1. Key Tenets of Blockchain
§ 1.2. Smart Contracts
§ 1.3. Distributed Open Ledger
§ 1.4. Network Consensus
§ 1.5. Secured Transactions
§ 1.6. O2O Protocol: Decentralized Data Sharing | Sharing Economy
1.1. KEY TENETS OF BLOCKCHAIN
O2O PROTOCOL – BLOCKCHAIN SHARING ECONOMY 4/1/18 3
Distributed
Open
Ledger
Network
Consensus
Secured
Transactions
Smart
Contracts
Everyone in the network can see
the ledger and every node in
the network has a synchronized
copy of the Digital Ledger
No transaction can be added
without consensus from everyone
in the network. Special nodes,
called Miners, can validate and
add a transaction in a block &
add to the blockchain
Private-Public Key Cryptography
makes transactions are secure,
authenticated & verifiable
Business Logic (Rules)
embedded in Blockchain
that can be triggered when
certain conditions are met
1.2. SMART CONTRACTS
O2O PROTOCOL – BLOCKCHAIN SHARING ECONOMY 4/1/18 4
A computer program capable of facilitating, executing and enforcing
the negotiation or performance of an Agreement (Contract) using
Blockchain; the process is automated and can act as a substitute for
legal contacts.
What are
Smart
Contracts ?
Implication: future contracts will be on a hybrid paper-plus-code model where contracts
will be verified for authenticity via Blockchain and paper backups will be filed for traditional
recourse.
How They
Work
Use of Smart Contracts in Insurance industry: AXA’s Fizzy is Blockchain-based “parametric
insurance” product with automatic compensation.
Coding
Encryption
and
Broadcasting
Network
Consensus
Updating
Distributed
Ledger
Monitoring
Compliance
Example
1.3. DISTRIBUTED OPEN LEDGER
O2O PROTOCOL – BLOCKCHAIN SHARING ECONOMY 4/1/18 5
Centralized Body
(e.g. Bank)
Centralized
Ledger
£ Every node in the
decentralized
system has a copy of
the ledger
(blockchain)
£ No centralized
“official” copy exists
and no user is trusted
more than the other
£ Transactions are
broadcast to
network
£ Eliminates risk of
data stored centrally
Decentralized
Ledger
1.4. NETWORK CONSENSUS
O2O PROTOCOL – BLOCKCHAIN SHARING ECONOMY 4/1/18 6
Number of nodes required to validate a transaction depends on
the Distributed Ledger Technology being used :
¢ 1 for Open Chain
¢ Simple Majority for Juno
¢ Super Majority for Ripple
¢ All nodes for Casper
¢ Configurable for Stellar
Consensus Rules (Proof-of-Work.)
Consensus Mechanism is central to the functioning of Blockchain –
there is no need to “trust” a central authority
Addition of block to
the existing
Blockchain
Network
Consensus
Miner broadcasts
transition and nonce
value to the network
Miner Node validates
transaction and solves
Proof-of-Work
¢ Syntax validation
¢ Transaction validation
¢ Nonce validation
¢ Timestamp validation
¢ Block-size validation
¢ First transaction validation (Coinbase)
Validations for Consensus
1.5. SECURED TRANSACTIONS
O2O PROTOCOL – BLOCKCHAIN SHARING ECONOMY 4/1/18 7
Wallet &
Transaction
Security
Sender
Private Key
For signatures
Public Key
For addresses
Message
Key Generation
Encryption Algorithm
Public Key
Ciphertext
Receiver
Message
Public Key
• SHA256/SHA160 for crypto. hashing
• Base58/Base58Check encoding for
data compression
Blockchain
Security
Block # 1
Nonce - 16651
Coinbase - $100 -> Anders
Transactions:
NULL
Prev Txn – 000000….
Hash – 000043D….
Block # 2
Nonce - 37284
Coinbase - $100 -> John
Transactions:
$10 from Anders to Sophie
$5 from John to Sophie
Prev Txn – 000043D….
Hash – 0000A5A….
£ Every block identified by hash (SHA 256) value
with Coinbase, Transactions, Previous
transaction as inputs
£ All transactions hashed (Merkle root)
£ All these hashes are Base58 encoded
£ Nonce is a 32 bit field whose value is set so
that hash of a block has run of leading 0s
£ Any alteration in any block will make
subsequent blocks invalid
1.6. O2O PROTOCOL - BENEFITS & FEATURES
O2O PROTOCOL – BLOCKCHAIN SHARING ECONOMY 4/1/18 8
Cost Reduction
Increased Transparency and
without Intermediaries
Reduced Time
Secure Transaction Ledger
with no double spending
Smart
Contracts
Protocol
Schemas
Protocol Schemas support
hundreds of listing types,
including custom verticals
Smart Contracts enable secure
and reliable payments directly
from one party to another
Open &
Shared Data
Open & Shared Data
encourages innovation by
businesses and developers
Identity verification &
reputation data on the Blockchain
ensures safe, reputable partners
Data
2. BLOCKCHAIN ETHEREUM
Ethereum Smart Contract: Development & QA Services
ETHEREUM OVERVIEW
@2018 1/4/18 10
Email : Internet :: Bitcoin : Blockchain 2nd Generation Dapps
Key Tenets
1
Platform for any application building & hence
SCALABLE
2 DApps are JOINTLY OWNED
3
Smart Contract based & hence
NO CENSORSHIP, DOWNTIME, 3RD PARTY INTERFERENCE
4 Based on ETHERS & TOKENS
DEV-QA NEEDS FOR DAPP LIFECYCLE
@2018 1/4/18 11
Access testnet by changing config file
Connect to the Testnet using Ganache
Connect to testnet by selecting
appropriate option when prompted
RUN A NODE IN ETH
NETWORK
Install Ethereum Client
Install Ethereum Mist Wallet /
Metamask Browser Extension
WALLET CREATION,
SEND/RCV ETHER
JavaScript Console
Mist/Metamask Browser
JSON RPC API
CODE SMART
CONTRACTS
Use Solidity
Use LLL
Use Serpent
COMPILE SMART
CONTRACTS
SOLC Compiler
Browser-based Compilers
DEPLOY SMART
CONTRACTS
BUILD DAPPS
RUN & USE DAPPS
1
2
3
4
5
CALL SMART CONTRACTS
WITH APIs
7
Access using APIs
(Blockapps.net) & Browsers
(Metamask, Alrthzero)
Remix IDE, Truffle, Embark, Dapple,
Populus
Can claim ethers for testing
using Ethereum Faucet
Smart Contracts UT
UI Testing of Dapps
Validation of synchronization
Validation of Wallet integration
Validation of Ether
transaction from Wallet
Functional Testing
Non-Functional Testing
Validation of
Transaction from
BlockExplorer
ICO CROWD-SALE
API Testing
6
0 6A Coin Contracts UT
Security Testing
ERC20 Compliance Testing
LEGEND Low Dev-Testing Need Medium-grade Dev-Testing Need High-grade Testing Need
ETHEREUM QUALITY ASSURANCE
@2018 1/4/18 12
Peer Sync Validation
• Comparing the latest
block at the top of
ethstats.net with block
number output in client
node’s log
Unit Testing of Smart
Contracts
• TDD approach using Truffle /
Embark / Dapple / Populus
• UT of Smart Contracts
through other contracts,
including Token Contracts
Functional Testing
• Wallet Integration
• Wallet Interface
• DApp Business Rules
• DApp Workflows
• Cross-Browser/Device
Testing
Non-Functional Testing
• Performance Testing for txn.
throughput validation
• Security Testing – key-based signing &
token-based DApp access
• Usability & Accessibility Testing
Transaction Validation
• Leverage BlockExplorer for
ü Txn. Validation for
receiving/sending Ether
ü Txn. Validation of Smart
Contract deployment
ü Txn. Validation of Token
Contract
User Interface Testing
• Validation of UI aspects like color,
logo, resolution, labels etc.
• Validation of navigability aspects
Compliance Testing
• ERC20 guidelines compliance
API Testing
• DApp API calls for
internal Smart Contract
methods
• DApp API calls for
interfacing application
integration
Blockchain
Tools
ISVs &
Customers
Blockchain
Marketplace
ENTERPRISE-READY BLOCKCHAIN MIDDLEWARE
q The Blockchain Middleware will provide
core services, which will help users create
and build on top of Blockchains.
q Core Services can be broken down into :
Ø Identity and Certificate Services – helps
with authentication, authorization,
access, and lifecycle management.
Ø Encryption Services – provides encryption
for Blockchain transactions and fields
Ø Cryptlet Services – provides runtime for
cryptlets and communication between
blockchain and cryptlet trusted host
Ø Blockchain Gateway Services – provides
communication between multiple
blockchains
Ø Data Services – rich data services, such
as analytics, auditing, and machine
learning
Ø Management and Operations – tools for
deployment and management
@2018 1/4/18 13
POCs
HealthcareRetail &
CPG
GovernmentDiscrete
Manufacturing
Banking,
Capital
Markets
Distributed Ledger Stacks
Cloud
Horizontal SaaS & Adapters
3rd
Part
y
3rd
Party
3rd Party DL
Stack A
1st Party DL Stack
1st Party
3rd
Party
Blockchain Virtual Machine Adapters
Smart Contract-based UTXO + others
MiddlewareBasePlatform
3rd Party DL
Stack B
3rd Party DL
Stack C
….
.
IndustrySolutions
Blockchain Resource Provider
CryptoDelegate & Cryptlet architecture (secure containers, attestation)
Professional Services & Support
Identity &
Key
Services
Crypto
Services
ML & BI
Services
Distributed
Ledger
Gateway
Services
2.1. BLOCKCHAIN >> BITCOIN
FYI only
DEV-QA LANDSCAPE FOR BITCOIN
@2018 1/4/18 15
1
2
3
BitCoin Service Providers
ATMs Exchanges BTC
Wallets
POS
Cards Gateways Merchant
Portals
Escrow
Service
Mining Pools
User 1 User 2 User 3
SideChains
Bitcoin MainChain
TestNet
Dev-QA Landscape for Bitcoin
End
Consumer
ü
ü Area of interest
DEV-QA SERVICES FOR
BTC SERVICE PROVIDER TRANSACTIONS
@2018 1/4/18 16
End Customer Merchant BTC Service Provider Bitcoin Network Risk Analysis
Customer decides to
pay with Bitcoin
1 Payment Request API call
2
Response containing
address (QR code) &
txn details
4
Payment Response3
Bitcoin Payment5
Blockchain details6
Transaction validation request7
Transaction guarantee response 8
Payment Notification9
Payment Confirmation10
Payment Broadcast
Check Payment Status
Payment Status Response
U F
F
S
F S P
V
V
F
Direct to Bank Deposit
V
U Usability Testing F Functional Testing S Security Testing V Service Virtualization P Performance Testing A Automation Testing Services Testing
A
A A
Optional services like
GAP600 that scores and
guarantees bitcoin
transactions as they are
published on the network
@2018 1/4/18 17
TENETS OF OUR STRATEGY
AGILE: FAIL FAST & CHEAP
MIX & MATCH
CREATE & INNOVATE
SHARE SOLUTIONS
PROVISION
https://github.com/o2oprotocol/o2oprotocol
THANK YOU!

Introduction to Ethereum Blockchain & Smart Contract

  • 1.
    Introduction to Ethereum Blockchain SmartContract Thanh Nguyen https://www.linkedin.com/in/nguyennhatthanh
  • 2.
    1. BLOCKCHAIN OVERVIEW §1.1. Key Tenets of Blockchain § 1.2. Smart Contracts § 1.3. Distributed Open Ledger § 1.4. Network Consensus § 1.5. Secured Transactions § 1.6. O2O Protocol: Decentralized Data Sharing | Sharing Economy
  • 3.
    1.1. KEY TENETSOF BLOCKCHAIN O2O PROTOCOL – BLOCKCHAIN SHARING ECONOMY 4/1/18 3 Distributed Open Ledger Network Consensus Secured Transactions Smart Contracts Everyone in the network can see the ledger and every node in the network has a synchronized copy of the Digital Ledger No transaction can be added without consensus from everyone in the network. Special nodes, called Miners, can validate and add a transaction in a block & add to the blockchain Private-Public Key Cryptography makes transactions are secure, authenticated & verifiable Business Logic (Rules) embedded in Blockchain that can be triggered when certain conditions are met
  • 4.
    1.2. SMART CONTRACTS O2OPROTOCOL – BLOCKCHAIN SHARING ECONOMY 4/1/18 4 A computer program capable of facilitating, executing and enforcing the negotiation or performance of an Agreement (Contract) using Blockchain; the process is automated and can act as a substitute for legal contacts. What are Smart Contracts ? Implication: future contracts will be on a hybrid paper-plus-code model where contracts will be verified for authenticity via Blockchain and paper backups will be filed for traditional recourse. How They Work Use of Smart Contracts in Insurance industry: AXA’s Fizzy is Blockchain-based “parametric insurance” product with automatic compensation. Coding Encryption and Broadcasting Network Consensus Updating Distributed Ledger Monitoring Compliance Example
  • 5.
    1.3. DISTRIBUTED OPENLEDGER O2O PROTOCOL – BLOCKCHAIN SHARING ECONOMY 4/1/18 5 Centralized Body (e.g. Bank) Centralized Ledger £ Every node in the decentralized system has a copy of the ledger (blockchain) £ No centralized “official” copy exists and no user is trusted more than the other £ Transactions are broadcast to network £ Eliminates risk of data stored centrally Decentralized Ledger
  • 6.
    1.4. NETWORK CONSENSUS O2OPROTOCOL – BLOCKCHAIN SHARING ECONOMY 4/1/18 6 Number of nodes required to validate a transaction depends on the Distributed Ledger Technology being used : ¢ 1 for Open Chain ¢ Simple Majority for Juno ¢ Super Majority for Ripple ¢ All nodes for Casper ¢ Configurable for Stellar Consensus Rules (Proof-of-Work.) Consensus Mechanism is central to the functioning of Blockchain – there is no need to “trust” a central authority Addition of block to the existing Blockchain Network Consensus Miner broadcasts transition and nonce value to the network Miner Node validates transaction and solves Proof-of-Work ¢ Syntax validation ¢ Transaction validation ¢ Nonce validation ¢ Timestamp validation ¢ Block-size validation ¢ First transaction validation (Coinbase) Validations for Consensus
  • 7.
    1.5. SECURED TRANSACTIONS O2OPROTOCOL – BLOCKCHAIN SHARING ECONOMY 4/1/18 7 Wallet & Transaction Security Sender Private Key For signatures Public Key For addresses Message Key Generation Encryption Algorithm Public Key Ciphertext Receiver Message Public Key • SHA256/SHA160 for crypto. hashing • Base58/Base58Check encoding for data compression Blockchain Security Block # 1 Nonce - 16651 Coinbase - $100 -> Anders Transactions: NULL Prev Txn – 000000…. Hash – 000043D…. Block # 2 Nonce - 37284 Coinbase - $100 -> John Transactions: $10 from Anders to Sophie $5 from John to Sophie Prev Txn – 000043D…. Hash – 0000A5A…. £ Every block identified by hash (SHA 256) value with Coinbase, Transactions, Previous transaction as inputs £ All transactions hashed (Merkle root) £ All these hashes are Base58 encoded £ Nonce is a 32 bit field whose value is set so that hash of a block has run of leading 0s £ Any alteration in any block will make subsequent blocks invalid
  • 8.
    1.6. O2O PROTOCOL- BENEFITS & FEATURES O2O PROTOCOL – BLOCKCHAIN SHARING ECONOMY 4/1/18 8 Cost Reduction Increased Transparency and without Intermediaries Reduced Time Secure Transaction Ledger with no double spending Smart Contracts Protocol Schemas Protocol Schemas support hundreds of listing types, including custom verticals Smart Contracts enable secure and reliable payments directly from one party to another Open & Shared Data Open & Shared Data encourages innovation by businesses and developers Identity verification & reputation data on the Blockchain ensures safe, reputable partners Data
  • 9.
    2. BLOCKCHAIN ETHEREUM EthereumSmart Contract: Development & QA Services
  • 10.
    ETHEREUM OVERVIEW @2018 1/4/1810 Email : Internet :: Bitcoin : Blockchain 2nd Generation Dapps Key Tenets 1 Platform for any application building & hence SCALABLE 2 DApps are JOINTLY OWNED 3 Smart Contract based & hence NO CENSORSHIP, DOWNTIME, 3RD PARTY INTERFERENCE 4 Based on ETHERS & TOKENS
  • 11.
    DEV-QA NEEDS FORDAPP LIFECYCLE @2018 1/4/18 11 Access testnet by changing config file Connect to the Testnet using Ganache Connect to testnet by selecting appropriate option when prompted RUN A NODE IN ETH NETWORK Install Ethereum Client Install Ethereum Mist Wallet / Metamask Browser Extension WALLET CREATION, SEND/RCV ETHER JavaScript Console Mist/Metamask Browser JSON RPC API CODE SMART CONTRACTS Use Solidity Use LLL Use Serpent COMPILE SMART CONTRACTS SOLC Compiler Browser-based Compilers DEPLOY SMART CONTRACTS BUILD DAPPS RUN & USE DAPPS 1 2 3 4 5 CALL SMART CONTRACTS WITH APIs 7 Access using APIs (Blockapps.net) & Browsers (Metamask, Alrthzero) Remix IDE, Truffle, Embark, Dapple, Populus Can claim ethers for testing using Ethereum Faucet Smart Contracts UT UI Testing of Dapps Validation of synchronization Validation of Wallet integration Validation of Ether transaction from Wallet Functional Testing Non-Functional Testing Validation of Transaction from BlockExplorer ICO CROWD-SALE API Testing 6 0 6A Coin Contracts UT Security Testing ERC20 Compliance Testing LEGEND Low Dev-Testing Need Medium-grade Dev-Testing Need High-grade Testing Need
  • 12.
    ETHEREUM QUALITY ASSURANCE @20181/4/18 12 Peer Sync Validation • Comparing the latest block at the top of ethstats.net with block number output in client node’s log Unit Testing of Smart Contracts • TDD approach using Truffle / Embark / Dapple / Populus • UT of Smart Contracts through other contracts, including Token Contracts Functional Testing • Wallet Integration • Wallet Interface • DApp Business Rules • DApp Workflows • Cross-Browser/Device Testing Non-Functional Testing • Performance Testing for txn. throughput validation • Security Testing – key-based signing & token-based DApp access • Usability & Accessibility Testing Transaction Validation • Leverage BlockExplorer for ü Txn. Validation for receiving/sending Ether ü Txn. Validation of Smart Contract deployment ü Txn. Validation of Token Contract User Interface Testing • Validation of UI aspects like color, logo, resolution, labels etc. • Validation of navigability aspects Compliance Testing • ERC20 guidelines compliance API Testing • DApp API calls for internal Smart Contract methods • DApp API calls for interfacing application integration
  • 13.
    Blockchain Tools ISVs & Customers Blockchain Marketplace ENTERPRISE-READY BLOCKCHAINMIDDLEWARE q The Blockchain Middleware will provide core services, which will help users create and build on top of Blockchains. q Core Services can be broken down into : Ø Identity and Certificate Services – helps with authentication, authorization, access, and lifecycle management. Ø Encryption Services – provides encryption for Blockchain transactions and fields Ø Cryptlet Services – provides runtime for cryptlets and communication between blockchain and cryptlet trusted host Ø Blockchain Gateway Services – provides communication between multiple blockchains Ø Data Services – rich data services, such as analytics, auditing, and machine learning Ø Management and Operations – tools for deployment and management @2018 1/4/18 13 POCs HealthcareRetail & CPG GovernmentDiscrete Manufacturing Banking, Capital Markets Distributed Ledger Stacks Cloud Horizontal SaaS & Adapters 3rd Part y 3rd Party 3rd Party DL Stack A 1st Party DL Stack 1st Party 3rd Party Blockchain Virtual Machine Adapters Smart Contract-based UTXO + others MiddlewareBasePlatform 3rd Party DL Stack B 3rd Party DL Stack C …. . IndustrySolutions Blockchain Resource Provider CryptoDelegate & Cryptlet architecture (secure containers, attestation) Professional Services & Support Identity & Key Services Crypto Services ML & BI Services Distributed Ledger Gateway Services
  • 14.
    2.1. BLOCKCHAIN >>BITCOIN FYI only
  • 15.
    DEV-QA LANDSCAPE FORBITCOIN @2018 1/4/18 15 1 2 3 BitCoin Service Providers ATMs Exchanges BTC Wallets POS Cards Gateways Merchant Portals Escrow Service Mining Pools User 1 User 2 User 3 SideChains Bitcoin MainChain TestNet Dev-QA Landscape for Bitcoin End Consumer ü ü Area of interest
  • 16.
    DEV-QA SERVICES FOR BTCSERVICE PROVIDER TRANSACTIONS @2018 1/4/18 16 End Customer Merchant BTC Service Provider Bitcoin Network Risk Analysis Customer decides to pay with Bitcoin 1 Payment Request API call 2 Response containing address (QR code) & txn details 4 Payment Response3 Bitcoin Payment5 Blockchain details6 Transaction validation request7 Transaction guarantee response 8 Payment Notification9 Payment Confirmation10 Payment Broadcast Check Payment Status Payment Status Response U F F S F S P V V F Direct to Bank Deposit V U Usability Testing F Functional Testing S Security Testing V Service Virtualization P Performance Testing A Automation Testing Services Testing A A A Optional services like GAP600 that scores and guarantees bitcoin transactions as they are published on the network
  • 17.
    @2018 1/4/18 17 TENETSOF OUR STRATEGY AGILE: FAIL FAST & CHEAP MIX & MATCH CREATE & INNOVATE SHARE SOLUTIONS PROVISION
  • 18.