Laravel, the Blockchain, and You!

Laravel, the Blockchain, and You!

You've heard the buzz, but is blockchain a technology worth exploring? In this talk, I compare/contrast storing data on the blockchain with traditional MySQL databases, talk about some real-world companies using blockchain technology in production, and share some resources for adding blockchain to your web apps.

28661481fa442ed9bc5bef2b24766caf?s=128

Samantha Geitz

March 06, 2019
Tweet

Transcript

  1. Laravel, the Blockchain, and YOU

  2. None
  3. Things you know about blockchain technology (if you're anything like

    me 6 months ago) ▸ It's a buzzword that people are arguing about on Twitter/Reddit ▸ It has coins? Or something...? ▸ One of those coins is Bitcoin and I really wish I'd invested in it like 6 years ago when I first heard about it ▸ I have no idea if I can use it with Laravel apps
  4. (Spoiler alert: you can use it with Laravel apps)

  5. But should you?

  6. Some people:

  7. But then there's this:

  8. So should I use a blockchain? Probably not (unless you're

    trying to solve a very specific problem.)
  9. Stuff I'm going to talk at you about: 1) What

    is a blockchain/cryptocurrency? 2) How is it better/worse than a MySQL database? 3) When should you consider a blockchain for your app? 4) How do you get started with Laravel/Vue?
  10. But before we begin... Visit https://chat.laracon.net/c/speaker-questions Find the thread called

    "[Samantha Geitz] Blockchain Game" Have it open in the background — you'll need it in 15 minutes or so! I will name the winner the "Elitest of the Laravel Elites" on Twitter
  11. Let's talk about MySQL ▸ Single database, sitting behind a

    server, acting as the source of truth for all clients connecting to an app ▸ To write data, you either add a new value or update an existing one ▸ Anyone who has access to database can change data ▸ If database is deleted or server goes down, data is inaccessible ▸ Works kinda like an Excel spreadsheet
  12. None
  13. How is blockchain different? ▸ Blockchains are decentralized — a

    network is made up of various "nodes" (computers) with a copy of the entire database ▸ Apps can read data and add new records but not edit data ▸ To update data, new "blocks" of data are added to the chain to show how existing data should change
  14. ▸ Works more like a ledger with records written one

    after another in permanent ink, or a git repository with sequential commits ▸ If you try to edit/change/erase data in your blockchain, it will be different than everyone else's copy of the data history ▸ All nodes on network work together to ensure a consensus on data, which is highly secure
  15. None
  16. OK, what's the catch? ▸ Every time anything happens, every

    computer on the network needs to come to an agreement that it took place. Meaning: ▸ It's slooooooooooow ▸ It's comparatively very expensive ▸ "Roughly, a good heuristic to use is that you will not be able to do anything that you cannot do on a smartphone from 1999.”
  17. So why would you use it? 3 real-world examples (And

    one fake Laravel app)
  18. Bitcoin

  19. Problems being solved: ▸ With traditional currency, banks and/or governments

    have control over people's money ▸ Nothing to stop governments releasing an unlimited supply of money ▸ Credit card fraud / forged currency ▸ Risk of transactions being disputed/reversed
  20. How does it work? ▸ You want to send me

    a Bitcoin because you loved my talk ▸ Two ways to get Bitcoin: buying them on an exchange or "mining" them (which we will talk about later) ▸ Add your computer as a "node" to the network by downloading the Bitcoin software, including a copy of the entire history (150GB) ▸ This software is known as a "wallet"
  21. Is that a wallet in your pocket or are you

    just happy to see me ▸ Wallets do not technically store coins. They contain: ▸ Private key: large, secret, randomly-generated string unique to you. How you identify yourself — never share this with anyone! ▸ Public key: code created via algorithm from private key — how others can find you on the network
  22. How does it work? ▸ You enter my public key

    in your wallet and indicate you want to send me 1 bitcoin (thanks!!!) ▸ Your wallet tells the network that you want to send me a coin and "signs" the transaction info with your private key, creating a hash ▸ Transactions can be validated with your public key and the hash without ever revealing your private key
  23. Hashing in Laravel ▸ Your user signs up and enters

    "foobar" as a password ▸ You save it with Hash::make($password) ▸ It is stored in your DB as $2y$10$hEEF0lv4spxnvw5O4XyLZ.QjCE1tCu8HjM pWhmCS89J0EcSW0XELu ▸ Can check 'foobar' against hash; cannot decrypt hash into 'foobar'
  24. Adding data to blockchain ▸ Need a way to incentivize

    people to maintain the integrity of the network (which takes a lot of computing power) ▸ Solution: mining! ▸ Mining nodes validate "blocks" (groups of transactions) and add them to the blockchain ▸ Reward: bitcoins (currently, about $47,500 worth)
  25. Ready for that game I mentioned earlier? This is your

    2-minute warning!
  26. A quick guide to mining ▸ There is a small

    cost to putting a transaction on the network ▸ This is basically your bidding to put their transaction in the miner's solved block ▸ The network sends these groups of transactions as a hash created with a nonce (short for number used once)
  27. Game time!

  28. You are all miners I am thinking of a number

    between 1 and 200 The first person to guess it in the chat wins You have unlimited guesses. Go! Go! Go!
  29. A quick guide to mining ▸ Mining nodes guess random

    numbers as quickly as possible to figure out the correct 256-bit number ▸ The first miner to guess it is rewarded 12.5 bitcoins, plus the transaction fees. Everyone else loses. ▸ Verified transactions are added onto the blockchain as a new block ▸ More powerful hardware = better odds of guessing nonce
  30. What if you try to spend a coin twice? ▸

    Network has a globally-accepted order of transactions ▸ If two transactions contradict each other, the one that ends up being second will be rejected and cannot become part of a block
  31. OK, but why "mining?" ▸ Bitcoin protocol = max of

    21 million bitcoins will ever exit ▸ (This is expected to happen around 2140) ▸ New bitcoins are "dug up" as the network is maintained ▸ Currently, 12.5 BTC reward for successful mining ▸ This amount halves every 4 years or so (eventually will basically be only transaction fees)
  32. Bitcoin lets you send "money," but what about other data?

  33. Bitcoin vs. Ethereum ▸ Ethereum is another blockchain technology that

    allows you to easily build decentralized apps (Dapps) ▸ Has "smart contracts" that can store data / business logic and talk to each other ▸ Built in JavaScript
  34. Ethereum mining ▸ Similar to Bitcoin mining, except you mine

    "ether" ▸ Ether is "gas," or computational power used to add data to the blockchain ▸ When you send a transaction, you set max gas you are willing to pay ▸ Gas left over is refunded ▸ Possible to get partial credit for mining, unlike Bitcoin
  35. Microsoft Xbox

  36. Problems being solved: ▸ It is very difficult to figure

    out Xbox game publisher royalties ▸ Microsoft accountants have to deal with printed documentation and manual Excel spreadsheets to reconcile/recalculate royalty payments ▸ Different publishers / locales have different requirements ▸ It generally takes about 45 days for publishers to get their money
  37. Solution ▸ Smart contracts on a distributed blockchain ▸ Stakeholders

    can see how contract is set up and calculated ▸ Publishers get paid (and actionable data) almost immediately ▸ New system reduces transaction costs for publishers by 99% and cuts Microsoft's operating costs in half
  38. Webjet

  39. Problems being solved: ▸ I have a hotel room I

    want to rent out ▸ A travel agency, Expedia, Hotels.com, the hotel chain, and the receptionist at the front desk are all using different systems to book ▸ An estimated 5% of bookings are disputed ▸ This is a nightmare on both the accounts receivable and accounts payable ends
  40. Solution ▸ Webjet created Rezchain, an Ethereum blockchain to share

    booking data between all partners ▸ Not reliant on any one partner's infrastructure ▸ Disputes are fewer, and happen very near the time of the original transaction, not at the hotel or when losses are discovered
  41. Possible good uses for blockchain tech ▸ Voting app ▸

    DRM management of media/games ▸ Any app where the verifying the identity of participants is important: financial, legal, doctor writing a prescription, etc.
  42. Bad use cases for blockchain tech ▸ Most things ▸

    Data is in constant flux ▸ You want/need the ability to manually control the current state of data (remove/correct records) ▸ Speed/performance (need data in ms) is a priority
  43. Laravel Elites (A hypothetical v2)

  44. laravelelites.com ▸ The new de facto standard for hiring Laravel

    devs! ▸ Now with Github OAuth2 login via Socialite ▸ A few prominent people in the community can make people "Laravel Elite" via a certification process ▸ They have a secret API key and can add data to the database
  45. None
  46. !

  47. None
  48. None
  49. !

  50. But what if it was on the blockchain? ▸ If

    multiple people were running copies of the blockchain, they could see that I edited his info ▸ I'd have to stick to a good old-fashioned Twitter fight
  51. Developing blockchain applications: stuff to know

  52. web3.js ▸ Main JavaScript library for interacting with Ethereum ▸

    There are a few web3 PHP implementations as well; if you try them, let me know if they're good!
  53. Truffle Suite https://truffleframework.com

  54. Truffle Framework ▸ Open-source Ethereum development framework ▸ Manage and

    test your smart contracts ▸ Various "boxes" for quickstart with Vue, React, etc.
  55. Ganache ▸ Sets up a personal blockchain for local development

    ▸ Desktop app (via Electron/JS) or CLI tool ▸ Has built-in block explorer to see blocks/transactions
  56. Ganache

  57. Drizzle ▸ Collection of libraries built on top of Redux

    to synchronize contract and transaction data ▸ Not a lot of Vue tooling around Drizzle yet (although there are several Vue Truffle boxes) ▸ #teamreact
  58. MetaMask ▸ Web extension you can install via Chrome ▸

    Manage your Ethereum private keys via web browser ▸ Serves as a web wallet that lets you visit blockchain apps without running a full Ethereum node
  59. MetaMask

  60. Solidity ▸ Object-oriented, statically-typed language for implementing smart contracts ▸

    Truffle lets you "migrate" smart contracts, compiling them to JSON and storing them on the blockchain
  61. Solidity pragma solidity >=0.4.0 <0.6.0; contract SimpleStorage { uint storedData;

    function set(uint x) public { storedData = x; } function get() public view returns (uint) { return storedData; } }
  62. CoinPress ▸ (My shameless self-promotion slide) ▸ Side project I

    created with @PolewskiEric ▸ Create your own production Ethereum blockchain in seconds ▸ Free node hosting ▸ In active development; more coming soon!
  63. CoinPress https://coinpress.cc

  64. Before we look at code... If you enjoyed my talk,

    follow: @SamanthaGeitz @PolewskiEric @CoinpressCC
  65. Coming up next: @stauffermatt

  66. Let's look at some code!