Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ITT 2019 - Martin Beeby - A Developer Primer on Blockchain

ITT 2019 - Martin Beeby - A Developer Primer on Blockchain

Come find out how developers can use Blockchain to build software. Understand through code how to create “smart contracts” and "chain code" and develop a different type of application that establishes trust, accountability and transparency, while streamlining business processes.

Istanbul Tech Talks

April 02, 2019
Tweet

More Decks by Istanbul Tech Talks

Other Decks in Technology

Transcript

  1. @ t h e b e e b s A

    Developer Primer on Blockchain Martin Beeby Principle Evangelist AWS
  2. @ t h e b e e b s M

    a r t i n B e e b y @ t h e b e e b s A software developer since I was 16 Developer for 20 years Work at Amazon Web Services MARTIN BEEBY @THEBEEBS
  3. @ t h e b e e b s M

    a r t i n B e e b y TERESA NUSRET DONALD @ t h e b e e b s THREE PEOPLE
  4. @ t h e b e e b s M

    a r t i n B e e b y @ t h e b e e b s ALL WORK IN AN OFFICE
  5. @ t h e b e e b s M

    a r t i n B e e b y @ t h e b e e b s NUSRET THE BAKER
  6. @ t h e b e e b s M

    a r t i n B e e b y TERESA NUSRET DONALD @ t h e b e e b s THEY BUY
  7. @ t h e b e e b s M

    a r t i n B e e b y TERESA NUSRET DONALD @ t h e b e e b s TERESA BUYS
  8. @ t h e b e e b s M

    a r t i n B e e b y TERESA NUSRET DONALD @ t h e b e e b s DONALD BUYS
  9. @ t h e b e e b s M

    a r t i n B e e b y TERESA NUSRET DONALD @ t h e b e e b s TERESA SELLS
  10. @ t h e b e e b s M

    a r t i n B e e b y TERESA NUSRET DONALD @ t h e b e e b s NUSRET ALSO BUYS
  11. @ t h e b e e b s M

    a r t i n B e e b y @ t h e b e e b s Handsome Smart Remote Worker NEW PERSON JOINS THE TEAM
  12. @ t h e b e e b s M

    a r t i n B e e b y @ t h e b e e b s MARTIN
  13. @ t h e b e e b s M

    a r t i n B e e b y @ t h e b e e b s Transferring Money between them is now harder Easy to lose track of who owes what Lets build a database MONEY IS A PAIN
  14. @ t h e b e e b s M

    a r t i n B e e b y @ t h e b e e b s Martin Controls it Each cake sale is a transaction The seller tells martin about the transaction. He records it CREATE A DATABASE
  15. @ t h e b e e b s M

    a r t i n B e e b y DONALD MARTIN @ t h e b e e b s TERESA NUSRET TRANSACTIONS
  16. @ t h e b e e b s M

    a r t i n B e e b y @ t h e b e e b s Trust Required (Fraud) Transparency Central Control WHAT’S THE PROBLEM?
  17. @ t h e b e e b s M

    a r t i n B e e b y @ t h e b e e b s Most Business run this way Big Databases are not a problem If there is Trust
  18. @ t h e b e e b s M

    a r t i n B e e b y @ t h e b e e b s MARTIN HAS A CAKE PROBLEM
  19. @ t h e b e e b s M

    a r t i n B e e b y DONALD MARTIN @ t h e b e e b s TERESA NUSRET DATABASE FOR EVERYONE
  20. @ t h e b e e b s M

    a r t i n B e e b y @ t h e b e e b s Hard to keep in sync Hard to agree Hard to reach consensus PEOPLE COULD STILL DEFRAUD
  21. @ t h e b e e b s M

    a r t i n B e e b y Blockchain builds trust in a network Eliminates the need for central authority in business networks Three main components: distributed ledger, consensus mechanism, and “smart contract” execution environment
  22. @ t h e b e e b s M

    a r t i n B e e b y Customers are experimenting in many industries Proof of Ownership Digital Security Trading Documents/Contracts Enterprise Platforms Financial Insurance Mortgage Loans Voting Mechanisms Patient Records Corporate Governance HCLS Real Estate Legal Agriculture Gaming M & E Transportation Digital Advertising Power/Utilities Retail Capital Markets Cloud OWNERSHIP PRIVATE MARKETS DERIVATIVES WAGERS GLOBAL PAYMENTS REMITTANCE NOTARISATION EQUITY MICROFINANCE INTELLECTUAL PROPERTY TITLE RECORD ESCROW DIGITAL RIGHTS E-COMMERCE DEBT CROWDFUNDING P2P LENDING HEALTHCARE VOTING TRUSTEES SMART CONTRACTS DIGITAL CURRENCY SECURITIES RECORD KEEPING BLOCKCHAIN TECHNOLOGY
  23. @ t h e b e e b s M

    a r t i n B e e b y DONALD MARTIN @ t h e b e e b s TERESA NUSRET PUBLIC AND PRIVATES OR CERTIFICATE Private Key Private Key Private Key Private Key Address 1 Address 2 Address 3 Address 6 Address 5
  24. @ t h e b e e b s M

    a r t i n B e e b y @ t h e b e e b s TRANSACTIONS Sender Amount Receiver Signed Address 1 5 Address 2 110101010 Address 2 4 Address 3 010101010 Address 3 3 Address 1 010011010
  25. @ t h e b e e b s M

    a r t i n B e e b y @ t h e b e e b s Listen for transactions and validates them Order transactions into a block Creates and hashes blocks PEERS LISTEN FOR TRANSACTIONS Sender Receiver Signed Address 1 5 Address 2 110101010 Address 2 4 Address 3 010101010 Address 3 3 Address 1 010011010
  26. @ t h e b e e b s M

    a r t i n B e e b y @ t h e b e e b s HASHING SHA256 446F09C5D7DB665A 851077054EBC7067 56E372A32C8753F0 428B6671CA6CE449 In west Philidelphia born and raised on the play ground was where I spent most of my days. Chilling 223E8E360399E82A C97B37A73FA1F532 071F03D8A174FA56 6D44F1770CC37D9A Istanbul
  27. @ t h e b e e b s M

    a r t i n B e e b y Suggest blocks to the network Other validating peers will verify the block. But how can they trust the new block? How do they reach consensus?
  28. @ t h e b e e b s M

    a r t i n B e e b y @ t h e b e e b s Solve a complex problem involving the hashing of the block Would be very expensive to try and present incorrect blocks Miners on bitcoin spend huge sums of money on electric PROOF OF WORK Jargon: A Consensus Algorithm
  29. @ t h e b e e b s M

    a r t i n B e e b y @ t h e b e e b s Proof of Stake Proof of Elapsed Time Byzantine fault tolerant OTHER CONSENSUS ALGORITHM
  30. @ t h e b e e b s M

    a r t i n B e e b y 80801 72456 80801 98994 A series of blocks that are hashed And linked by the hash of the previous block 80801 72456 34623
  31. @ t h e b e e b s M

    a r t i n B e e b y DONALD MARTIN @ t h e b e e b s TERESA NUSRET OTHER PEERS VERIFY
  32. @ t h e b e e b s M

    a r t i n B e e b y @ t h e b e e b s PEERS THEN BUILD ANOTHER
  33. @ t h e b e e b s M

    a r t i n B e e b y @ t h e b e e b s A list of transactions grouped into blocks Blocks chained together by knowing the previous hash Nothing can be easily altered, the slightest modification would be obvious A BLOCKCHAIN IS Jargon: Merkle Tree 80801 72456 80801 72456 34623
  34. @ t h e b e e b s M

    a r t i n B e e b y What Can A Developer Do? Smart Contracts (chaincode) and Build Distributed apps
  35. @ t h e b e e b s M

    a r t i n B e e b y Public and permissioned networks Public networks allow anyone to participate in the network. Members are incentivized to maintain the network Permissioned networks limit the members to known entities
  36. @ t h e b e e b s M

    a r t i n B e e b y Chaincode basics Code executed on the network, and can query and update ledger Fabric supports chaincode in three languages: Chaincode execute within a docker container on peer nodes Chaincode has two operations in its interface: • Init()—initializes the chaincode with parameters • Invoke()—invokes the chaincode with parameters
  37. @ t h e b e e b s M

    a r t i n B e e b y Peer nodes Ordering service blob3 blckNo tx1 tx2 Block forming blob1 Verify endorsement, readset If OK then apply writeset Else invalid transaction (blob) Genesis block Submitting client Peer Validated Ledger (VL) PeerLedger PeerLedger Validated Ledger block block seqNo=blckNo 3 4 seqNo blob1 blob2 Orders • Stores a copy of the ledger database • Executes chaincode and endorses transactions • Validates transactions before the final commit to ledger
  38. @ t h e b e e b s M

    a r t i n B e e b y Endorsement policies Endorsement policies allow chaincode to specify which members (or how many) need to validate a transaction before submitting Endorsed transactions then get submitted to the ordering service and assembled into blocks Member 1 client Hyperledger Fabric ordering service Ledger Ledger Member 2 Peer Member 1 Peer 1 3 2 1 3
  39. @ t h e b e e b s M

    a r t i n B e e b y @ t h e b e e b s From Sea to Table Lots of Fraud Could benefit from Transparency THE TUNA SUPPLY CHAIN
  40. @ t h e b e e b s M

    a r t i n B e e b y @ t h e b e e b s Sarah is the fisherman who sustainably and legally catches tuna. Regulators verify that the tuna has been legally/sustainably caught. Miriam is a restaurant owner who wants legal/sustainable tuna TUNA SUPPLY CHAIN Carl is another restaurant owner fisherman Sarah can sell tuna to.
  41. @ t h e b e e b s M

    a r t i n B e e b y @ t h e b e e b s Sarah sells at different prices Privacy around deals Carl shouldn’t see Miriams price DEALS NEED TO BE PRIVATE
  42. @ t h e b e e b s M

    a r t i n B e e b y
  43. @ t h e b e e b s M

    a r t i n B e e b y Channels for access control Channels allow isolation of transactions among specific members in the network Create or update a channel with configuration transaction (configtx) Member 1 Member 2 Member 3 Channel 2 Ledger Channel 1 Ledger Hyperledger Fabric ordering service Channel 2 Channel 1 Member 2 Peer Member 3 Peer Member 1 Peer
  44. @ t h e b e e b s M

    a r t i n B e e b y @ t h e b e e b s CHAINCODE package main import ( "fmt" "github.com/hyperledger/fabric/core/chaincode/shim" "github.com/hyperledger/fabric/protos/peer" )
  45. @ t h e b e e b s M

    a r t i n B e e b y @ t h e b e e b s TUNA STRUCT type Tuna struct { Vessel string ‘json:"vessel"’ Datetime string ‘json:"datetime"’ Location string ‘json:"location"’ Holder string ‘json:"holder"’ }
  46. @ t h e b e e b s M

    a r t i n B e e b y @ t h e b e e b s INIT func (s *SmartContract) initLedger(APIstub shim.ChaincodeStubInterface) sc.Response { tuna := []Tuna{ Tuna{Vessel: "923F", Location: "67.0006, -70.5476", Timestamp: "1504054225", Holder: "Miriam"}, Tuna{Vessel: "M83T", Location: "91.2395, -49.4594", Timestamp: "1504057825", Holder: "Dave"}, Tuna{Vessel: "T012", Location: "58.0148, 59.01391", Timestamp: "1493517025", Holder: "Igor"}, Tuna{Vessel: "P490", Location: "-45.0945, 0.7949", Timestamp: "1496105425", Holder: "Amalea"}, Tuna{Vessel: "S439", Location: "-107.6043, 19.5003", Timestamp: "1493512301", Holder: "Rafa"}, Tuna{Vessel: "J205", Location: "-155.2304, -15.8723", Timestamp: "1494117101", Holder: "Shen"}, Tuna{Vessel: "S22L", Location: "103.8842, 22.1277", Timestamp: "1496104301", Holder: "Leila"}, Tuna{Vessel: "EI89", Location: "-132.3207, -34.0983", Timestamp: "1485066691", Holder: "Yuan"}, Tuna{Vessel: "129R", Location: "153.0054, 12.6429", Timestamp: "1485153091", Holder: "Carlo"}, Tuna{Vessel: "49W4", Location: "51.9435, 8.2735", Timestamp: "1487745091", Holder: "Fatima"}, } i := 0 for i < len(tuna) { fmt.Println("i is ", i) tunaAsBytes, _ := json.Marshal(tuna[i]) APIstub.PutState(strconv.Itoa(i+1), tunaAsBytes) fmt.Println("Added", tuna[i]) i = i + 1 } return shim.Success(nil) }
  47. @ t h e b e e b s M

    a r t i n B e e b y
  48. @ t h e b e e b s M

    a r t i n B e e b y @ t h e b e e b s INVOKE func (s *SmartContract) Invoke(APIstub shim.ChaincodeStubInterface) sc.Response { // Retrieve the requested Smart Contract function and arguments function, args := APIstub.GetFunctionAndParameters() // Route to the appropriate handler function to interact with the ledger appropriately if function == "queryTuna" { return s.queryTuna(APIstub, args) } else if function == "initLedger" { return s.initLedger(APIstub) } else if function == "recordTuna" { return s.recordTuna(APIstub, args) } else if function == "queryAllTuna" { return s.queryAllTuna(APIstub) } else if function == "changeTunaHolder" { return s.changeTunaHolder(APIstub, args) } return shim.Error("Invalid Smart Contract function name.") }
  49. @ t h e b e e b s M

    a r t i n B e e b y @ t h e b e e b s QUERYTUNA func (s *SmartContract) queryTuna(APIstub shim.ChaincodeStubInterface, args []string) sc.Response { if len(args) != 1 { return shim.Error("Incorrect number of arguments. Expecting 1") } tunaAsBytes, _ := APIstub.GetState(args[0]) if tunaAsBytes == nil { return shim.Error(“Could not locate tuna”) } return shim.Success(tunaAsBytes) }
  50. @ t h e b e e b s M

    a r t i n B e e b y @ t h e b e e b s RECORDTUNA func (s *SmartContract) recordTuna(APIstub shim.ChaincodeStubInterface, args []string) sc.Response { if len(args) != 5 { return shim.Error("Incorrect number of arguments. Expecting 5") } var tuna = Tuna{ Vessel: args[1], Location: args[2], Timestamp: args[3], Holder: args[4]} tunaAsBytes, _ := json.Marshal(tuna) err := APIstub.PutState(args[0], tunaAsBytes) if err != nil { return shim.Error(fmt.Sprintf("Failed to record tuna catch: %s", args[0])) } return shim.Success(nil) }
  51. @ t h e b e e b s M

    a r t i n B e e b y @ t h e b e e b s CHANGETUNAHOLDER func (s *SmartContract) changeTunaHolder(APIstub shim.ChaincodeStubInterface, args []string) sc.Response { if len(args) != 2 { return shim.Error("Incorrect number of arguments. Expecting 2") } tunaAsBytes, _ := APIstub.GetState(args[0]) if tunaAsBytes != nil { return shim.Error("Could not locate tuna") } tuna := Tuna{} json.Unmarshal(tunaAsBytes, &tuna) // Normally check that the specified argument is a valid holder of tuna but here we are skipping this check for this example. tuna.Holder = args[1] tunaAsBytes, _ = json.Marshal(tuna) err := APIstub.PutState(args[0], tunaAsBytes) if err != nil { return shim.Error(fmt.Sprintf("Failed to change tuna holder: %s", args[0])) } return shim.Success(nil) }
  52. @ t h e b e e b s Install

    Chain Code from the CLI peer chaincode install –n tunachaincode –-v v0 -p src/chaincode_tuna/go
  53. @ t h e b e e b s Check

    Installed Chain Code from the CLI peer chaincode list --instantiated \ -o $ORDERER -C mychannel \ --cafile /opt/home/managedblockchain-tls-chain.pem –tls Name: tunachaincode Version: v0 Path: src/chaincode_tuna/go
  54. @ t h e b e e b s Invoke

    peer chaincode invoke -C mychannel \ -n tunachaincode -c '{"Args":["invoke",”queryTuna"]}' \ -o $ORDERER --cafile /opt/home/managedblockchain- tls-chain.pem --tls
  55. @ t h e b e e b s M

    a r t i n B e e b y
  56. @ t h e b e e b s M

    a r t i n B e e b y
  57. @ t h e b e e b s M

    a r t i n B e e b y @ t h e b e e b s CALLING SOME CODE // changeTunaHolder - requires 2 argument var request = { chaincodeId:’ tunachaincode’, fcn: 'changeTunaHolder', args: ['1', 'Alex'], chainId: 'mychannel', txId: tx_id }; return channel.sendTransactionProposal(request);
  58. @ t h e b e e b s M

    a r t i n B e e b y Need for a ledger with centralized trust DMV Track vehicle title history Manufacturers Track distribution of a recalled product HR & Payroll Track changes to an individual’s profile Healthcare Verify and track hospital equipment inventory LEDGERS WITH CENTRALIZED TRUST 1
  59. @ t h e b e e b s M

    a r t i n B e e b y Need for running transactions with decentralized trust 2 Financial institutions Peer-to-peer payments Mortgage lenders Process syndicated loans Supply Chain Transact with suppliers and distributers Retail Streamline customer rewards TRANSACTIONS WITH DECENTRALIZED TRUST
  60. @ t h e b e e b s M

    a r t i n B e e b y Blockchain services at AWS Amazon Quantum Ledger Database (QLDB) Amazon Managed Blockchain
  61. @ t h e b e e b s Amazon

    Quantum Ledger Database (QLDB) Fully managed ledger database with a central trusted authority
  62. @ t h e b e e b s M

    a r t i n B e e b y Challenges customers face Building Ledgers with traditional databases Difficult to manage and scale Impossible to verify Error prone and incomplete Resource intensive Blockchain approaches Designed for a different purpose Adds unnecessary complexity
  63. @ t h e b e e b s M

    a r t i n B e e b y Amazon Quantum Ledger Database (QLDB) (Preview) Fully managed ledger database Track and verify history of all changes made to your application’s data Maintains a sequenced record of all changes to your data, which cannot be deleted or modified; you have the ability to query and analyze the full history Immutable Uses cryptography to generate a secure output file of your data’s history Cryptographically verifiable Easy to use, letting you use familiar database capabilities like SQL APIs for querying the data Easy to use Highly scalable Executes 2–3X as many transactions as ledgers in common blockchain frameworks
  64. @ t h e b e e b s M

    a r t i n B e e b y Blockchain components: Distributed Ledger database The journal records an immutable log of all transactions and is maintained by nodes in the blockchain network Block 61 Block hash: 000044bf2efe32 Previous block hash: 000087ea2ffe94 Timestamp Transaction Transaction Block 61 Block hash: 000087ea2ffe94 Previous block hash: 000057ec2fda71 Timestamp Transaction Transaction Block 61 Block hash: 000057ec2fda71 Previous block hash: 0000d68b2f0a3b Timestamp Transaction Transaction
  65. @ t h e b e e b s M

    a r t i n B e e b y What is immutability? 1 Tracy buys a car on Aug 3, 2013 2 Tracy sells car to Ronnie on Sept 10, 2014 DMV QLDB database will add Ronnie’s record Journal Current state DMV scenario 3 Ronnie’s car gets in an accident and gets totaled DMV QLDB Database adds new row, called “delete” DELETE DATE: 09/02/2016 ID Manufacturer Model Year VIN Owner 1 Tesla Model S 2012 123456789 Traci Russell ID Manufacturer Model Year VIN Owner 1 Tesla Model S 2012 123456789 Ronnie Nash ID Manufacturer Model Year VIN Owner Built from ground-up in such a way that Journal cannot be modified or altered Entire change history is easily accessible DMV QLDB database will add Traci’s record
  66. @ t h e b e e b s M

    a r t i n B e e b y “Healthdirect Australia operates in a heavily regulated industry, and it is critical that our compliance data is correct and auditable. With Amazon QLDB we look forward to having a complete and verifiable history of every change in our system, making it simple to audit when and how we arrived at our current state. Regulatory compliance is fact of life for healthcare companies, and Amazon QLDB enables us to easily track the controls we have in place and understand how they have changed over time.” —Bruce Haefele General Manager, Technology, Healthdirect Australia
  67. @ t h e b e e b s Amazon

    Managed Blockchain Fully managed blockchain service, supporting both Hyperledger Fabric and Ethereum frameworks
  68. @ t h e b e e b s M

    a r t i n B e e b y Challenges with existing blockchain solutions Complicated to manage Setup is hard Hard to scale Expensive
  69. @ t h e b e e b s M

    a r t i n B e e b y Amazon Managed Blockchain Easily create and manage scalable blockchain networks Quickly create blockchain networks that span multiple AWS accounts. Easily add or remove members and monitor the network Fully managed Choice of Hyperledger Fabric or Ethereum Improves reliability Scalable and secure Easily scale your blockchain network as the usage grows. Also, Managed Blockchain secures your network certificates with KMS Choose the right framework for your needs, whether you are building a permissioned or public network Managed Blockchain improves the reliability of the “ordering service,” by replacing the default technology with QLDB. This improves durability
  70. @ t h e b e e b s M

    a r t i n B e e b y Hyperledger Fabric and Ethereum benefits Useful for a finite set of known users Well-suited for applications that require stringent privacy and permission controls with a known set of members For example, a financial application where certain trade-related data is only shared with select banks and other members in the network don’t have access to the data Hyperledger Fabric Useful for an infinite number of unknown users Well suited for highly distributed blockchain networks where transparency of data for all members is important For example, a digital identity network comprising of farmers and government organization, where an infinite number of farmers can join the network and information regarding their land, crop yields, etc., is shared across all members on the blockchain Ethereum
  71. @ t h e b e e b s M

    a r t i n B e e b y How Amazon Managed Blockchain works Amazon Managed Blockchain Create a network Choose an open source blockchain framework, set up a new blockchain network and your membership in your AWS account with just a few clicks Invite members Invite other AWS accounts to join the network Add nodes Create and configure blockchain peer nodes that store a copy of the distributed ledger Deploy applications Create and deploy decentralized applications to your network through your per nodes. Transact with other members on the network
  72. @ t h e b e e b s M

    a r t i n B e e b y “Given our vast partner ecosystem, we are exploring the decentralization and immutable tracking benefits of blockchain for potential applications in our insurance business. We believe blockchain can improve the transparency and efficiency for stakeholders in these networks to transact, while still maintaining an independently verifiable lineage of activities. However, blockchain frameworks are complex and difficult to operate. With Amazon Managed Blockchain, we can now easily create Hyperledger Fabric blockchain networks to test and learn without worrying about managing the underlying infrastructure, networking, and software configuration.” —Daniel Johnson CTO and Head of Innovation, Guardian Life Insurance Company
  73. @ t h e b e e b s M

    a r t i n B e e b y Summary: helping customers identify the right AWS blockchain service Owned by a single, trusted authority Addresses core need of a immutable and verifiable transactional log It’s a database, so its fast, as it doesn’t require consent from members Amazon QLDB Amazon Managed Blockchain No single owner of the ledger. Joint ownership by multiple parties Addresses core need of enabling multiple parties to transact transparently and with trust with each other Removes intermediaries when a group of members needs to transact. So it makes business processes more efficient Ownership Addresses Need Key Benefit
  74. @ t h e b e e b s M

    a r t i n B e e b y Next steps • Learn more about our services and sign up for our preview today! Amazon Managed Blockchain landing page: https://aws.amazon.com/managed- blockchain • How to deploy an app with Amazon Managed Blockchain : https://aws.amazon.com/blogs/database/tag/amazon-managed-blockchain/ • Amazon QLDB landing page: https://aws.amazon.com/qldb
  75. @ t h e b e e b s M

    a r t i n B e e b y Thank you! @ t h e b e e b s Martin Beeby @thebeebs