Deploy a blockchain webapp with Hyperledger Fabric Horea
Deploy a blockchain web-app with Hyperledger Fabric Horea Porutiu Advisory Software Engineer, IBM July 2019 Blockchain Explained IBM Blockchain Platform Blockchain Solutions Blockchain Composed Blockchain Architected Blockchain Explored Next Steps
By a show of hands… ��� 1. Understands how blockchains work? � 2. Know what Hyperledger Fabric is? 3. Developed a smart contract? 4. Developed a dapp? 5. Deployed a network to production? 2
What you will learn 1. Blockchain vocabulary �� 3
What you will learn 1. Blockchain vocabulary �� 2. A use-case of blockchain � 4
What you will learn 1. Blockchain vocabulary �� 2. A use-case of blockchain � 3. Architecture behind a Hyperledger Fabric solution �� 5
What you will learn 1. Blockchain vocabulary �� 2. A use-case of blockchain � 3. Architecture behind a Hyperledger Fabric solution 4. Difference between the world state and the ledger �� �� 6
What you will learn 1. Blockchain vocabulary �� 2. A use-case of blockchain � �� 4. Difference between the world state and the ledger �� 5. Difference between public and private blockchains �� 3. Architecture behind a Hyperledger Fabric solution 7
What you will learn 1. Blockchain vocabulary �� 2. A use-case of blockchain � �� 4. Difference between the world state and the ledger �� 5. Difference between public and private blockchains �� 6. How a client application invokes a smart contract �� 3. Architecture behind a Hyperledger Fabric solution 8
Security: Public vs. private blockchains Public blockchains • Bitcoin • Users treated equally • Identity is anonymous 9
Security: Public vs. private blockchains Public blockchains • Bitcoin • Users treated equally • Identity is anonymous Private blockchains • Hyperledger Fabric, Quorum • Network members known, transactions can be secret 10
Security: Public vs. private blockchains Public blockchains • Bitcoin • Users treated equally • Identity is anonymous Private blockchains • Hyperledger Fabric, Quorum • Network members known, transactions can be secret • Identity management (anonymous vs. known) 11
Security: Public vs. private blockchains Public blockchains • Bitcoin • Users treated equally • Identity is anonymous Private blockchains • Hyperledger Fabric, Quorum • Network members known, transactions can be secret • Identity management (anonymous vs. known) • Most business use-cases require private, permissioned blockchains – Network members know who they’re dealing with (KYC) – Membership is controlled 12
A ledger often consists of two data structures • Blockchain block txn txn o A linked list of blocks o Each block describes a set of transactions (e. g. the inputs to a smart contract invocation) Blockchain o Immutable – blocks cannot be tampered 13
A ledger often consists of two data structures • Blockchain block txn txn o A linked list of blocks o Each block describes a set of transactions (e. g. the inputs to a smart contract invocation) Blockchain o Immutable – blocks cannot be tampered • World State o An ordinary database (e. g. key/value store) o Stores the combined outputs of all transactions World state o CAN delete 14
Block detail (simplified) … Block 15 Block 16 Block 17 Block Hash: 57 ec 2 fda 71 Block Hash: 87 ea 2 ffe 94 Block Hash: 44 bf 2 efe 32 Prev Block Hash: d 68 b 2 f 0 a 3 b Prev Block Hash: 57 ec 2 fda 71 Transaction Prev Block Hash: 87 ea 2 ffe 94 … Transaction - New blocks always added to the end 15
Block detail (simplified) … Block 15 Block 16 Block 17 Block Hash: 57 ec 2 fda 71 Block Hash: 87 ea 2 ffe 94 Block Hash: 44 bf 2 efe 32 Prev Block Hash: d 68 b 2 f 0 a 3 b Prev Block Hash: 57 ec 2 fda 71 Transaction Prev Block Hash: 87 ea 2 ffe 94 … Transaction - New blocks always added to the end - Each block header includes a hash of the current block transactions and the previous block’s transactions 16
What is Hyperledger Fabric • Platform for distributed ledger solutions �� 17
What is Hyperledger Fabric • Platform for distributed ledger solutions �� • Open Source – Contributions by hundreds of engineers from tens of organizations ������ �� 18
What is Hyperledger Fabric • Platform for distributed ledger solutions �� • Open Source – Contributions by hundreds of engineers from tens of organizations ������ �� • Features – Smart Contracts (updates the ledger) – Consensus (synch ledger across network) – Privacy (channels) �� 19
Actors in a blockchain solution R A Blockchain Architect Regulator B 2 B transactions. U performs oversight ü designs Blockchain Developer creates applications Blockchain Network Operator accesses security certificates Membership Services access to data Traditional operates O Blockchain User access to logic Data Sources Traditional Processing Platforms 20
The blockchain developer D Blockchain developers’ primary interests are… Application Blockchain Developer Smart Contract f(abc); 21
The blockchain developer D Blockchain developers’ primary interests are… Application Blockchain Developer Smart Contract f(abc); …and how they interact with the ledger and other systems of record: Ledger … Traditional Processing Platforms Traditional Data Sources Events ! Systems Integration 22
Components in a blockchain solution Ledger … List of transactions maintained by peers 23
Components in a blockchain solution Ledger Smart Contract … f(abc); List of transactions maintained by peers Software running on peer, updates the world state 24
Components in a blockchain solution Ledger Smart Contract Peer Network … f(abc); List of transactions maintained by peers Software running on peer, updates the world state Network which reaches consensus to add blocks 25
Components in a blockchain solution Ledger Smart Contract … f(abc); Peer Network Membership List of transactions maintained by peers Software running on peer, updates the world state Network which reaches consensus to add blocks E T Authenticates and manages identities on network 26
Components in a blockchain solution Ledger Smart Contract … f(abc); Peer Network Membership Events List of transactions maintained by peers Software running on peer, updates the world state Network which reaches consensus to add blocks T E ! Authenticates and manages identities on network Emits notifications of operations on network 27
Components in a blockchain solution Ledger Smart Contract … f(abc); Peer Network Membership Software running on peer, updates the world state Network which reaches consensus to add blocks T E ! Events Systems Management List of transactions maintained by peers i Authenticates and manages identities on network Emits notifications of operations on network Enables us to create/monitor blockchain components 28
Components in a blockchain solution Ledger Smart Contract … f(abc); Peer Network Membership Wallet Software running on peer, updates the world state Network which reaches consensus to add blocks T E ! Events Systems Management List of transactions maintained by peers i Authenticates and manages identities on network Emits notifications of operations on network Enables us to create/monitor blockchain components Securely manages a user’s credentials 29
Components in a blockchain solution Ledger Smart Contract … f(abc); Peer Network Membership Wallet Systems Integration Software running on peer, updates the world state Network which reaches consensus to add blocks T E ! Events Systems Management List of transactions maintained by peers i Authenticates and manages identities on network Emits notifications of operations on network Enables us to create/monitor blockchain components Securely manages a user’s credentials Integrate blockchain with eternal systems 30
Smart Contracts contain the business logic deployed to peers 31
Smart Contracts contain the business logic deployed to peers • Interact with the world state through the Fabric shim interface 32
Smart Contracts contain the business logic deployed to peers • Interact with the world state through the Fabric shim interface • Language support for: – Golang – Node. js – Java 33
Smart Contracts contain the business logic deployed to peers • Interact with the world state through the Fabric shim interface • Language support for: – Golang – Node. js – Java Admin Install Instantiate Invoke() Client SDK Application Peer Init() Smart Contract 34
Client Application Client applications use Fabric SDK to: • Connects over channels to peer and orderer nodes • Provide public / private keys Client Application Channels SDK �� ! Events 35
Client Application Client applications use Fabric SDK to: • Connects over channels to peer and orderer nodes • Provide public / private keys Client Application �� Connection Profile parameters to a Hyperledger Fabric network ! Events Local MSP • Network end-points and connection • The gateway to submit transactions Channels SDK Connection Profile • • Connection Parms Credential Store Channels Organisations Orderers Peers CAs 36
How applications interact with the ledger Blockchain developer D develops Client Application SDK submits Smart Contract emits ! event accesses ‘get’, ‘put’, ‘delete’ recorded Ledger block txn Peer World state txn emits ! event Blockchain 37
Sample blockchain use-case: e-voting 38
Components in an e-voting blockchain solution Ledger … The ledger containing history of submitted votes 39
Components in an e-voting blockchain solution Ledger Smart Contract … f(abc); The ledger containing history of submitted votes voter. Contract. Registers voters & submits votes 40
Components in an e-voting blockchain solution Ledger Smart Contract Peer Network … f(abc); The ledger containing history of submitted votes voter. Contract. Registers voters & submits votes The peers which run the voter. Contract 41
Components in an e-voting blockchain solution Ledger … Smart Contract f(abc); Peer Network Membership The ledger containing history of submitted votes voter. Contract. Registers voters & submits votes The peers which run the voter. Contract E T Public and private key for each registered voter 42
Components in an e-voting blockchain solution Ledger … Smart Contract f(abc); Peer Network Membership Events The ledger containing history of submitted votes voter. Contract. Registers voters & submits votes The peers which run the voter. Contract T E ! Public and private key for each registered voter Emit events to when a transaction is complete 43
Components in an e-voting blockchain solution Ledger … Smart Contract f(abc); Peer Network Membership voter. Contract. Registers voters & submits votes The peers which run the voter. Contract T E ! Events Systems Management The ledger containing history of submitted votes i Public and private key for each registered voter Emit events to when a transaction is complete VSCode extension to manage nodes & network 44
Components in an e-voting blockchain solution Ledger … Smart Contract f(abc); Peer Network Membership Wallet voter. Contract. Registers voters & submits votes The peers which run the voter. Contract T E ! Events Systems Management The ledger containing history of submitted votes i Public and private key for each registered voter Emit events to when a transaction is complete VSCode extension to manage nodes & network Stores our voter’s public/private keys and certs 45
Components in an e-voting blockchain solution Ledger … Smart Contract f(abc); Peer Network Membership voter. Contract. Registers voters & submits votes The peers which run the voter. Contract T E ! Events Systems Management The ledger containing history of submitted votes i Public and private key for each registered voter Emit events to when a transaction is complete VSCode extension to manage nodes & network Wallet Stores our voter’s public/private keys and certs Systems Integration An API to validate voter registration (DMV API) 46
App Architecture 47
Concepts and Components Considerations for the Developer, Operator and Architect
Working with the ledger example: a change of ownership transaction Transaction input - sent from application Application invoke(voter. Contract, cast. Vote, 2020 election, 123123123, democrat) Smart Contract f(abc); txn txn World state 49
Working with the ledger example: a change of ownership transaction Transaction input - sent from application Application invoke(voter. Contract, cast. Vote, 2020 election, 123123123, democrat) Smart contract implementation Smart Contract cast. Vote(ctx, args) { args. democrat. count++ } f(abc); txn txn World state 50
Working with the ledger example: a change of ownership transaction Transaction input - sent from application Application invoke(voter. Contract, cast. Vote, 2020 election, 123123123, democrat) Smart contract implementation Smart Contract cast. Vote(ctx, args) { args. democrat. count++ } f(abc); txn World state: new contents democrat. count = 1 voter. Id. cast. Ballot = true 51
Working with the ledger example: a change of ownership transaction Transaction input - sent from application Application invoke(voter. Contract, cast. Vote, 2020 election, 123123123, democrat) Smart contract implementation Smart Contract cast. Vote(ctx, args) { args. democrat. count++ } f(abc); Democrat. co unt = 1 World state txn txn World state: new contents democrat. count = 1 voter. Id. cast. Ballot = true 52
Working with the ledger example: a change of ownership transaction Transaction input - sent from application Application invoke(voter. Contract, cast. Vote, 2020 election, 123123123, democrat) Smart contract implementation Smart Contract f(abc); cast. Vote(ctx, args) { args. democrat. count++ } World state: new contents txn txn Democrat. co democrat. count = 1 voter. Id. cast. Ballot = true World state “Invoke, voter. Contract, cast. Vote, 2020 election, 123123123, democrat” 53
E-voting Demo 54
What we learned 1. Blockchain vocabulary �� 2. A use-case of blockchain � �� 4. Difference between the world state and the ledger �� 5. Difference between public and private blockchains �� 6. How a client application invokes a smart contract �� 3. Architecture behind a Hyperledger Fabric solution 55
Contact Questions⁉� : horea. porutiu@ibm. com Twitter: @horeaporutiu You. Tube�� : horeaporutiu 56
Rate today ’s session Session page on conference website O’Reilly Events App
- Slides: 58