Share
Embed
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.
Samantha Geitz
March 06, 2019
Transcript
66 slides
-
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 -
So should I use a blockchain? Probably not (unless you're
trying to solve a very specific problem.) -
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? -
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 -
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 -
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 -
▸ 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 -
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.” -
So why would you use it? 3 real-world examples (And
one fake Laravel app) -
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 -
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" -
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 -
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 -
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' -
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) -
Ready for that game I mentioned earlier? This is your
2-minute warning! -
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) -
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! -
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 -
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 -
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) -
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 -
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 -
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 -
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 -
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 -
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 -
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. -
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 -
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 -
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 -
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! -
Truffle Framework ▸ Open-source Ethereum development framework ▸ Manage and
test your smart contracts ▸ Various "boxes" for quickstart with Vue, React, etc. -
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 -
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 -
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 -
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 -
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; } } -
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! -
Before we look at code... If you enjoyed my talk,
follow: @SamanthaGeitz @PolewskiEric @CoinpressCC