Kindle Notes & Highlights
by
Siraj Raval
Read between
April 27 - April 30, 2018
Bitcoin and other cryptocurrencies will help define the fifth protocol layer of the Internet, letting machines transfer value as fast and efficiently as data.
consensus mechanism called proof-of-work which prevents double-spending in the network
with proof-of-work, they would also need to have the majority of computational power in the network to verify it.
Distributed means computation is spread across multiple nodes instead of just one. Decentralized means no node is instructing any other node as to what to do.
Bitcoin is distributed because its timestamped public ledger, the blockchain, resides on multiple computers. It’s also decentralized because if one node fails, the network is still able to operate.
Decentralized, closed-source applications require users to trust that the app is as decentralized as the core developers say it is, and that they don’t have access to their data through a central source.
How is any open-source dapp developer supposed to make money? The answer is to allocate scarce resources in the network using a scarce token: an appcoin. Users need this appcoin to use the network. Owners of scarce resources get paid in appcoins.
The blockchain’s innovation is decentralized consensus. If your app needs some feature that requires everyone else to agree on something, you should use a blockchain.
The blockchain is an immutable record that every node has a copy of, so no one can pretend that they too are @user. This can be done via the use of smart contracts.
A smart contract is a piece of code that lives in a blockchain. When a preprogrammed condition is triggered, the smart contract executes the corresponding contractual clause.
One big difference: smart contracts live on a blockchain, not a server. No third-party trust is required, and there is no need to trust Stripe or a server owner.
The blockchain helped solve the Byzantine Generals Problem. That problem asks the question, “How do you coordinate among distributed nodes to come up with some sort of consensus that is resistant to attackers trying to undermine it?” The proof-of-work algorithm and the blockchain help solve this.
proof-of-work is the only known Sybil-prevention system thus far.
In terms of up-and-coming competitors to proof-of-work, there is a big one that comes to mind: proof-of-stake. Proof-of-stake isn’t perfect, either, but it can complement proof-of-work.
Proof-of-stake is a consensus mechanism that relies instead on computational power to prevent Sybil attacks on stake in the network. Usually, by stake it means amount of cryptocurrency owned by the miner.
subdivide the space into three categories, following Melanie Swan’s book Blockchain (O’Reilly) and others; blockchain 1.0 is currency, blockchain 2.0 adds in contracts (stocks, bonds, financial assets), and blockchain 3.0 encompasses applications beyond pure finance in areas like governance and health (dapps).
four concepts in web applications that have traditionally been in the domain of centralized control: identity, wealth, data,
and computing.
First, we don’t just want the decentralized storage capabilities of a DHT and the speed of BitTorrent’s file transfer, we also want data permanence.
Second, we need to ensure that the links to the data don’t die.
To be more specific, it’s a directed, acyclic graph (DAG). A merkleDAG can look like a linked list or a tree. When adding data to the DHT, the system generates an SHA-256 multihash public-private key pair, and the user gets both.
All data on IPFS is public, so it’s the users’ responsibility to encrypt their data accordingly. The private keys, in addition to allowing access to the data, can prove ownership.
As soon as the coin appears to have enough value, the creators sell it all for a currency that is more stable and long-term like Bitcoin or fiat. This is a common scheme in the altcoin world, and it is terrible for the cryptocurrency ecosystem for obvious reasons. First of all, these coins tarnish the reputation of
cryptocurrency in general because they make potential investors increasingly wary of the space. Second, they compete with the Bitcoin blockchain for market share unnecessarily while bringing no real value to the table. This in turn harms Bitcoin’s value and all of those that rely on it as the most-used cryptocurrency.
Token agnosticism is a strong set of views, but I believe Bitcoin can cooperate with existing financial systems.
I’m willing to trust Coinbase more because it holds so many users’ assets, the CEO seems trustworthy to me (or at least much more so than Mark Karpelès of Mt Gox), and it is backed by a pair of trusted investors (Andreessen Horowitz and Union Square Ventures).
two options. The first is to store the data in IPFS and host your source code on a traditional virtual machine (VM) for web apps like Heroku.
A second way to deploy is by storing your users’ data on IPFS and deploying your source code to a decentralized VM built on top of IPFS. Does this exist? The closest project to achieving this is astralboot.
In the information economy where dapps are mainstream, each user of a dapp is also consequently a shareholder.
Centralized Architecture There are three paradigms that are commonplace when building a standard server-client–based web app. Let’s discuss them a bit. REST The server-client model is relatively simple and has become the de facto way to exchange data across the Web. REST, or Representational State Transfer, is a set of guidelines and best practices for creating scalable web apps usually based on the server-client model.
CRUD CRUD stands for Create-Read-Update-Delete. These are the
basic operations to be done in a data repository.
MVC MVC stands for Model-View-Controller, and it’s currently the most popular software programming paradigm.
what happens to CRUD and REST in a decentralized architecture? They become one and the same.
When you build your dapp, it won’t run on a server; rather,
it will run locally on all your users’ computers.
web browser or directly within a client interface — for example, Spotify or Skype. Dapps will require data storage in some form or another and as such they will double as IPFS-distributed file storage nodes.
incentivized by uploaders to store data by being paid in dollars or a cryptocurrency. IPFS creator Juan Benet published a paper for a currency called FileCoin to do just that, but work on it still hasn’t begun and thus cannot benefit us yet.
two key commands in IPFS: ADD Add data to IPFS CAT Read data from IPFS
add data to IPFS, you are essentially just broadcasting to the network that you have the data; you aren’t actually sending it to someone’s computer.
IPNS (the naming layer on top of IPFS) gives the appearance that updating and deleting are possible through mutable names. With IPNS you can publish a DAG of data under your immutable peer ID,
What about smart contracts? What role do they play? In a dapp, there are certain elements that need consensus via smart contracts that would usually require a server.
Smart contracts are technically “models,” and you can feed data into them via transactions, but they are not the de facto “model” in MVC architecture.
Setup Let’s set up our Go environment. I’m all about reducing complexity where it’s not necessary. Luckily, Go has package installers for Linux and Mac OS X. (Sorry, Windows users, we’re going to focus on Unix-based systems). The great thing about these package installers is that they will automatically install the Go distribution to usr/local/go and set our path variables. Path variables are one of those “gotchas” in software configuration. They link your libraries to Terminal keywords you can use to call them. If it didn’t set our path variables, we would have to set them ourselves, like so:
...more
on the Web. To install IPFS, type this into your console: go get -d github.com/ipfs/go-ipfs After installation, Source your bash: Source ~/.bashrc
To begin using IPFS, you need to initialize its config files on your system, as follows: 'ipfs init' This will take a few seconds; it’s adding bootstrapped (hardcoded) peers to your configuration and giving your node an identity key-pair to identify as a peer to the network when you add or pin a file.
That data still lives on your computer, but now there is a content address associated with it, and anyone who has that address can retrieve the file directly from your computer as long as you’re online.
Now that you’ve added some data to IPFS, let’s try CATing it back: ipfs cat <that hash> This should pull and display hello in the console. It’s pulling it directly from your computer.
The first snippet of code starts a node, so your dapp doubles as an IPFS client. It starts up the daemon, so you broadcast yourself as a peer to the network. The second snippet of code lets you add text to IPFS. You can add any kind of data to IPFS: video, images, data structures. But
The last snippet of text essentially performs an “ipfs cat” on the hash associated with your peerID (using IPNS) and stores it in an array for you to use and display in your view. You’ll also use a lightweight dependency called httprouter that helps making web apps easier.

