A Developer Primer on Blockchain

A Developer Primer on Blockchain

Come find out how you can build a peer-to-peer distributed ledger forged by consensus. Understand through code how to create “smart contracts” and develop a different type of transactional application that establishes trust, accountability and transparency, while streamlining business processes and legal constraints.

D7b395c3c1e55fecb5eefecc3c78c4fa?s=128

Martin Beeby

April 09, 2018
Tweet

Transcript

  1. Martin Beeby - @thebeebs PRIMER ON BLOCKCHAIN A DEVELOPER

  2. Martin Beeby @thebeebs Software developer Since I was 16 Joined

    Oracle 5 months ago MARTIN BEEBY
  3. Martin Beeby @thebeebs Tim Berners-Lee's At CERN Web Invented 0

    DAYS DECEMBER 20, 1990
  4. Martin Beeby @thebeebs 9950 DAYS 19 MARCH 2018

  5. Martin Beeby @thebeebs 10,000 DAYS 7 MAY 2018

  6. Martin Beeby @thebeebs CAR DAY 10,000

  7. Martin Beeby @thebeebs TV DAY 10,000

  8. Martin Beeby @thebeebs

  9. Martin Beeby @thebeebs ME DAY 10,000

  10. Martin Beeby @thebeebs BLOCKCHAIN IS DAY 3335

  11. Martin Beeby @thebeebs WHAT IS BLOCKCHAIN WHAT CAN A DEVELOPER

    DO HOW DO I DO IT
  12. Martin Beeby @thebeebs THREE PEOPLE CHRISTER EDWARD DONALD

  13. Martin Beeby @thebeebs ALL WORK IN AN OFFICE

  14. Martin Beeby @thebeebs CHRISTER THE BAKER

  15. Martin Beeby @thebeebs DONALD AND EDWARD BUY DONALD CHRISTER EDWARD

  16. Martin Beeby @thebeebs EDWARD BUYS DONALD CHRISTER EDWARD

  17. Martin Beeby @thebeebs DONALD BUYS DONALD CHRISTER EDWARD

  18. Martin Beeby @thebeebs SOMETMES EDWARD SELLS DONALD CHRISTER EDWARD

  19. Martin Beeby @thebeebs CHRISTER BUYS DONALD CHRISTER EDWARD

  20. Martin Beeby @thebeebs Handsome Smart Remote Worker NEW PERSON JOINS

    THE TEAM
  21. Martin Beeby @thebeebs MARTIN

  22. Martin Beeby @thebeebs Transferring Money between them is now harder

    Easy to lose track of who owes what Lets build a database MONEY IS A PAIN
  23. Martin Beeby @thebeebs Martin Controls it Each cake sale is

    a transaction The seller tells martin about the transaction. He records it CREATE A DATABASE
  24. Martin Beeby @thebeebs TRANSACTIONS DONALD MARTIN CHRISTER EDWARD

  25. Martin Beeby @thebeebs Trust Required (Fraud) Transparency Central Control WHAT’S

    THE PROBLEM?
  26. Martin Beeby @thebeebs MOST BUSINESS RUN THIS WAY BIG DATABASES

    ARE NOT A PROBLEM IF THERE IS TRUST
  27. Martin Beeby @thebeebs MARTIN HAS A CAKE PROBLEM

  28. Martin Beeby @thebeebs DATABASE FOR EVERYONE DONALD MARTIN CHRISTER EDWARD

  29. Martin Beeby @thebeebs Hard to keep in sync Hard to

    agree Hard to reach consensus PEOPLE COULD STILL DEFRAUD
  30. Martin Beeby @thebeebs BLOCKCHAIN

  31. Martin Beeby @thebeebs PUBLIC AND PRIVATES DONALD MARTIN Address 1

    Address 2 Address 3 Address 6 Address 5 Private Key Private Key Private Key Private Key CHRISTER EDWARD
  32. Martin Beeby @thebeebs Sender Amount Receiver Signed Address 1 5

    Address 2 110101010 Address 2 4 Address 3 010101010 Address 3 3 Address 1 010011010 TRANSACTIONS
  33. Martin Beeby @thebeebs Listen for transactions and validates them Order

    transactions into a block Creates and hashes blocks solving a maths problem related MINERS LISTEN FOR TRANSACTIONS Sender Receiver Signed Address 1 5 Address 2 110101010 Address 2 4 Address 3 010101010 Address 3 3 Address 1 010011010
  34. Martin Beeby @thebeebs 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
  35. Martin Beeby @thebeebs Proof of Stake Proof of Elapsed Time

    Byzantine fault tolerant OTHER CONSENSUS ALGORITHM
  36. Martin Beeby @thebeebs HASHING In west Philadelphia born and raised

    on the play ground was where I spent most of my days. Chilling 446F09C5D7DB665A 851077054EBC7067 56E372A32C8753F0 428B6671CA6CE449 In west Trondheim born and raised on the play ground was where I spent most of my days. Chilling 223E8E360399E82A C97B37A73FA1F532 071F03D8A174FA56 6D44F1770CC37D9A SHA256
  37. Martin Beeby @thebeebs

  38. Martin Beeby @thebeebs Previous Hash of the block All the

    transactions to create a block Hash the block to create a unique Hash that represents everything YOU CANT CHANGE A BLOCK
  39. Martin Beeby @thebeebs OTHER NODES VERIFY

  40. Martin Beeby @thebeebs MINERS THEN BUILD ANOTHER

  41. Martin Beeby @thebeebs A list of transactions grouped into blocks

    Blocks chained together by knowing the previous hash Nothing can be altered, the slightest modification would be obvious A BLOCK CHAIN IS Jargon: Merkle Tree
  42. Martin Beeby @thebeebs Smart Contracts Private Ledgers Build Apps WHAT

    CAN A DEVELOPER DO
  43. Martin Beeby @thebeebs SMART CONTRACTS

  44. Martin Beeby @thebeebs Christer decides to run an incentive. Every

    100th cake customer get a reward. Contract Int x AddAddress(address) x = x + 1; If (x =100){ address.transfer(reward) } A PSUEDO CONTRACT
  45. Martin Beeby @thebeebs A CONTRACT IS A TRANSACTION

  46. Martin Beeby @thebeebs EVERY CALL TO THE CONTRACT REQUIRES A

    TRANSACTION
  47. Martin Beeby @thebeebs MINERS EXECUTE THE PROGRAMS WHILST VERIFYING THE

    TRANSACTION
  48. Martin Beeby @thebeebs The contract code is visible on the

    blockchain It can’t be changed by anyone All the calls are public and everyone can see the cake competition is fair ITS TRANSPARENT
  49. Martin Beeby @thebeebs Bitcoin is great when you have zero

    trust in the nodes If you have no trust Proof of Work is a good compromise But the electricity cost is the compromise LEVELS OF TRUST
  50. Martin Beeby @thebeebs You have trust and want to have

    decentralised consensus You want to see all the transitions and have distributed consensus You want to add and remove members. ENTERPRISE TRUST ISSUES CAN BE DIFFERENT
  51. Martin Beeby @thebeebs https://www.hyperledger.org/members LINUX FOUNDATION

  52. Martin Beeby @thebeebs Private and Permissioned Membership Service Provider (MSP)

    Pluggable: MSP/Consensus/Ledger Format HYPERLEDGER FABRIC Channels
  53. Martin Beeby @thebeebs THE TUNA SUPPLY CHAIN From Sea to

    Table Lots of Fraud Could benefit from Transparency
  54. Martin Beeby @thebeebs TUNA SUPPLY CHAIN 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 Carl is another restaurant owner fisherman Sarah can sell tuna to.
  55. Martin Beeby @thebeebs Sarah sells at different prices Privacy around

    deals Carl shouldn’t see Miriams price DEALS NEED TO BE PRIVATE
  56. Martin Beeby @thebeebs

  57. Martin Beeby @thebeebs package main import ( "fmt" "github.com/hyperledger/fabric/core/chaincode/shim" "github.com/hyperledger/fabric/protos/peer"

    ) http://thebeebs.co.uk/blockchain CHAINCODE
  58. Martin Beeby @thebeebs type Tuna struct { Vessel string ‘json:"vessel"’

    Datetime string ‘json:"datetime"’ Location string ‘json:"location"’ Holder string ‘json:"holder"’ } TUNA STRUCT
  59. Martin Beeby @thebeebs 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) } INIT
  60. Martin Beeby @thebeebs

  61. Martin Beeby @thebeebs 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.") } INVOKE
  62. Martin Beeby @thebeebs 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) } QUERYTUNA
  63. Martin Beeby @thebeebs 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) }
  64. Martin Beeby @thebeebs 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) } CHANGETUNAHOLDER
  65. Martin Beeby @thebeebs

  66. Martin Beeby @thebeebs

  67. Martin Beeby @thebeebs CALLING SOME CODE // changeTunaHolder - requires

    2 argument var request = { chaincodeId:’tuna-app’, fcn: 'changeTunaHolder', args: ['1', 'Alex'], chainId: 'mychannel', txId: tx_id }; return channel.sendTransactionProposal(request);
  68. Martin Beeby @thebeebs THEBEEBS.UK/BLOCKCHAIN

  69. Martin Beeby @thebeebs WHY ORACLE?

  70. Martin Beeby @thebeebs It’s open It’s Flexible I would love

    your feedback WE HAVE A CLOUD
  71. Martin Beeby @thebeebs HTTP://THEBEEBS.UK/TRIAL $300

  72. Martin Beeby @thebeebs CONTACT MARTIN BEEBY @thebeebs https://www.thebeebs.co.uk martin.beeby@oracle.com