The Blockchain Explained to Web Developers, Part 1: The Theory

The marmelab blog

The blockchain is the fresh hot technology. If you haven’t heard about it, you most likely know Bitcoin. Well, the blockchain is the underlying technology that powers Bitcoin. Experts say the blockchain will cause a revolution similar to what Internet provoked. But what is it truly, and how can it be used to build apps today? This post is the very first in a series of three, explaining the blockchain phenomenon to web developers. We’ll discuss the theory, showcase actual code, and share our learnings, based on a real world project.

To begin, let’s attempt to understand what blockchains indeed are.

What Is A Blockchain, Take One

Albeit the blockchain was created to support Bitcoin, the blockchain concept can be defined regardless of the Bitcoin ecosystem. The literature usually defines a blockchain as goes after:

A blockchain is a ledger of facts, replicated across several computers assembled in a peer-to-peer network. Facts can be anything from monetary transactions to content signature. Members of the network are anonymous individuals called knots. All communication inwards the network takes advantage of cryptography to securely identify the sender and the receiver. When a knot wants to add a fact to the ledger, a consensus forms in the network to determine where this fact should emerge in the ledger; this consensus is called a block.

I don’t know about you, but after reading these definitions, I still had troubles figuring out what this is all about. Let’s get a bit deeper.

Ordering Facts

Decentralized peer-to-peer networks aren’t fresh. Napster and BitTorrent are P2P networks. Instead of exchanging movies, members of the blockchain network exchange facts. Then what’s the real deal about blockchains?

P2P networks, like other distributed systems, have to solve a very difficult computer science problem: the resolution of conflicts, or reconciliation. Relational databases suggest referential integrity, but there is no such thing in distributed system. If two incompatible facts arrive at the same time, the system must have rules to determine which fact is considered valid.

Take for example the dual spend problem: Alice has Ten$, and she sends twice Ten$ to Bob and Charlie. Who will have the Ten$ eventually? To reaction this question, the best way is to order the facts. If two incompatible facts arrive in the network, the very first one to be recorded wins.

In a P2P network, two facts sent toughly at the same time may arrive in different orders in distant knots. Then how can the entire network agree on the very first fact? To assure integrity over a P2P network, you need a way to make everyone agree on the ordering of facts. You need a consensus system.

Consensus algorithms for distributed systems are a very active research field. You may have heard of Paxos or Raft algorithms. The blockchain implements another algorithm, the proof-of-work consensus, using blocks.

Blocks

Blocks are a wise trick to order facts in a network of non-trusted peers. The idea is ordinary: facts are grouped in blocks, and there is only a single chain of blocks, replicated in the entire network. Each block references the previous one. So if fact F is in block 21, and fact E is in block 22, then fact E is considered by the entire network to be posterior to fact F. Before being added to a block, facts are pending, i.e. unconfirmed.

Mining

Some knots in the chain create a fresh local block with pending facts. They challenge to see if their local block is going to become the next block in the chain for the entire network, by rolling dice. If a knot makes a dual six, then it earns the capability to publish their local block, and all facts in this block become confirmed. This block is sent to all other knots in the network. All knots check that the block is correct, add it to their copy of the chain, and attempt to build a fresh block with fresh pending facts.

But knots don’t just roll a duo dice. Blockchain challenges imply rolling a giant number of dice. Finding the random key to validate a block is very unlikely, by design. This prevents fraud, and makes the network safe (unless a malicious user wields more than half of the knots in the network). As a consequence, fresh blocks gets published to the chain at a immobilized time interval. In Bitcoin, blocks are published every ten minutes on average.

In Bitcoin, the challenge involves a dual SHA-256 hash of a string made of the pending facts, the identifier of the previous block, and a random string. A knot wins if their hash contains at least n leading zeroes.

Number n is adjusted every once in a while to keep block duration immovable despite variations in the number of knots. This number is called the difficulty. Other blockchain implementations use special hashing mechanisms that discourage the usage of GPUs (e.g. by requiring large memory transfers).

The process of looking for blocks is called mining. This is because, just like gold mining, block mining brings an economical prize – some form of money. That’s the reason why people who run knots in a blockchain are also called miners.

Note: By default, a knot doesn’t mine – it just receives blocks mined by other knots. It’s a voluntary process to turn a knot into a miner knot.

Money and Cryptocurrencies

Every 2nd, each miner knot in a blockchain tests thousands of random strings to attempt and form a fresh block. So running a miner in the blockchain pumps a big amount of computer resources (storage and CPU). That’s why you must pay to store facts in a blockchain. Reading facts, on the other arm, is free: you just need to run your own knot, and you’ll recuperate the entire history of facts issued by all the other knots. So to summarize:

  • Reading data is free
  • Adding facts costs a puny fee
  • Mining a block brings in the money of all the fees of the facts included in the block

We’re not talking about real money here. In fact, each blockchain has its own (crypto-)currency. It’s called Bitcoin (BTC) in the Bitcoin network, Ether (ETH) on the Ethereum network, etc. To make a payment in the Bitcoin network, you must pay a puny fee in Bitcoins – just like you would pay a fee to a bank. But then, where do the very first coins come from?

Miners receive a gratification for keeping the network working and safe. Each time they successfully mine a block, they receive a immobilized amount of cryptocurrency. In Bitcoin this gratification is twenty five BTC per block, in Ethereum it’s five ETH per block. That way, the blockchain generates its own money.

Lastly, cryptocurrencies rapidly became convertible to real money. Their facial value is only determined by suggest and request, so it’s subject to speculation. At the time of writing, mining Bitcoins still costs slightly less in energy and hardware than you can earn by selling the coins you discovered in the process. That’s why people add fresh miners every day, hoping to turn electric current into money. But fluctuations in the BTC value make it less and less profitable.

Contracts

So far we’ve mostly mentioned facts storage, but a blockchain can also execute programs. Some blockchains permit each fact to contain a mini program. Such programs are replicated together with the facts, and every knot executes them when receiving the facts. In bitcoin, this can be used to make a transaction conditional: Bob will receive one hundred BTC from Alice if and only if today is February 29th.

Other blockchains permit for more sophisticated contracts. In Ethereum for example, each contract carries a mini-database, and exposes methods to modify the data. As contracts are replicated across all knots, so are their database. Each time a user calls a method on the contract and therefore updates the underlying data, this instruction is replicated and replayed by the entire network. This permits for a distributed consensus on the execution of a promise.

This idea of pre-programed conditions, interfaced with the real world, and broadcasted to everyone, is called a brainy contract. A contract is a promise that signing parties agree to make legally-enforceable. A brainy contract is the same, except with the word “technically-“ instead of “legally-“. This liquidates the need for a judge, or any authority acknowledged by both parties.

Imagine that you want to rent your house for a week and $1,000, with a 50% upfront payment. You and the loaner sign a contract, very likely written by a lawyer. You also need a bank to receive the payment. At the beginning of the week, you ask for a $Five,000 deposit; the loaner writes a check for it. At the end of the week, the loaner denies to pay the remaining 50%. You also realize that they broke a window, and that the deposit check refers to an empty account. You’ll need a lawyer to help you enforce the rental contract in a court.

Brainy contracts in a blockchain permit you to get rid of the bank, the lawyer, and the court. Just write a program that defines how much money should be transferred in response to certain conditions:

  • two weeks before beginning of rental: transfer $500 from loaner to possessor
  • cancellation by the holder: transfer $500 from proprietor to loaner
  • end of the rental period: transfer $500 from loaner to holder
  • proof of physical degradation after the rental period: transfer $Five,000 from loaner to holder

Upload this brainy contract to the blockchain, and you’re all set. At the time defined in the contract, the money transfers will occur. And if the proprietor can bring a predefined proof of physical degradation, they get the $Five,000 automatically (without any need for a deposit).

You might wonder how to build a proof of physical degradation. That’s where the Internet of Things (IoT) kicks in. In order to interact with the real world, blockchains need sensors and actuators. The Blockchain revolution won’t happen unless the IoT revolution comes very first.

Such applications relying on wise contracts are called Decentralized Apps, or DApps.

Brainy contracts naturally extend to clever property, and a lot more wise things. The thing to recall is that “smart” means “no intermediaries”, or “technically-enforced”. Blockchains are a fresh way to disintermediate businesses – just like the Internet disintermediated music distribution.

What Is A Blockchain, Take Two

In my opinion, the best way to understand the blockchain is to look at it from various angles.

What it does A blockchain permits to securely share and/or process data inbetween numerous parties over a network on non-trusted peers. Data can be anything, but most interesting uses concern information that presently require a trusted third-party to exchange. Examples include money (requires a bank), a proof or property (requires a lawyer), a loan certificate, etc. In essence, the blockchain liquidates the need for a trusted third party.

How it works From a technical point of view, the blockchain is an innovation relying on three concepts: peer-to-peer networks, public-key cryptography, and distributed consensus based on the resolution of a random mathematical challenge. None of there concepts are fresh. It’s their combination that permits a breakthrough in computing. If you don’t understand it all, don’t worry: very few people know enough to be able to develop a blockchain on their own (which is a problem). But not understanding the blockchain doesn’t prevent you from using it, just like you can build web apps without knowing about TCP slow commence and Certificate Authorities.

What it compares to See the blockchain as a database replicated as many times as there are knots and (loosely) synchronized, or as a supercomputer formed by the combination of the CPUs/GPUs of all its knots. You can use this supercomputer to store and process data, just like you would with a remote API. Except you don’t need to own the backend, and you can be sure the data is safe and processed decently by the network.

Practical Implications

Facts stored in the blockchain can’t be lost. They are there forever, replicated as many times as there are knots. Even more, the blockchain doesn’t simply store a final state, it stores the history of all passed states, so that everyone can check the correctness of the final state by replaying the facts from the beginning.

Facts in the blockchain can be trusted, as they are verified by a technically enforceable consensus. Even if the network contains black sheeps, you can trust its judgement as a entire.

Storing data in the blockchain isn’t swift, as it requires a distributed consensus.

Peak: If you have twenty spare minutes to get a deeper understanding, witness this excellent introduction movie about Bitcoin, which also explains the blockchain:

Why It’s a Big deal

«The Blockchain is the most disruptive technology I have ever seen.» Salim Ismail

«The most interesting intellectual development on the Internet in the last five years.» Julian Assange

«I think the fact that within the Bitcoin universe an algorithm substitutes the functions of [the government] … is actually pretty cool.» Al Gore

These wise people have seen a large potential in the blockchain. It concerns disintermediation. The blockchain can potentially substitute all the intermediaries required to build trust. Let’s see a few example applications, most of which are just proof-of-concepts for now:

  • Monegraph lets authors claim their work, and set their rules (and fares) for use
  • La Zooz is a decentralized Uber. Share your car, find a seat, without Uber taking a fee.
  • Augur is an online bookmaker. Bet on outcomes, and get paid.
  • Storj.io is a peer-to-peer storage system. Rent your unused disk space, or find ultra cheap online storage.
  • Muse is a distributed, open, and translucent database tailored for the music industry
  • Ripple enables low cost cross-border payments for banks

Many successful businesses on the Internet today are intermediaries. Think about Google for a minute: Google managed to become the intermediary inbetween you and the entire Internet. Think about Amazon: they became the intermediary inbetween sellers and buyers for any type of good. That’s why a technology that permits to eliminate intermediaries can potentially disrupt the entire Internet.

Will it benefit to end users, who won’t need third parties to exchange goods and services anymore? It’s far from certain. Internet had the same promise of intense disintermediation. Yet Google built the very first market capitalization worldwide as an intermediary. That’s why it’s crucial to invest in the blockchain quickly, because the winners and losers of the next decade are being born right now.

You Won’t Build Your Own Blockchain

The technology behind the blockchain uses advanced cryptography, custom-built network protocols, and spectacle optimizations. This is all too sophisticated to be redeveloped each time a project needs a blockchain. Fortunately, aside of Bitcoin, there are several open-source blockchain implementations. Here are the most advanced:

  • Ethereum: an open-source blockchain platform by the Ethereum Foundation
  • Hyperledger: another open-source implementation, this time by the Linux Foundation. The very first proposal was published very recently.
  • Eris Industries: Instruments helping to manipulate Ethereum, Bitcoin or totally independent blockchains, mostly to build private networks. Their tutorials and explainers are a good beginning point for an overview of the blockchain technology.

The maturity of these implementations varies a lot. If you have to build an application now, we’d advise:

  • Eris for a closed Blockchain, or to detect and play with the technology
  • Ethereum for a collective Blockchain

Also, Bitcoin isn’t a good choice to build an application upon. It was designed for money transactions and nothing else, albeit you can program pseudo-smart contracts (but you have to love assembly). The network presently suffers a serious growth crisis, transactions wait in line for up to one hour to get inserted in a block. Miners often select transactions with the highest fees, so money transfers in Bitcoin become more expensive than they are in a Bank. The developer community is at war, and the speculation on the cryptocurrency makes the face value stir too much.

Numbers

How big are blockchains today? Let’s see some numbers.

Conclusion

The blockchain technology is both intriguing and titillating. Could it be the revolution that gurus predict? Or is it just a speculative bubble based on an impractical idea? After reading a lot on the matter, we couldn’t form a definitive opinion.

When we face uncertainty, we know a superb way to lift it: attempting. That’s what we determined to do. Read the next post in this series to see what we’ve learned by building a real world app running on the blockchain.

The Blockchain Explained to Web Developers, Part 1: The Theory

The marmelab blog

The blockchain is the fresh hot technology. If you haven’t heard about it, you most likely know Bitcoin. Well, the blockchain is the underlying technology that powers Bitcoin. Experts say the blockchain will cause a revolution similar to what Internet provoked. But what is it truly, and how can it be used to build apps today? This post is the very first in a series of three, explaining the blockchain phenomenon to web developers. We’ll discuss the theory, demonstrate actual code, and share our learnings, based on a real world project.

To begin, let’s attempt to understand what blockchains indeed are.

What Is A Blockchain, Take One

Albeit the blockchain was created to support Bitcoin, the blockchain concept can be defined regardless of the Bitcoin ecosystem. The literature usually defines a blockchain as goes after:

A blockchain is a ledger of facts, replicated across several computers assembled in a peer-to-peer network. Facts can be anything from monetary transactions to content signature. Members of the network are anonymous individuals called knots. All communication inwards the network takes advantage of cryptography to securely identify the sender and the receiver. When a knot wants to add a fact to the ledger, a consensus forms in the network to determine where this fact should emerge in the ledger; this consensus is called a block.

I don’t know about you, but after reading these definitions, I still had troubles figuring out what this is all about. Let’s get a bit deeper.

Ordering Facts

Decentralized peer-to-peer networks aren’t fresh. Napster and BitTorrent are P2P networks. Instead of exchanging movies, members of the blockchain network exchange facts. Then what’s the real deal about blockchains?

P2P networks, like other distributed systems, have to solve a very difficult computer science problem: the resolution of conflicts, or reconciliation. Relational databases suggest referential integrity, but there is no such thing in distributed system. If two incompatible facts arrive at the same time, the system must have rules to determine which fact is considered valid.

Take for example the dual spend problem: Alice has Ten$, and she sends twice Ten$ to Bob and Charlie. Who will have the Ten$ eventually? To reaction this question, the best way is to order the facts. If two incompatible facts arrive in the network, the very first one to be recorded wins.

In a P2P network, two facts sent harshly at the same time may arrive in different orders in distant knots. Then how can the entire network agree on the very first fact? To ensure integrity over a P2P network, you need a way to make everyone agree on the ordering of facts. You need a consensus system.

Consensus algorithms for distributed systems are a very active research field. You may have heard of Paxos or Raft algorithms. The blockchain implements another algorithm, the proof-of-work consensus, using blocks.

Blocks

Blocks are a wise trick to order facts in a network of non-trusted peers. The idea is ordinary: facts are grouped in blocks, and there is only a single chain of blocks, replicated in the entire network. Each block references the previous one. So if fact F is in block 21, and fact E is in block 22, then fact E is considered by the entire network to be posterior to fact F. Before being added to a block, facts are pending, i.e. unconfirmed.

Mining

Some knots in the chain create a fresh local block with pending facts. They challenge to see if their local block is going to become the next block in the chain for the entire network, by rolling dice. If a knot makes a dual six, then it earns the capability to publish their local block, and all facts in this block become confirmed. This block is sent to all other knots in the network. All knots check that the block is correct, add it to their copy of the chain, and attempt to build a fresh block with fresh pending facts.

But knots don’t just roll a duo dice. Blockchain challenges imply rolling a gigantic number of dice. Finding the random key to validate a block is very unlikely, by design. This prevents fraud, and makes the network safe (unless a malicious user wields more than half of the knots in the network). As a consequence, fresh blocks gets published to the chain at a stationary time interval. In Bitcoin, blocks are published every ten minutes on average.

In Bitcoin, the challenge involves a dual SHA-256 hash of a string made of the pending facts, the identifier of the previous block, and a random string. A knot wins if their hash contains at least n leading zeroes.

Number n is adjusted every once in a while to keep block duration stationary despite variations in the number of knots. This number is called the difficulty. Other blockchain implementations use special hashing mechanisms that discourage the usage of GPUs (e.g. by requiring large memory transfers).

The process of looking for blocks is called mining. This is because, just like gold mining, block mining brings an economical prize – some form of money. That’s the reason why people who run knots in a blockchain are also called miners.

Note: By default, a knot doesn’t mine – it just receives blocks mined by other knots. It’s a voluntary process to turn a knot into a miner knot.

Money and Cryptocurrencies

Every 2nd, each miner knot in a blockchain tests thousands of random strings to attempt and form a fresh block. So running a miner in the blockchain pumps a thick amount of computer resources (storage and CPU). That’s why you must pay to store facts in a blockchain. Reading facts, on the other forearm, is free: you just need to run your own knot, and you’ll recuperate the entire history of facts issued by all the other knots. So to summarize:

  • Reading data is free
  • Adding facts costs a puny fee
  • Mining a block brings in the money of all the fees of the facts included in the block

We’re not talking about real money here. In fact, each blockchain has its own (crypto-)currency. It’s called Bitcoin (BTC) in the Bitcoin network, Ether (ETH) on the Ethereum network, etc. To make a payment in the Bitcoin network, you must pay a puny fee in Bitcoins – just like you would pay a fee to a bank. But then, where do the very first coins come from?

Miners receive a gratification for keeping the network working and safe. Each time they successfully mine a block, they receive a motionless amount of cryptocurrency. In Bitcoin this gratification is twenty five BTC per block, in Ethereum it’s five ETH per block. That way, the blockchain generates its own money.

Lastly, cryptocurrencies rapidly became convertible to real money. Their facial value is only determined by suggest and request, so it’s subject to speculation. At the time of writing, mining Bitcoins still costs slightly less in energy and hardware than you can earn by selling the coins you discovered in the process. That’s why people add fresh miners every day, hoping to turn electro-therapy into money. But fluctuations in the BTC value make it less and less profitable.

Contracts

So far we’ve mostly mentioned facts storage, but a blockchain can also execute programs. Some blockchains permit each fact to contain a mini program. Such programs are replicated together with the facts, and every knot executes them when receiving the facts. In bitcoin, this can be used to make a transaction conditional: Bob will receive one hundred BTC from Alice if and only if today is February 29th.

Other blockchains permit for more sophisticated contracts. In Ethereum for example, each contract carries a mini-database, and exposes methods to modify the data. As contracts are replicated across all knots, so are their database. Each time a user calls a method on the contract and therefore updates the underlying data, this instruction is replicated and replayed by the entire network. This permits for a distributed consensus on the execution of a promise.

This idea of pre-programed conditions, interfaced with the real world, and broadcasted to everyone, is called a clever contract. A contract is a promise that signing parties agree to make legally-enforceable. A brainy contract is the same, except with the word “technically-“ instead of “legally-“. This eliminates the need for a judge, or any authority acknowledged by both parties.

Imagine that you want to rent your house for a week and $1,000, with a 50% upfront payment. You and the loaner sign a contract, very likely written by a lawyer. You also need a bank to receive the payment. At the beginning of the week, you ask for a $Five,000 deposit; the loaner writes a check for it. At the end of the week, the loaner turns down to pay the remaining 50%. You also realize that they broke a window, and that the deposit check refers to an empty account. You’ll need a lawyer to help you enforce the rental contract in a court.

Wise contracts in a blockchain permit you to get rid of the bank, the lawyer, and the court. Just write a program that defines how much money should be transferred in response to certain conditions:

  • two weeks before beginning of rental: transfer $500 from loaner to holder
  • cancellation by the proprietor: transfer $500 from possessor to loaner
  • end of the rental period: transfer $500 from loaner to possessor
  • proof of physical degradation after the rental period: transfer $Five,000 from loaner to possessor

Upload this brainy contract to the blockchain, and you’re all set. At the time defined in the contract, the money transfers will occur. And if the possessor can bring a predefined proof of physical degradation, they get the $Five,000 automatically (without any need for a deposit).

You might wonder how to build a proof of physical degradation. That’s where the Internet of Things (IoT) kicks in. In order to interact with the real world, blockchains need sensors and actuators. The Blockchain revolution won’t happen unless the IoT revolution comes very first.

Such applications relying on clever contracts are called Decentralized Apps, or DApps.

Wise contracts naturally extend to brainy property, and a lot more brainy things. The thing to recall is that “smart” means “no intermediaries”, or “technically-enforced”. Blockchains are a fresh way to disintermediate businesses – just like the Internet disintermediated music distribution.

What Is A Blockchain, Take Two

In my opinion, the best way to understand the blockchain is to look at it from various angles.

What it does A blockchain permits to securely share and/or process data inbetween numerous parties over a network on non-trusted peers. Data can be anything, but most interesting uses concern information that presently require a trusted third-party to exchange. Examples include money (requires a bank), a proof or property (requires a lawyer), a loan certificate, etc. In essence, the blockchain liquidates the need for a trusted third party.

How it works From a technical point of view, the blockchain is an innovation relying on three concepts: peer-to-peer networks, public-key cryptography, and distributed consensus based on the resolution of a random mathematical challenge. None of there concepts are fresh. It’s their combination that permits a breakthrough in computing. If you don’t understand it all, don’t worry: very few people know enough to be able to develop a blockchain on their own (which is a problem). But not understanding the blockchain doesn’t prevent you from using it, just like you can build web apps without knowing about TCP slow begin and Certificate Authorities.

What it compares to See the blockchain as a database replicated as many times as there are knots and (loosely) synchronized, or as a supercomputer formed by the combination of the CPUs/GPUs of all its knots. You can use this supercomputer to store and process data, just like you would with a remote API. Except you don’t need to own the backend, and you can be sure the data is safe and processed decently by the network.

Practical Implications

Facts stored in the blockchain can’t be lost. They are there forever, replicated as many times as there are knots. Even more, the blockchain doesn’t simply store a final state, it stores the history of all passed states, so that everyone can check the correctness of the final state by replaying the facts from the beginning.

Facts in the blockchain can be trusted, as they are verified by a technically enforceable consensus. Even if the network contains black sheeps, you can trust its judgement as a entire.

Storing data in the blockchain isn’t rapid, as it requires a distributed consensus.

Peak: If you have twenty spare minutes to get a deeper understanding, observe this excellent introduction movie about Bitcoin, which also explains the blockchain:

Why It’s a Big deal

«The Blockchain is the most disruptive technology I have ever seen.» Salim Ismail

«The most interesting intellectual development on the Internet in the last five years.» Julian Assange

«I think the fact that within the Bitcoin universe an algorithm substitutes the functions of [the government] … is actually pretty cool.» Al Gore

These brainy people have seen a meaty potential in the blockchain. It concerns disintermediation. The blockchain can potentially substitute all the intermediaries required to build trust. Let’s see a few example applications, most of which are just proof-of-concepts for now:

  • Monegraph lets authors claim their work, and set their rules (and fares) for use
  • La Zooz is a decentralized Uber. Share your car, find a seat, without Uber taking a fee.
  • Augur is an online bookmaker. Bet on outcomes, and get paid.
  • Storj.io is a peer-to-peer storage system. Rent your unused disk space, or find ultra cheap online storage.
  • Muse is a distributed, open, and semi-transparent database tailored for the music industry
  • Ripple enables low cost cross-border payments for banks

Many successful businesses on the Internet today are intermediaries. Think about Google for a minute: Google managed to become the intermediary inbetween you and the entire Internet. Think about Amazon: they became the intermediary inbetween sellers and buyers for any type of good. That’s why a technology that permits to liquidate intermediaries can potentially disrupt the entire Internet.

Will it benefit to end users, who won’t need third parties to exchange goods and services anymore? It’s far from certain. Internet had the same promise of mighty disintermediation. Yet Google built the very first market capitalization worldwide as an intermediary. That’s why it’s crucial to invest in the blockchain quickly, because the winners and losers of the next decade are being born right now.

You Won’t Build Your Own Blockchain

The technology behind the blockchain uses advanced cryptography, custom-built network protocols, and spectacle optimizations. This is all too sophisticated to be redeveloped each time a project needs a blockchain. Fortunately, aside of Bitcoin, there are several open-source blockchain implementations. Here are the most advanced:

  • Ethereum: an open-source blockchain platform by the Ethereum Foundation
  • Hyperledger: another open-source implementation, this time by the Linux Foundation. The very first proposal was published very recently.
  • Eris Industries: Contraptions helping to manipulate Ethereum, Bitcoin or totally independent blockchains, mostly to build private networks. Their tutorials and explainers are a excellent embarking point for an overview of the blockchain technology.

The maturity of these implementations varies a lot. If you have to build an application now, we’d advise:

  • Eris for a closed Blockchain, or to detect and play with the technology
  • Ethereum for a collective Blockchain

Also, Bitcoin isn’t a good choice to build an application upon. It was designed for money transactions and nothing else, albeit you can program pseudo-smart contracts (but you have to love assembly). The network presently suffers a serious growth crisis, transactions wait in line for up to one hour to get inserted in a block. Miners often select transactions with the highest fees, so money transfers in Bitcoin become more expensive than they are in a Bank. The developer community is at war, and the speculation on the cryptocurrency makes the face value stir too much.

Numbers

How big are blockchains today? Let’s see some numbers.

Conclusion

The blockchain technology is both intriguing and arousing. Could it be the revolution that gurus predict? Or is it just a speculative bubble based on an impractical idea? After reading a lot on the matter, we couldn’t form a definitive opinion.

When we face uncertainty, we know a excellent way to lift it: attempting. That’s what we determined to do. Read the next post in this series to see what we’ve learned by building a real world app running on the blockchain.

The Blockchain Explained to Web Developers, Part 1: The Theory

The marmelab blog

The blockchain is the fresh hot technology. If you haven’t heard about it, you most likely know Bitcoin. Well, the blockchain is the underlying technology that powers Bitcoin. Experts say the blockchain will cause a revolution similar to what Internet provoked. But what is it truly, and how can it be used to build apps today? This post is the very first in a series of three, explaining the blockchain phenomenon to web developers. We’ll discuss the theory, display actual code, and share our learnings, based on a real world project.

To begin, let’s attempt to understand what blockchains truly are.

What Is A Blockchain, Take One

Albeit the blockchain was created to support Bitcoin, the blockchain concept can be defined regardless of the Bitcoin ecosystem. The literature usually defines a blockchain as goes after:

A blockchain is a ledger of facts, replicated across several computers assembled in a peer-to-peer network. Facts can be anything from monetary transactions to content signature. Members of the network are anonymous individuals called knots. All communication inwards the network takes advantage of cryptography to securely identify the sender and the receiver. When a knot wants to add a fact to the ledger, a consensus forms in the network to determine where this fact should show up in the ledger; this consensus is called a block.

I don’t know about you, but after reading these definitions, I still had troubles figuring out what this is all about. Let’s get a bit deeper.

Ordering Facts

Decentralized peer-to-peer networks aren’t fresh. Napster and BitTorrent are P2P networks. Instead of exchanging movies, members of the blockchain network exchange facts. Then what’s the real deal about blockchains?

P2P networks, like other distributed systems, have to solve a very difficult computer science problem: the resolution of conflicts, or reconciliation. Relational databases suggest referential integrity, but there is no such thing in distributed system. If two incompatible facts arrive at the same time, the system must have rules to determine which fact is considered valid.

Take for example the dual spend problem: Alice has Ten$, and she sends twice Ten$ to Bob and Charlie. Who will have the Ten$ eventually? To reaction this question, the best way is to order the facts. If two incompatible facts arrive in the network, the very first one to be recorded wins.

In a P2P network, two facts sent harshly at the same time may arrive in different orders in distant knots. Then how can the entire network agree on the very first fact? To ensure integrity over a P2P network, you need a way to make everyone agree on the ordering of facts. You need a consensus system.

Consensus algorithms for distributed systems are a very active research field. You may have heard of Paxos or Raft algorithms. The blockchain implements another algorithm, the proof-of-work consensus, using blocks.

Blocks

Blocks are a clever trick to order facts in a network of non-trusted peers. The idea is elementary: facts are grouped in blocks, and there is only a single chain of blocks, replicated in the entire network. Each block references the previous one. So if fact F is in block 21, and fact E is in block 22, then fact E is considered by the entire network to be posterior to fact F. Before being added to a block, facts are pending, i.e. unconfirmed.

Mining

Some knots in the chain create a fresh local block with pending facts. They challenge to see if their local block is going to become the next block in the chain for the entire network, by rolling dice. If a knot makes a dual six, then it earns the capability to publish their local block, and all facts in this block become confirmed. This block is sent to all other knots in the network. All knots check that the block is correct, add it to their copy of the chain, and attempt to build a fresh block with fresh pending facts.

But knots don’t just roll a duo dice. Blockchain challenges imply rolling a yam-sized number of dice. Finding the random key to validate a block is very unlikely, by design. This prevents fraud, and makes the network safe (unless a malicious user wields more than half of the knots in the network). As a consequence, fresh blocks gets published to the chain at a immobile time interval. In Bitcoin, blocks are published every ten minutes on average.

In Bitcoin, the challenge involves a dual SHA-256 hash of a string made of the pending facts, the identifier of the previous block, and a random string. A knot wins if their hash contains at least n leading zeroes.

Number n is adjusted every once in a while to keep block duration stationary despite variations in the number of knots. This number is called the difficulty. Other blockchain implementations use special hashing technologies that discourage the usage of GPUs (e.g. by requiring large memory transfers).

The process of looking for blocks is called mining. This is because, just like gold mining, block mining brings an economical prize – some form of money. That’s the reason why people who run knots in a blockchain are also called miners.

Note: By default, a knot doesn’t mine – it just receives blocks mined by other knots. It’s a voluntary process to turn a knot into a miner knot.

Money and Cryptocurrencies

Every 2nd, each miner knot in a blockchain tests thousands of random strings to attempt and form a fresh block. So running a miner in the blockchain pumps a gigantic amount of computer resources (storage and CPU). That’s why you must pay to store facts in a blockchain. Reading facts, on the other forearm, is free: you just need to run your own knot, and you’ll recuperate the entire history of facts issued by all the other knots. So to summarize:

  • Reading data is free
  • Adding facts costs a petite fee
  • Mining a block brings in the money of all the fees of the facts included in the block

We’re not talking about real money here. In fact, each blockchain has its own (crypto-)currency. It’s called Bitcoin (BTC) in the Bitcoin network, Ether (ETH) on the Ethereum network, etc. To make a payment in the Bitcoin network, you must pay a petite fee in Bitcoins – just like you would pay a fee to a bank. But then, where do the very first coins come from?

Miners receive a gratification for keeping the network working and safe. Each time they successfully mine a block, they receive a immobile amount of cryptocurrency. In Bitcoin this gratification is twenty five BTC per block, in Ethereum it’s five ETH per block. That way, the blockchain generates its own money.

Lastly, cryptocurrencies rapidly became convertible to real money. Their facial value is only determined by suggest and request, so it’s subject to speculation. At the time of writing, mining Bitcoins still costs slightly less in energy and hardware than you can earn by selling the coins you discovered in the process. That’s why people add fresh miners every day, hoping to turn electro-stimulation into money. But fluctuations in the BTC value make it less and less profitable.

Contracts

So far we’ve mostly mentioned facts storage, but a blockchain can also execute programs. Some blockchains permit each fact to contain a mini program. Such programs are replicated together with the facts, and every knot executes them when receiving the facts. In bitcoin, this can be used to make a transaction conditional: Bob will receive one hundred BTC from Alice if and only if today is February 29th.

Other blockchains permit for more sophisticated contracts. In Ethereum for example, each contract carries a mini-database, and exposes methods to modify the data. As contracts are replicated across all knots, so are their database. Each time a user calls a method on the contract and therefore updates the underlying data, this instruction is replicated and replayed by the entire network. This permits for a distributed consensus on the execution of a promise.

This idea of pre-programed conditions, interfaced with the real world, and broadcasted to everyone, is called a wise contract. A contract is a promise that signing parties agree to make legally-enforceable. A clever contract is the same, except with the word “technically-“ instead of “legally-“. This eliminates the need for a judge, or any authority acknowledged by both parties.

Imagine that you want to rent your house for a week and $1,000, with a 50% upfront payment. You and the loaner sign a contract, most likely written by a lawyer. You also need a bank to receive the payment. At the beginning of the week, you ask for a $Five,000 deposit; the loaner writes a check for it. At the end of the week, the loaner denies to pay the remaining 50%. You also realize that they broke a window, and that the deposit check refers to an empty account. You’ll need a lawyer to help you enforce the rental contract in a court.

Clever contracts in a blockchain permit you to get rid of the bank, the lawyer, and the court. Just write a program that defines how much money should be transferred in response to certain conditions:

  • two weeks before beginning of rental: transfer $500 from loaner to possessor
  • cancellation by the proprietor: transfer $500 from proprietor to loaner
  • end of the rental period: transfer $500 from loaner to proprietor
  • proof of physical degradation after the rental period: transfer $Five,000 from loaner to proprietor

Upload this wise contract to the blockchain, and you’re all set. At the time defined in the contract, the money transfers will occur. And if the holder can bring a predefined proof of physical degradation, they get the $Five,000 automatically (without any need for a deposit).

You might wonder how to build a proof of physical degradation. That’s where the Internet of Things (IoT) kicks in. In order to interact with the real world, blockchains need sensors and actuators. The Blockchain revolution won’t happen unless the IoT revolution comes very first.

Such applications relying on clever contracts are called Decentralized Apps, or DApps.

Brainy contracts naturally extend to clever property, and a lot more brainy things. The thing to recall is that “smart” means “no intermediaries”, or “technically-enforced”. Blockchains are a fresh way to disintermediate businesses – just like the Internet disintermediated music distribution.

What Is A Blockchain, Take Two

In my opinion, the best way to understand the blockchain is to look at it from various angles.

What it does A blockchain permits to securely share and/or process data inbetween numerous parties over a network on non-trusted peers. Data can be anything, but most interesting uses concern information that presently require a trusted third-party to exchange. Examples include money (requires a bank), a proof or property (requires a lawyer), a loan certificate, etc. In essence, the blockchain liquidates the need for a trusted third party.

How it works From a technical point of view, the blockchain is an innovation relying on three concepts: peer-to-peer networks, public-key cryptography, and distributed consensus based on the resolution of a random mathematical challenge. None of there concepts are fresh. It’s their combination that permits a breakthrough in computing. If you don’t understand it all, don’t worry: very few people know enough to be able to develop a blockchain on their own (which is a problem). But not understanding the blockchain doesn’t prevent you from using it, just like you can build web apps without knowing about TCP slow begin and Certificate Authorities.

What it compares to See the blockchain as a database replicated as many times as there are knots and (loosely) synchronized, or as a supercomputer formed by the combination of the CPUs/GPUs of all its knots. You can use this supercomputer to store and process data, just like you would with a remote API. Except you don’t need to own the backend, and you can be sure the data is safe and processed decently by the network.

Practical Implications

Facts stored in the blockchain can’t be lost. They are there forever, replicated as many times as there are knots. Even more, the blockchain doesn’t simply store a final state, it stores the history of all passed states, so that everyone can check the correctness of the final state by replaying the facts from the beginning.

Facts in the blockchain can be trusted, as they are verified by a technically enforceable consensus. Even if the network contains black sheeps, you can trust its judgement as a entire.

Storing data in the blockchain isn’t prompt, as it requires a distributed consensus.

Peak: If you have twenty spare minutes to get a deeper understanding, observe this excellent introduction movie about Bitcoin, which also explains the blockchain:

Why It’s a Big deal

«The Blockchain is the most disruptive technology I have ever seen.» Salim Ismail

«The most interesting intellectual development on the Internet in the last five years.» Julian Assange

«I think the fact that within the Bitcoin universe an algorithm substitutes the functions of [the government] … is actually pretty cool.» Al Gore

These clever people have seen a meaty potential in the blockchain. It concerns disintermediation. The blockchain can potentially substitute all the intermediaries required to build trust. Let’s see a few example applications, most of which are just proof-of-concepts for now:

  • Monegraph lets authors claim their work, and set their rules (and fares) for use
  • La Zooz is a decentralized Uber. Share your car, find a seat, without Uber taking a fee.
  • Augur is an online bookmaker. Bet on outcomes, and get paid.
  • Storj.io is a peer-to-peer storage system. Rent your unused disk space, or find ultra cheap online storage.
  • Muse is a distributed, open, and semitransparent database tailored for the music industry
  • Ripple enables low cost cross-border payments for banks

Many successful businesses on the Internet today are intermediaries. Think about Google for a minute: Google managed to become the intermediary inbetween you and the entire Internet. Think about Amazon: they became the intermediary inbetween sellers and buyers for any type of good. That’s why a technology that permits to eliminate intermediaries can potentially disrupt the entire Internet.

Will it benefit to end users, who won’t need third parties to exchange goods and services anymore? It’s far from certain. Internet had the same promise of mighty disintermediation. Yet Google built the very first market capitalization worldwide as an intermediary. That’s why it’s crucial to invest in the blockchain quickly, because the winners and losers of the next decade are being born right now.

You Won’t Build Your Own Blockchain

The technology behind the blockchain uses advanced cryptography, custom-made network protocols, and spectacle optimizations. This is all too sophisticated to be redeveloped each time a project needs a blockchain. Fortunately, aside of Bitcoin, there are several open-source blockchain implementations. Here are the most advanced:

  • Ethereum: an open-source blockchain platform by the Ethereum Foundation
  • Hyperledger: another open-source implementation, this time by the Linux Foundation. The very first proposal was published very recently.
  • Eris Industries: Instruments helping to manipulate Ethereum, Bitcoin or totally independent blockchains, mostly to build private networks. Their tutorials and explainers are a excellent embarking point for an overview of the blockchain technology.

The maturity of these implementations varies a lot. If you have to build an application now, we’d advise:

  • Eris for a closed Blockchain, or to detect and play with the technology
  • Ethereum for a collective Blockchain

Also, Bitcoin isn’t a good choice to build an application upon. It was designed for money transactions and nothing else, albeit you can program pseudo-smart contracts (but you have to love assembly). The network presently suffers a serious growth crisis, transactions wait in line for up to one hour to get inserted in a block. Miners often select transactions with the highest fees, so money transfers in Bitcoin become more expensive than they are in a Bank. The developer community is at war, and the speculation on the cryptocurrency makes the face value budge too much.

Numbers

How big are blockchains today? Let’s see some numbers.

Conclusion

The blockchain technology is both intriguing and arousing. Could it be the revolution that gurus predict? Or is it just a speculative bubble based on an impractical idea? After reading a lot on the matter, we couldn’t form a definitive opinion.

When we face uncertainty, we know a fine way to lift it: attempting. That’s what we determined to do. Read the next post in this series to see what we’ve learned by building a real world app running on the blockchain.

The Blockchain Explained to Web Developers, Part 1: The Theory

The marmelab blog

The blockchain is the fresh hot technology. If you haven’t heard about it, you most likely know Bitcoin. Well, the blockchain is the underlying technology that powers Bitcoin. Experts say the blockchain will cause a revolution similar to what Internet provoked. But what is it indeed, and how can it be used to build apps today? This post is the very first in a series of three, explaining the blockchain phenomenon to web developers. We’ll discuss the theory, demonstrate actual code, and share our learnings, based on a real world project.

To begin, let’s attempt to understand what blockchains truly are.

What Is A Blockchain, Take One

Albeit the blockchain was created to support Bitcoin, the blockchain concept can be defined regardless of the Bitcoin ecosystem. The literature usually defines a blockchain as goes after:

A blockchain is a ledger of facts, replicated across several computers assembled in a peer-to-peer network. Facts can be anything from monetary transactions to content signature. Members of the network are anonymous individuals called knots. All communication inwards the network takes advantage of cryptography to securely identify the sender and the receiver. When a knot wants to add a fact to the ledger, a consensus forms in the network to determine where this fact should show up in the ledger; this consensus is called a block.

I don’t know about you, but after reading these definitions, I still had troubles figuring out what this is all about. Let’s get a bit deeper.

Ordering Facts

Decentralized peer-to-peer networks aren’t fresh. Napster and BitTorrent are P2P networks. Instead of exchanging movies, members of the blockchain network exchange facts. Then what’s the real deal about blockchains?

P2P networks, like other distributed systems, have to solve a very difficult computer science problem: the resolution of conflicts, or reconciliation. Relational databases suggest referential integrity, but there is no such thing in distributed system. If two incompatible facts arrive at the same time, the system must have rules to determine which fact is considered valid.

Take for example the dual spend problem: Alice has Ten$, and she sends twice Ten$ to Bob and Charlie. Who will have the Ten$ eventually? To response this question, the best way is to order the facts. If two incompatible facts arrive in the network, the very first one to be recorded wins.

In a P2P network, two facts sent harshly at the same time may arrive in different orders in distant knots. Then how can the entire network agree on the very first fact? To assure integrity over a P2P network, you need a way to make everyone agree on the ordering of facts. You need a consensus system.

Consensus algorithms for distributed systems are a very active research field. You may have heard of Paxos or Raft algorithms. The blockchain implements another algorithm, the proof-of-work consensus, using blocks.

Blocks

Blocks are a wise trick to order facts in a network of non-trusted peers. The idea is ordinary: facts are grouped in blocks, and there is only a single chain of blocks, replicated in the entire network. Each block references the previous one. So if fact F is in block 21, and fact E is in block 22, then fact E is considered by the entire network to be posterior to fact F. Before being added to a block, facts are pending, i.e. unconfirmed.

Mining

Some knots in the chain create a fresh local block with pending facts. They rival to see if their local block is going to become the next block in the chain for the entire network, by rolling dice. If a knot makes a dual six, then it earns the capability to publish their local block, and all facts in this block become confirmed. This block is sent to all other knots in the network. All knots check that the block is correct, add it to their copy of the chain, and attempt to build a fresh block with fresh pending facts.

But knots don’t just roll a duo dice. Blockchain challenges imply rolling a phat number of dice. Finding the random key to validate a block is very unlikely, by design. This prevents fraud, and makes the network safe (unless a malicious user possesses more than half of the knots in the network). As a consequence, fresh blocks gets published to the chain at a motionless time interval. In Bitcoin, blocks are published every ten minutes on average.

In Bitcoin, the challenge involves a dual SHA-256 hash of a string made of the pending facts, the identifier of the previous block, and a random string. A knot wins if their hash contains at least n leading zeroes.

Number n is adjusted every once in a while to keep block duration immovable despite variations in the number of knots. This number is called the difficulty. Other blockchain implementations use special hashing technics that discourage the usage of GPUs (e.g. by requiring large memory transfers).

The process of looking for blocks is called mining. This is because, just like gold mining, block mining brings an economical prize – some form of money. That’s the reason why people who run knots in a blockchain are also called miners.

Note: By default, a knot doesn’t mine – it just receives blocks mined by other knots. It’s a voluntary process to turn a knot into a miner knot.

Money and Cryptocurrencies

Every 2nd, each miner knot in a blockchain tests thousands of random strings to attempt and form a fresh block. So running a miner in the blockchain pumps a thick amount of computer resources (storage and CPU). That’s why you must pay to store facts in a blockchain. Reading facts, on the other mitt, is free: you just need to run your own knot, and you’ll recuperate the entire history of facts issued by all the other knots. So to summarize:

  • Reading data is free
  • Adding facts costs a petite fee
  • Mining a block brings in the money of all the fees of the facts included in the block

We’re not talking about real money here. In fact, each blockchain has its own (crypto-)currency. It’s called Bitcoin (BTC) in the Bitcoin network, Ether (ETH) on the Ethereum network, etc. To make a payment in the Bitcoin network, you must pay a puny fee in Bitcoins – just like you would pay a fee to a bank. But then, where do the very first coins come from?

Miners receive a gratification for keeping the network working and safe. Each time they successfully mine a block, they receive a motionless amount of cryptocurrency. In Bitcoin this gratification is twenty five BTC per block, in Ethereum it’s five ETH per block. That way, the blockchain generates its own money.

Lastly, cryptocurrencies rapidly became convertible to real money. Their facial value is only determined by suggest and request, so it’s subject to speculation. At the time of writing, mining Bitcoins still costs slightly less in energy and hardware than you can earn by selling the coins you discovered in the process. That’s why people add fresh miners every day, hoping to turn electro-therapy into money. But fluctuations in the BTC value make it less and less profitable.

Contracts

So far we’ve mostly mentioned facts storage, but a blockchain can also execute programs. Some blockchains permit each fact to contain a mini program. Such programs are replicated together with the facts, and every knot executes them when receiving the facts. In bitcoin, this can be used to make a transaction conditional: Bob will receive one hundred BTC from Alice if and only if today is February 29th.

Other blockchains permit for more sophisticated contracts. In Ethereum for example, each contract carries a mini-database, and exposes methods to modify the data. As contracts are replicated across all knots, so are their database. Each time a user calls a method on the contract and therefore updates the underlying data, this directive is replicated and replayed by the entire network. This permits for a distributed consensus on the execution of a promise.

This idea of pre-programed conditions, interfaced with the real world, and broadcasted to everyone, is called a wise contract. A contract is a promise that signing parties agree to make legally-enforceable. A brainy contract is the same, except with the word “technically-“ instead of “legally-“. This eliminates the need for a judge, or any authority acknowledged by both parties.

Imagine that you want to rent your house for a week and $1,000, with a 50% upfront payment. You and the loaner sign a contract, very likely written by a lawyer. You also need a bank to receive the payment. At the beginning of the week, you ask for a $Five,000 deposit; the loaner writes a check for it. At the end of the week, the loaner turns down to pay the remaining 50%. You also realize that they broke a window, and that the deposit check refers to an empty account. You’ll need a lawyer to help you enforce the rental contract in a court.

Brainy contracts in a blockchain permit you to get rid of the bank, the lawyer, and the court. Just write a program that defines how much money should be transferred in response to certain conditions:

  • two weeks before beginning of rental: transfer $500 from loaner to possessor
  • cancellation by the proprietor: transfer $500 from proprietor to loaner
  • end of the rental period: transfer $500 from loaner to holder
  • proof of physical degradation after the rental period: transfer $Five,000 from loaner to possessor

Upload this wise contract to the blockchain, and you’re all set. At the time defined in the contract, the money transfers will occur. And if the proprietor can bring a predefined proof of physical degradation, they get the $Five,000 automatically (without any need for a deposit).

You might wonder how to build a proof of physical degradation. That’s where the Internet of Things (IoT) kicks in. In order to interact with the real world, blockchains need sensors and actuators. The Blockchain revolution won’t happen unless the IoT revolution comes very first.

Such applications relying on clever contracts are called Decentralized Apps, or DApps.

Wise contracts naturally extend to wise property, and a lot more brainy things. The thing to recall is that “smart” means “no intermediaries”, or “technically-enforced”. Blockchains are a fresh way to disintermediate businesses – just like the Internet disintermediated music distribution.

What Is A Blockchain, Take Two

In my opinion, the best way to understand the blockchain is to look at it from various angles.

What it does A blockchain permits to securely share and/or process data inbetween numerous parties over a network on non-trusted peers. Data can be anything, but most interesting uses concern information that presently require a trusted third-party to exchange. Examples include money (requires a bank), a proof or property (requires a lawyer), a loan certificate, etc. In essence, the blockchain liquidates the need for a trusted third party.

How it works From a technical point of view, the blockchain is an innovation relying on three concepts: peer-to-peer networks, public-key cryptography, and distributed consensus based on the resolution of a random mathematical challenge. None of there concepts are fresh. It’s their combination that permits a breakthrough in computing. If you don’t understand it all, don’t worry: very few people know enough to be able to develop a blockchain on their own (which is a problem). But not understanding the blockchain doesn’t prevent you from using it, just like you can build web apps without knowing about TCP slow commence and Certificate Authorities.

What it compares to See the blockchain as a database replicated as many times as there are knots and (loosely) synchronized, or as a supercomputer formed by the combination of the CPUs/GPUs of all its knots. You can use this supercomputer to store and process data, just like you would with a remote API. Except you don’t need to own the backend, and you can be sure the data is safe and processed decently by the network.

Practical Implications

Facts stored in the blockchain can’t be lost. They are there forever, replicated as many times as there are knots. Even more, the blockchain doesn’t simply store a final state, it stores the history of all passed states, so that everyone can check the correctness of the final state by replaying the facts from the beginning.

Facts in the blockchain can be trusted, as they are verified by a technically enforceable consensus. Even if the network contains black sheeps, you can trust its judgement as a entire.

Storing data in the blockchain isn’t prompt, as it requires a distributed consensus.

Peak: If you have twenty spare minutes to get a deeper understanding, observe this excellent introduction movie about Bitcoin, which also explains the blockchain:

Why It’s a Big deal

«The Blockchain is the most disruptive technology I have ever seen.» Salim Ismail

«The most interesting intellectual development on the Internet in the last five years.» Julian Assange

«I think the fact that within the Bitcoin universe an algorithm substitutes the functions of [the government] … is actually pretty cool.» Al Gore

These brainy people have seen a fat potential in the blockchain. It concerns disintermediation. The blockchain can potentially substitute all the intermediaries required to build trust. Let’s see a few example applications, most of which are just proof-of-concepts for now:

  • Monegraph lets authors claim their work, and set their rules (and fares) for use
  • La Zooz is a decentralized Uber. Share your car, find a seat, without Uber taking a fee.
  • Augur is an online bookmaker. Bet on outcomes, and get paid.
  • Storj.io is a peer-to-peer storage system. Rent your unused disk space, or find ultra cheap online storage.
  • Muse is a distributed, open, and semi-transparent database tailored for the music industry
  • Ripple enables low cost cross-border payments for banks

Many successful businesses on the Internet today are intermediaries. Think about Google for a minute: Google managed to become the intermediary inbetween you and the entire Internet. Think about Amazon: they became the intermediary inbetween sellers and buyers for any type of good. That’s why a technology that permits to liquidate intermediaries can potentially disrupt the entire Internet.

Will it benefit to end users, who won’t need third parties to exchange goods and services anymore? It’s far from certain. Internet had the same promise of mighty disintermediation. Yet Google built the very first market capitalization worldwide as an intermediary. That’s why it’s crucial to invest in the blockchain quickly, because the winners and losers of the next decade are being born right now.

You Won’t Build Your Own Blockchain

The technology behind the blockchain uses advanced cryptography, custom-built network protocols, and spectacle optimizations. This is all too sophisticated to be redeveloped each time a project needs a blockchain. Fortunately, aside of Bitcoin, there are several open-source blockchain implementations. Here are the most advanced:

  • Ethereum: an open-source blockchain platform by the Ethereum Foundation
  • Hyperledger: another open-source implementation, this time by the Linux Foundation. The very first proposal was published very recently.
  • Eris Industries: Contraptions helping to manipulate Ethereum, Bitcoin or totally independent blockchains, mostly to build private networks. Their tutorials and explainers are a excellent beginning point for an overview of the blockchain technology.

The maturity of these implementations varies a lot. If you have to build an application now, we’d advise:

  • Eris for a closed Blockchain, or to detect and play with the technology
  • Ethereum for a collective Blockchain

Also, Bitcoin isn’t a good choice to build an application upon. It was designed for money transactions and nothing else, albeit you can program pseudo-smart contracts (but you have to love assembly). The network presently suffers a serious growth crisis, transactions wait in line for up to one hour to get inserted in a block. Miners often select transactions with the highest fees, so money transfers in Bitcoin become more expensive than they are in a Bank. The developer community is at war, and the speculation on the cryptocurrency makes the face value budge too much.

Numbers

How big are blockchains today? Let’s see some numbers.

Conclusion

The blockchain technology is both intriguing and arousing. Could it be the revolution that gurus predict? Or is it just a speculative bubble based on an impractical idea? After reading a lot on the matter, we couldn’t form a definitive opinion.

When we face uncertainty, we know a fine way to lift it: attempting. That’s what we determined to do. Read the next post in this series to see what we’ve learned by building a real world app running on the blockchain.

The Blockchain Explained to Web Developers, Part 1: The Theory

The marmelab blog

The blockchain is the fresh hot technology. If you haven’t heard about it, you most likely know Bitcoin. Well, the blockchain is the underlying technology that powers Bitcoin. Experts say the blockchain will cause a revolution similar to what Internet provoked. But what is it indeed, and how can it be used to build apps today? This post is the very first in a series of three, explaining the blockchain phenomenon to web developers. We’ll discuss the theory, display actual code, and share our learnings, based on a real world project.

To begin, let’s attempt to understand what blockchains truly are.

What Is A Blockchain, Take One

Albeit the blockchain was created to support Bitcoin, the blockchain concept can be defined regardless of the Bitcoin ecosystem. The literature usually defines a blockchain as goes after:

A blockchain is a ledger of facts, replicated across several computers assembled in a peer-to-peer network. Facts can be anything from monetary transactions to content signature. Members of the network are anonymous individuals called knots. All communication inwards the network takes advantage of cryptography to securely identify the sender and the receiver. When a knot wants to add a fact to the ledger, a consensus forms in the network to determine where this fact should emerge in the ledger; this consensus is called a block.

I don’t know about you, but after reading these definitions, I still had troubles figuring out what this is all about. Let’s get a bit deeper.

Ordering Facts

Decentralized peer-to-peer networks aren’t fresh. Napster and BitTorrent are P2P networks. Instead of exchanging movies, members of the blockchain network exchange facts. Then what’s the real deal about blockchains?

P2P networks, like other distributed systems, have to solve a very difficult computer science problem: the resolution of conflicts, or reconciliation. Relational databases suggest referential integrity, but there is no such thing in distributed system. If two incompatible facts arrive at the same time, the system must have rules to determine which fact is considered valid.

Take for example the dual spend problem: Alice has Ten$, and she sends twice Ten$ to Bob and Charlie. Who will have the Ten$ eventually? To reaction this question, the best way is to order the facts. If two incompatible facts arrive in the network, the very first one to be recorded wins.

In a P2P network, two facts sent toughly at the same time may arrive in different orders in distant knots. Then how can the entire network agree on the very first fact? To ensure integrity over a P2P network, you need a way to make everyone agree on the ordering of facts. You need a consensus system.

Consensus algorithms for distributed systems are a very active research field. You may have heard of Paxos or Raft algorithms. The blockchain implements another algorithm, the proof-of-work consensus, using blocks.

Blocks

Blocks are a wise trick to order facts in a network of non-trusted peers. The idea is plain: facts are grouped in blocks, and there is only a single chain of blocks, replicated in the entire network. Each block references the previous one. So if fact F is in block 21, and fact E is in block 22, then fact E is considered by the entire network to be posterior to fact F. Before being added to a block, facts are pending, i.e. unconfirmed.

Mining

Some knots in the chain create a fresh local block with pending facts. They challenge to see if their local block is going to become the next block in the chain for the entire network, by rolling dice. If a knot makes a dual six, then it earns the capability to publish their local block, and all facts in this block become confirmed. This block is sent to all other knots in the network. All knots check that the block is correct, add it to their copy of the chain, and attempt to build a fresh block with fresh pending facts.

But knots don’t just roll a duo dice. Blockchain challenges imply rolling a gigantic number of dice. Finding the random key to validate a block is very unlikely, by design. This prevents fraud, and makes the network safe (unless a malicious user wields more than half of the knots in the network). As a consequence, fresh blocks gets published to the chain at a immovable time interval. In Bitcoin, blocks are published every ten minutes on average.

In Bitcoin, the challenge involves a dual SHA-256 hash of a string made of the pending facts, the identifier of the previous block, and a random string. A knot wins if their hash contains at least n leading zeroes.

Number n is adjusted every once in a while to keep block duration immobilized despite variations in the number of knots. This number is called the difficulty. Other blockchain implementations use special hashing technologies that discourage the usage of GPUs (e.g. by requiring large memory transfers).

The process of looking for blocks is called mining. This is because, just like gold mining, block mining brings an economical prize – some form of money. That’s the reason why people who run knots in a blockchain are also called miners.

Note: By default, a knot doesn’t mine – it just receives blocks mined by other knots. It’s a voluntary process to turn a knot into a miner knot.

Money and Cryptocurrencies

Every 2nd, each miner knot in a blockchain tests thousands of random strings to attempt and form a fresh block. So running a miner in the blockchain pumps a thick amount of computer resources (storage and CPU). That’s why you must pay to store facts in a blockchain. Reading facts, on the other mitt, is free: you just need to run your own knot, and you’ll recuperate the entire history of facts issued by all the other knots. So to summarize:

  • Reading data is free
  • Adding facts costs a puny fee
  • Mining a block brings in the money of all the fees of the facts included in the block

We’re not talking about real money here. In fact, each blockchain has its own (crypto-)currency. It’s called Bitcoin (BTC) in the Bitcoin network, Ether (ETH) on the Ethereum network, etc. To make a payment in the Bitcoin network, you must pay a puny fee in Bitcoins – just like you would pay a fee to a bank. But then, where do the very first coins come from?

Miners receive a gratification for keeping the network working and safe. Each time they successfully mine a block, they receive a motionless amount of cryptocurrency. In Bitcoin this gratification is twenty five BTC per block, in Ethereum it’s five ETH per block. That way, the blockchain generates its own money.

Lastly, cryptocurrencies rapidly became convertible to real money. Their facial value is only determined by suggest and request, so it’s subject to speculation. At the time of writing, mining Bitcoins still costs slightly less in energy and hardware than you can earn by selling the coins you discovered in the process. That’s why people add fresh miners every day, hoping to turn electro-therapy into money. But fluctuations in the BTC value make it less and less profitable.

Contracts

So far we’ve mostly mentioned facts storage, but a blockchain can also execute programs. Some blockchains permit each fact to contain a mini program. Such programs are replicated together with the facts, and every knot executes them when receiving the facts. In bitcoin, this can be used to make a transaction conditional: Bob will receive one hundred BTC from Alice if and only if today is February 29th.

Other blockchains permit for more sophisticated contracts. In Ethereum for example, each contract carries a mini-database, and exposes methods to modify the data. As contracts are replicated across all knots, so are their database. Each time a user calls a method on the contract and therefore updates the underlying data, this instruction is replicated and replayed by the entire network. This permits for a distributed consensus on the execution of a promise.

This idea of pre-programed conditions, interfaced with the real world, and broadcasted to everyone, is called a clever contract. A contract is a promise that signing parties agree to make legally-enforceable. A brainy contract is the same, except with the word “technically-“ instead of “legally-“. This liquidates the need for a judge, or any authority acknowledged by both parties.

Imagine that you want to rent your house for a week and $1,000, with a 50% upfront payment. You and the loaner sign a contract, most likely written by a lawyer. You also need a bank to receive the payment. At the beginning of the week, you ask for a $Five,000 deposit; the loaner writes a check for it. At the end of the week, the loaner denies to pay the remaining 50%. You also realize that they broke a window, and that the deposit check refers to an empty account. You’ll need a lawyer to help you enforce the rental contract in a court.

Brainy contracts in a blockchain permit you to get rid of the bank, the lawyer, and the court. Just write a program that defines how much money should be transferred in response to certain conditions:

  • two weeks before beginning of rental: transfer $500 from loaner to proprietor
  • cancellation by the proprietor: transfer $500 from holder to loaner
  • end of the rental period: transfer $500 from loaner to possessor
  • proof of physical degradation after the rental period: transfer $Five,000 from loaner to proprietor

Upload this brainy contract to the blockchain, and you’re all set. At the time defined in the contract, the money transfers will occur. And if the holder can bring a predefined proof of physical degradation, they get the $Five,000 automatically (without any need for a deposit).

You might wonder how to build a proof of physical degradation. That’s where the Internet of Things (IoT) kicks in. In order to interact with the real world, blockchains need sensors and actuators. The Blockchain revolution won’t happen unless the IoT revolution comes very first.

Such applications relying on wise contracts are called Decentralized Apps, or DApps.

Wise contracts naturally extend to clever property, and a lot more brainy things. The thing to recall is that “smart” means “no intermediaries”, or “technically-enforced”. Blockchains are a fresh way to disintermediate businesses – just like the Internet disintermediated music distribution.

What Is A Blockchain, Take Two

In my opinion, the best way to understand the blockchain is to look at it from various angles.

What it does A blockchain permits to securely share and/or process data inbetween numerous parties over a network on non-trusted peers. Data can be anything, but most interesting uses concern information that presently require a trusted third-party to exchange. Examples include money (requires a bank), a proof or property (requires a lawyer), a loan certificate, etc. In essence, the blockchain liquidates the need for a trusted third party.

How it works From a technical point of view, the blockchain is an innovation relying on three concepts: peer-to-peer networks, public-key cryptography, and distributed consensus based on the resolution of a random mathematical challenge. None of there concepts are fresh. It’s their combination that permits a breakthrough in computing. If you don’t understand it all, don’t worry: very few people know enough to be able to develop a blockchain on their own (which is a problem). But not understanding the blockchain doesn’t prevent you from using it, just like you can build web apps without knowing about TCP slow commence and Certificate Authorities.

What it compares to See the blockchain as a database replicated as many times as there are knots and (loosely) synchronized, or as a supercomputer formed by the combination of the CPUs/GPUs of all its knots. You can use this supercomputer to store and process data, just like you would with a remote API. Except you don’t need to own the backend, and you can be sure the data is safe and processed decently by the network.

Practical Implications

Facts stored in the blockchain can’t be lost. They are there forever, replicated as many times as there are knots. Even more, the blockchain doesn’t simply store a final state, it stores the history of all passed states, so that everyone can check the correctness of the final state by replaying the facts from the beginning.

Facts in the blockchain can be trusted, as they are verified by a technically enforceable consensus. Even if the network contains black sheeps, you can trust its judgement as a entire.

Storing data in the blockchain isn’t prompt, as it requires a distributed consensus.

Peak: If you have twenty spare minutes to get a deeper understanding, observe this excellent introduction movie about Bitcoin, which also explains the blockchain:

Why It’s a Big deal

«The Blockchain is the most disruptive technology I have ever seen.» Salim Ismail

«The most interesting intellectual development on the Internet in the last five years.» Julian Assange

«I think the fact that within the Bitcoin universe an algorithm substitutes the functions of [the government] … is actually pretty cool.» Al Gore

These brainy people have seen a meaty potential in the blockchain. It concerns disintermediation. The blockchain can potentially substitute all the intermediaries required to build trust. Let’s see a few example applications, most of which are just proof-of-concepts for now:

  • Monegraph lets authors claim their work, and set their rules (and fares) for use
  • La Zooz is a decentralized Uber. Share your car, find a seat, without Uber taking a fee.
  • Augur is an online bookmaker. Bet on outcomes, and get paid.
  • Storj.io is a peer-to-peer storage system. Rent your unused disk space, or find ultra cheap online storage.
  • Muse is a distributed, open, and translucent database tailored for the music industry
  • Ripple enables low cost cross-border payments for banks

Many successful businesses on the Internet today are intermediaries. Think about Google for a minute: Google managed to become the intermediary inbetween you and the entire Internet. Think about Amazon: they became the intermediary inbetween sellers and buyers for any type of good. That’s why a technology that permits to eliminate intermediaries can potentially disrupt the entire Internet.

Will it benefit to end users, who won’t need third parties to exchange goods and services anymore? It’s far from certain. Internet had the same promise of intense disintermediation. Yet Google built the very first market capitalization worldwide as an intermediary. That’s why it’s crucial to invest in the blockchain quickly, because the winners and losers of the next decade are being born right now.

You Won’t Build Your Own Blockchain

The technology behind the blockchain uses advanced cryptography, custom-made network protocols, and spectacle optimizations. This is all too sophisticated to be redeveloped each time a project needs a blockchain. Fortunately, aside of Bitcoin, there are several open-source blockchain implementations. Here are the most advanced:

  • Ethereum: an open-source blockchain platform by the Ethereum Foundation
  • Hyperledger: another open-source implementation, this time by the Linux Foundation. The very first proposal was published very recently.
  • Eris Industries: Devices helping to manipulate Ethereum, Bitcoin or totally independent blockchains, mostly to build private networks. Their tutorials and explainers are a good beginning point for an overview of the blockchain technology.

The maturity of these implementations varies a lot. If you have to build an application now, we’d advise:

  • Eris for a closed Blockchain, or to detect and play with the technology
  • Ethereum for a collective Blockchain

Also, Bitcoin isn’t a good choice to build an application upon. It was designed for money transactions and nothing else, albeit you can program pseudo-smart contracts (but you have to love assembly). The network presently suffers a serious growth crisis, transactions wait in line for up to one hour to get inserted in a block. Miners often select transactions with the highest fees, so money transfers in Bitcoin become more expensive than they are in a Bank. The developer community is at war, and the speculation on the cryptocurrency makes the face value budge too much.

Numbers

How big are blockchains today? Let’s see some numbers.

Conclusion

The blockchain technology is both intriguing and arousing. Could it be the revolution that gurus predict? Or is it just a speculative bubble based on an impractical idea? After reading a lot on the matter, we couldn’t form a definitive opinion.

When we face uncertainty, we know a excellent way to lift it: attempting. That’s what we determined to do. Read the next post in this series to see what we’ve learned by building a real world app running on the blockchain.

The Blockchain Explained to Web Developers, Part 1: The Theory

The marmelab blog

The blockchain is the fresh hot technology. If you haven’t heard about it, you very likely know Bitcoin. Well, the blockchain is the underlying technology that powers Bitcoin. Experts say the blockchain will cause a revolution similar to what Internet provoked. But what is it truly, and how can it be used to build apps today? This post is the very first in a series of three, explaining the blockchain phenomenon to web developers. We’ll discuss the theory, showcase actual code, and share our learnings, based on a real world project.

To begin, let’s attempt to understand what blockchains indeed are.

What Is A Blockchain, Take One

Albeit the blockchain was created to support Bitcoin, the blockchain concept can be defined regardless of the Bitcoin ecosystem. The literature usually defines a blockchain as goes after:

A blockchain is a ledger of facts, replicated across several computers assembled in a peer-to-peer network. Facts can be anything from monetary transactions to content signature. Members of the network are anonymous individuals called knots. All communication inwards the network takes advantage of cryptography to securely identify the sender and the receiver. When a knot wants to add a fact to the ledger, a consensus forms in the network to determine where this fact should emerge in the ledger; this consensus is called a block.

I don’t know about you, but after reading these definitions, I still had troubles figuring out what this is all about. Let’s get a bit deeper.

Ordering Facts

Decentralized peer-to-peer networks aren’t fresh. Napster and BitTorrent are P2P networks. Instead of exchanging movies, members of the blockchain network exchange facts. Then what’s the real deal about blockchains?

P2P networks, like other distributed systems, have to solve a very difficult computer science problem: the resolution of conflicts, or reconciliation. Relational databases suggest referential integrity, but there is no such thing in distributed system. If two incompatible facts arrive at the same time, the system must have rules to determine which fact is considered valid.

Take for example the dual spend problem: Alice has Ten$, and she sends twice Ten$ to Bob and Charlie. Who will have the Ten$ eventually? To reaction this question, the best way is to order the facts. If two incompatible facts arrive in the network, the very first one to be recorded wins.

In a P2P network, two facts sent toughly at the same time may arrive in different orders in distant knots. Then how can the entire network agree on the very first fact? To assure integrity over a P2P network, you need a way to make everyone agree on the ordering of facts. You need a consensus system.

Consensus algorithms for distributed systems are a very active research field. You may have heard of Paxos or Raft algorithms. The blockchain implements another algorithm, the proof-of-work consensus, using blocks.

Blocks

Blocks are a wise trick to order facts in a network of non-trusted peers. The idea is ordinary: facts are grouped in blocks, and there is only a single chain of blocks, replicated in the entire network. Each block references the previous one. So if fact F is in block 21, and fact E is in block 22, then fact E is considered by the entire network to be posterior to fact F. Before being added to a block, facts are pending, i.e. unconfirmed.

Mining

Some knots in the chain create a fresh local block with pending facts. They rival to see if their local block is going to become the next block in the chain for the entire network, by rolling dice. If a knot makes a dual six, then it earns the capability to publish their local block, and all facts in this block become confirmed. This block is sent to all other knots in the network. All knots check that the block is correct, add it to their copy of the chain, and attempt to build a fresh block with fresh pending facts.

But knots don’t just roll a duo dice. Blockchain challenges imply rolling a phat number of dice. Finding the random key to validate a block is very unlikely, by design. This prevents fraud, and makes the network safe (unless a malicious user possesses more than half of the knots in the network). As a consequence, fresh blocks gets published to the chain at a immovable time interval. In Bitcoin, blocks are published every ten minutes on average.

In Bitcoin, the challenge involves a dual SHA-256 hash of a string made of the pending facts, the identifier of the previous block, and a random string. A knot wins if their hash contains at least n leading zeroes.

Number n is adjusted every once in a while to keep block duration immobile despite variations in the number of knots. This number is called the difficulty. Other blockchain implementations use special hashing technologies that discourage the usage of GPUs (e.g. by requiring large memory transfers).

The process of looking for blocks is called mining. This is because, just like gold mining, block mining brings an economical prize – some form of money. That’s the reason why people who run knots in a blockchain are also called miners.

Note: By default, a knot doesn’t mine – it just receives blocks mined by other knots. It’s a voluntary process to turn a knot into a miner knot.

Money and Cryptocurrencies

Every 2nd, each miner knot in a blockchain tests thousands of random strings to attempt and form a fresh block. So running a miner in the blockchain pumps a gigantic amount of computer resources (storage and CPU). That’s why you must pay to store facts in a blockchain. Reading facts, on the other mitt, is free: you just need to run your own knot, and you’ll recuperate the entire history of facts issued by all the other knots. So to summarize:

  • Reading data is free
  • Adding facts costs a puny fee
  • Mining a block brings in the money of all the fees of the facts included in the block

We’re not talking about real money here. In fact, each blockchain has its own (crypto-)currency. It’s called Bitcoin (BTC) in the Bitcoin network, Ether (ETH) on the Ethereum network, etc. To make a payment in the Bitcoin network, you must pay a petite fee in Bitcoins – just like you would pay a fee to a bank. But then, where do the very first coins come from?

Miners receive a gratification for keeping the network working and safe. Each time they successfully mine a block, they receive a motionless amount of cryptocurrency. In Bitcoin this gratification is twenty five BTC per block, in Ethereum it’s five ETH per block. That way, the blockchain generates its own money.

Lastly, cryptocurrencies rapidly became convertible to real money. Their facial value is only determined by suggest and request, so it’s subject to speculation. At the time of writing, mining Bitcoins still costs slightly less in energy and hardware than you can earn by selling the coins you discovered in the process. That’s why people add fresh miners every day, hoping to turn electrical play into money. But fluctuations in the BTC value make it less and less profitable.

Contracts

So far we’ve mostly mentioned facts storage, but a blockchain can also execute programs. Some blockchains permit each fact to contain a mini program. Such programs are replicated together with the facts, and every knot executes them when receiving the facts. In bitcoin, this can be used to make a transaction conditional: Bob will receive one hundred BTC from Alice if and only if today is February 29th.

Other blockchains permit for more sophisticated contracts. In Ethereum for example, each contract carries a mini-database, and exposes methods to modify the data. As contracts are replicated across all knots, so are their database. Each time a user calls a method on the contract and therefore updates the underlying data, this directive is replicated and replayed by the entire network. This permits for a distributed consensus on the execution of a promise.

This idea of pre-programed conditions, interfaced with the real world, and broadcasted to everyone, is called a brainy contract. A contract is a promise that signing parties agree to make legally-enforceable. A brainy contract is the same, except with the word “technically-“ instead of “legally-“. This liquidates the need for a judge, or any authority acknowledged by both parties.

Imagine that you want to rent your house for a week and $1,000, with a 50% upfront payment. You and the loaner sign a contract, very likely written by a lawyer. You also need a bank to receive the payment. At the beginning of the week, you ask for a $Five,000 deposit; the loaner writes a check for it. At the end of the week, the loaner rejects to pay the remaining 50%. You also realize that they broke a window, and that the deposit check refers to an empty account. You’ll need a lawyer to help you enforce the rental contract in a court.

Brainy contracts in a blockchain permit you to get rid of the bank, the lawyer, and the court. Just write a program that defines how much money should be transferred in response to certain conditions:

  • two weeks before beginning of rental: transfer $500 from loaner to holder
  • cancellation by the proprietor: transfer $500 from possessor to loaner
  • end of the rental period: transfer $500 from loaner to possessor
  • proof of physical degradation after the rental period: transfer $Five,000 from loaner to holder

Upload this brainy contract to the blockchain, and you’re all set. At the time defined in the contract, the money transfers will occur. And if the proprietor can bring a predefined proof of physical degradation, they get the $Five,000 automatically (without any need for a deposit).

You might wonder how to build a proof of physical degradation. That’s where the Internet of Things (IoT) kicks in. In order to interact with the real world, blockchains need sensors and actuators. The Blockchain revolution won’t happen unless the IoT revolution comes very first.

Such applications relying on clever contracts are called Decentralized Apps, or DApps.

Wise contracts naturally extend to wise property, and a lot more wise things. The thing to recall is that “smart” means “no intermediaries”, or “technically-enforced”. Blockchains are a fresh way to disintermediate businesses – just like the Internet disintermediated music distribution.

What Is A Blockchain, Take Two

In my opinion, the best way to understand the blockchain is to look at it from various angles.

What it does A blockchain permits to securely share and/or process data inbetween numerous parties over a network on non-trusted peers. Data can be anything, but most interesting uses concern information that presently require a trusted third-party to exchange. Examples include money (requires a bank), a proof or property (requires a lawyer), a loan certificate, etc. In essence, the blockchain eliminates the need for a trusted third party.

How it works From a technical point of view, the blockchain is an innovation relying on three concepts: peer-to-peer networks, public-key cryptography, and distributed consensus based on the resolution of a random mathematical challenge. None of there concepts are fresh. It’s their combination that permits a breakthrough in computing. If you don’t understand it all, don’t worry: very few people know enough to be able to develop a blockchain on their own (which is a problem). But not understanding the blockchain doesn’t prevent you from using it, just like you can build web apps without knowing about TCP slow commence and Certificate Authorities.

What it compares to See the blockchain as a database replicated as many times as there are knots and (loosely) synchronized, or as a supercomputer formed by the combination of the CPUs/GPUs of all its knots. You can use this supercomputer to store and process data, just like you would with a remote API. Except you don’t need to own the backend, and you can be sure the data is safe and processed decently by the network.

Practical Implications

Facts stored in the blockchain can’t be lost. They are there forever, replicated as many times as there are knots. Even more, the blockchain doesn’t simply store a final state, it stores the history of all passed states, so that everyone can check the correctness of the final state by replaying the facts from the beginning.

Facts in the blockchain can be trusted, as they are verified by a technically enforceable consensus. Even if the network contains black sheeps, you can trust its judgement as a entire.

Storing data in the blockchain isn’t prompt, as it requires a distributed consensus.

Peak: If you have twenty spare minutes to get a deeper understanding, observe this excellent introduction movie about Bitcoin, which also explains the blockchain:

Why It’s a Big deal

«The Blockchain is the most disruptive technology I have ever seen.» Salim Ismail

«The most interesting intellectual development on the Internet in the last five years.» Julian Assange

«I think the fact that within the Bitcoin universe an algorithm substitutes the functions of [the government] … is actually pretty cool.» Al Gore

These brainy people have seen a giant potential in the blockchain. It concerns disintermediation. The blockchain can potentially substitute all the intermediaries required to build trust. Let’s see a few example applications, most of which are just proof-of-concepts for now:

  • Monegraph lets authors claim their work, and set their rules (and fares) for use
  • La Zooz is a decentralized Uber. Share your car, find a seat, without Uber taking a fee.
  • Augur is an online bookmaker. Bet on outcomes, and get paid.
  • Storj.io is a peer-to-peer storage system. Rent your unused disk space, or find ultra cheap online storage.
  • Muse is a distributed, open, and see-through database tailored for the music industry
  • Ripple enables low cost cross-border payments for banks

Many successful businesses on the Internet today are intermediaries. Think about Google for a minute: Google managed to become the intermediary inbetween you and the entire Internet. Think about Amazon: they became the intermediary inbetween sellers and buyers for any type of good. That’s why a technology that permits to eliminate intermediaries can potentially disrupt the entire Internet.

Will it benefit to end users, who won’t need third parties to exchange goods and services anymore? It’s far from certain. Internet had the same promise of strenuous disintermediation. Yet Google built the very first market capitalization worldwide as an intermediary. That’s why it’s crucial to invest in the blockchain quickly, because the winners and losers of the next decade are being born right now.

You Won’t Build Your Own Blockchain

The technology behind the blockchain uses advanced cryptography, custom-made network protocols, and spectacle optimizations. This is all too sophisticated to be redeveloped each time a project needs a blockchain. Fortunately, aside of Bitcoin, there are several open-source blockchain implementations. Here are the most advanced:

  • Ethereum: an open-source blockchain platform by the Ethereum Foundation
  • Hyperledger: another open-source implementation, this time by the Linux Foundation. The very first proposal was published very recently.
  • Eris Industries: Implements helping to manipulate Ethereum, Bitcoin or totally independent blockchains, mostly to build private networks. Their tutorials and explainers are a superb commencing point for an overview of the blockchain technology.

The maturity of these implementations varies a lot. If you have to build an application now, we’d advise:

  • Eris for a closed Blockchain, or to detect and play with the technology
  • Ethereum for a collective Blockchain

Also, Bitcoin isn’t a good choice to build an application upon. It was designed for money transactions and nothing else, albeit you can program pseudo-smart contracts (but you have to love assembly). The network presently suffers a serious growth crisis, transactions wait in line for up to one hour to get inserted in a block. Miners often select transactions with the highest fees, so money transfers in Bitcoin become more expensive than they are in a Bank. The developer community is at war, and the speculation on the cryptocurrency makes the face value stir too much.

Numbers

How big are blockchains today? Let’s see some numbers.

Conclusion

The blockchain technology is both intriguing and arousing. Could it be the revolution that gurus predict? Or is it just a speculative bubble based on an impractical idea? After reading a lot on the matter, we couldn’t form a definitive opinion.

When we face uncertainty, we know a superb way to lift it: attempting. That’s what we determined to do. Read the next post in this series to see what we’ve learned by building a real world app running on the blockchain.

The Blockchain Explained to Web Developers, Part 1: The Theory

The marmelab blog

The blockchain is the fresh hot technology. If you haven’t heard about it, you very likely know Bitcoin. Well, the blockchain is the underlying technology that powers Bitcoin. Experts say the blockchain will cause a revolution similar to what Internet provoked. But what is it truly, and how can it be used to build apps today? This post is the very first in a series of three, explaining the blockchain phenomenon to web developers. We’ll discuss the theory, display actual code, and share our learnings, based on a real world project.

To begin, let’s attempt to understand what blockchains truly are.

What Is A Blockchain, Take One

Albeit the blockchain was created to support Bitcoin, the blockchain concept can be defined regardless of the Bitcoin ecosystem. The literature usually defines a blockchain as goes after:

A blockchain is a ledger of facts, replicated across several computers assembled in a peer-to-peer network. Facts can be anything from monetary transactions to content signature. Members of the network are anonymous individuals called knots. All communication inwards the network takes advantage of cryptography to securely identify the sender and the receiver. When a knot wants to add a fact to the ledger, a consensus forms in the network to determine where this fact should show up in the ledger; this consensus is called a block.

I don’t know about you, but after reading these definitions, I still had troubles figuring out what this is all about. Let’s get a bit deeper.

Ordering Facts

Decentralized peer-to-peer networks aren’t fresh. Napster and BitTorrent are P2P networks. Instead of exchanging movies, members of the blockchain network exchange facts. Then what’s the real deal about blockchains?

P2P networks, like other distributed systems, have to solve a very difficult computer science problem: the resolution of conflicts, or reconciliation. Relational databases suggest referential integrity, but there is no such thing in distributed system. If two incompatible facts arrive at the same time, the system must have rules to determine which fact is considered valid.

Take for example the dual spend problem: Alice has Ten$, and she sends twice Ten$ to Bob and Charlie. Who will have the Ten$ eventually? To response this question, the best way is to order the facts. If two incompatible facts arrive in the network, the very first one to be recorded wins.

In a P2P network, two facts sent toughly at the same time may arrive in different orders in distant knots. Then how can the entire network agree on the very first fact? To ensure integrity over a P2P network, you need a way to make everyone agree on the ordering of facts. You need a consensus system.

Consensus algorithms for distributed systems are a very active research field. You may have heard of Paxos or Raft algorithms. The blockchain implements another algorithm, the proof-of-work consensus, using blocks.

Blocks

Blocks are a wise trick to order facts in a network of non-trusted peers. The idea is elementary: facts are grouped in blocks, and there is only a single chain of blocks, replicated in the entire network. Each block references the previous one. So if fact F is in block 21, and fact E is in block 22, then fact E is considered by the entire network to be posterior to fact F. Before being added to a block, facts are pending, i.e. unconfirmed.

Mining

Some knots in the chain create a fresh local block with pending facts. They contest to see if their local block is going to become the next block in the chain for the entire network, by rolling dice. If a knot makes a dual six, then it earns the capability to publish their local block, and all facts in this block become confirmed. This block is sent to all other knots in the network. All knots check that the block is correct, add it to their copy of the chain, and attempt to build a fresh block with fresh pending facts.

But knots don’t just roll a duo dice. Blockchain challenges imply rolling a yam-sized number of dice. Finding the random key to validate a block is very unlikely, by design. This prevents fraud, and makes the network safe (unless a malicious user wields more than half of the knots in the network). As a consequence, fresh blocks gets published to the chain at a motionless time interval. In Bitcoin, blocks are published every ten minutes on average.

In Bitcoin, the challenge involves a dual SHA-256 hash of a string made of the pending facts, the identifier of the previous block, and a random string. A knot wins if their hash contains at least n leading zeroes.

Number n is adjusted every once in a while to keep block duration immobilized despite variations in the number of knots. This number is called the difficulty. Other blockchain implementations use special hashing technologies that discourage the usage of GPUs (e.g. by requiring large memory transfers).

The process of looking for blocks is called mining. This is because, just like gold mining, block mining brings an economical prize – some form of money. That’s the reason why people who run knots in a blockchain are also called miners.

Note: By default, a knot doesn’t mine – it just receives blocks mined by other knots. It’s a voluntary process to turn a knot into a miner knot.

Money and Cryptocurrencies

Every 2nd, each miner knot in a blockchain tests thousands of random strings to attempt and form a fresh block. So running a miner in the blockchain pumps a enormous amount of computer resources (storage and CPU). That’s why you must pay to store facts in a blockchain. Reading facts, on the other mitt, is free: you just need to run your own knot, and you’ll recuperate the entire history of facts issued by all the other knots. So to summarize:

  • Reading data is free
  • Adding facts costs a petite fee
  • Mining a block brings in the money of all the fees of the facts included in the block

We’re not talking about real money here. In fact, each blockchain has its own (crypto-)currency. It’s called Bitcoin (BTC) in the Bitcoin network, Ether (ETH) on the Ethereum network, etc. To make a payment in the Bitcoin network, you must pay a petite fee in Bitcoins – just like you would pay a fee to a bank. But then, where do the very first coins come from?

Miners receive a gratification for keeping the network working and safe. Each time they successfully mine a block, they receive a stationary amount of cryptocurrency. In Bitcoin this gratification is twenty five BTC per block, in Ethereum it’s five ETH per block. That way, the blockchain generates its own money.

Lastly, cryptocurrencies rapidly became convertible to real money. Their facial value is only determined by suggest and request, so it’s subject to speculation. At the time of writing, mining Bitcoins still costs slightly less in energy and hardware than you can earn by selling the coins you discovered in the process. That’s why people add fresh miners every day, hoping to turn tens unit into money. But fluctuations in the BTC value make it less and less profitable.

Contracts

So far we’ve mostly mentioned facts storage, but a blockchain can also execute programs. Some blockchains permit each fact to contain a mini program. Such programs are replicated together with the facts, and every knot executes them when receiving the facts. In bitcoin, this can be used to make a transaction conditional: Bob will receive one hundred BTC from Alice if and only if today is February 29th.

Other blockchains permit for more sophisticated contracts. In Ethereum for example, each contract carries a mini-database, and exposes methods to modify the data. As contracts are replicated across all knots, so are their database. Each time a user calls a method on the contract and therefore updates the underlying data, this instruction is replicated and replayed by the entire network. This permits for a distributed consensus on the execution of a promise.

This idea of pre-programed conditions, interfaced with the real world, and broadcasted to everyone, is called a wise contract. A contract is a promise that signing parties agree to make legally-enforceable. A wise contract is the same, except with the word “technically-“ instead of “legally-“. This eliminates the need for a judge, or any authority acknowledged by both parties.

Imagine that you want to rent your house for a week and $1,000, with a 50% upfront payment. You and the loaner sign a contract, most likely written by a lawyer. You also need a bank to receive the payment. At the beginning of the week, you ask for a $Five,000 deposit; the loaner writes a check for it. At the end of the week, the loaner denies to pay the remaining 50%. You also realize that they broke a window, and that the deposit check refers to an empty account. You’ll need a lawyer to help you enforce the rental contract in a court.

Wise contracts in a blockchain permit you to get rid of the bank, the lawyer, and the court. Just write a program that defines how much money should be transferred in response to certain conditions:

  • two weeks before beginning of rental: transfer $500 from loaner to proprietor
  • cancellation by the possessor: transfer $500 from possessor to loaner
  • end of the rental period: transfer $500 from loaner to possessor
  • proof of physical degradation after the rental period: transfer $Five,000 from loaner to holder

Upload this clever contract to the blockchain, and you’re all set. At the time defined in the contract, the money transfers will occur. And if the possessor can bring a predefined proof of physical degradation, they get the $Five,000 automatically (without any need for a deposit).

You might wonder how to build a proof of physical degradation. That’s where the Internet of Things (IoT) kicks in. In order to interact with the real world, blockchains need sensors and actuators. The Blockchain revolution won’t happen unless the IoT revolution comes very first.

Such applications relying on clever contracts are called Decentralized Apps, or DApps.

Wise contracts naturally extend to brainy property, and a lot more wise things. The thing to recall is that “smart” means “no intermediaries”, or “technically-enforced”. Blockchains are a fresh way to disintermediate businesses – just like the Internet disintermediated music distribution.

What Is A Blockchain, Take Two

In my opinion, the best way to understand the blockchain is to look at it from various angles.

What it does A blockchain permits to securely share and/or process data inbetween numerous parties over a network on non-trusted peers. Data can be anything, but most interesting uses concern information that presently require a trusted third-party to exchange. Examples include money (requires a bank), a proof or property (requires a lawyer), a loan certificate, etc. In essence, the blockchain eliminates the need for a trusted third party.

How it works From a technical point of view, the blockchain is an innovation relying on three concepts: peer-to-peer networks, public-key cryptography, and distributed consensus based on the resolution of a random mathematical challenge. None of there concepts are fresh. It’s their combination that permits a breakthrough in computing. If you don’t understand it all, don’t worry: very few people know enough to be able to develop a blockchain on their own (which is a problem). But not understanding the blockchain doesn’t prevent you from using it, just like you can build web apps without knowing about TCP slow begin and Certificate Authorities.

What it compares to See the blockchain as a database replicated as many times as there are knots and (loosely) synchronized, or as a supercomputer formed by the combination of the CPUs/GPUs of all its knots. You can use this supercomputer to store and process data, just like you would with a remote API. Except you don’t need to own the backend, and you can be sure the data is safe and processed decently by the network.

Practical Implications

Facts stored in the blockchain can’t be lost. They are there forever, replicated as many times as there are knots. Even more, the blockchain doesn’t simply store a final state, it stores the history of all passed states, so that everyone can check the correctness of the final state by replaying the facts from the beginning.

Facts in the blockchain can be trusted, as they are verified by a technically enforceable consensus. Even if the network contains black sheeps, you can trust its judgement as a entire.

Storing data in the blockchain isn’t rapid, as it requires a distributed consensus.

Peak: If you have twenty spare minutes to get a deeper understanding, see this excellent introduction movie about Bitcoin, which also explains the blockchain:

Why It’s a Big deal

«The Blockchain is the most disruptive technology I have ever seen.» Salim Ismail

«The most interesting intellectual development on the Internet in the last five years.» Julian Assange

«I think the fact that within the Bitcoin universe an algorithm substitutes the functions of [the government] … is actually pretty cool.» Al Gore

These clever people have seen a enormous potential in the blockchain. It concerns disintermediation. The blockchain can potentially substitute all the intermediaries required to build trust. Let’s see a few example applications, most of which are just proof-of-concepts for now:

  • Monegraph lets authors claim their work, and set their rules (and fares) for use
  • La Zooz is a decentralized Uber. Share your car, find a seat, without Uber taking a fee.
  • Augur is an online bookmaker. Bet on outcomes, and get paid.
  • Storj.io is a peer-to-peer storage system. Rent your unused disk space, or find ultra cheap online storage.
  • Muse is a distributed, open, and semitransparent database tailored for the music industry
  • Ripple enables low cost cross-border payments for banks

Many successful businesses on the Internet today are intermediaries. Think about Google for a minute: Google managed to become the intermediary inbetween you and the entire Internet. Think about Amazon: they became the intermediary inbetween sellers and buyers for any type of good. That’s why a technology that permits to liquidate intermediaries can potentially disrupt the entire Internet.

Will it benefit to end users, who won’t need third parties to exchange goods and services anymore? It’s far from certain. Internet had the same promise of mighty disintermediation. Yet Google built the very first market capitalization worldwide as an intermediary. That’s why it’s crucial to invest in the blockchain quickly, because the winners and losers of the next decade are being born right now.

You Won’t Build Your Own Blockchain

The technology behind the blockchain uses advanced cryptography, custom-built network protocols, and spectacle optimizations. This is all too sophisticated to be redeveloped each time a project needs a blockchain. Fortunately, aside of Bitcoin, there are several open-source blockchain implementations. Here are the most advanced:

  • Ethereum: an open-source blockchain platform by the Ethereum Foundation
  • Hyperledger: another open-source implementation, this time by the Linux Foundation. The very first proposal was published very recently.
  • Eris Industries: Devices helping to manipulate Ethereum, Bitcoin or totally independent blockchains, mostly to build private networks. Their tutorials and explainers are a excellent kicking off point for an overview of the blockchain technology.

The maturity of these implementations varies a lot. If you have to build an application now, we’d advise:

  • Eris for a closed Blockchain, or to detect and play with the technology
  • Ethereum for a collective Blockchain

Also, Bitcoin isn’t a good choice to build an application upon. It was designed for money transactions and nothing else, albeit you can program pseudo-smart contracts (but you have to love assembly). The network presently suffers a serious growth crisis, transactions wait in line for up to one hour to get inserted in a block. Miners often select transactions with the highest fees, so money transfers in Bitcoin become more expensive than they are in a Bank. The developer community is at war, and the speculation on the cryptocurrency makes the face value stir too much.

Numbers

How big are blockchains today? Let’s see some numbers.

Conclusion

The blockchain technology is both intriguing and titillating. Could it be the revolution that gurus predict? Or is it just a speculative bubble based on an impractical idea? After reading a lot on the matter, we couldn’t form a definitive opinion.

When we face uncertainty, we know a fine way to lift it: attempting. That’s what we determined to do. Read the next post in this series to see what we’ve learned by building a real world app running on the blockchain.

The Blockchain Explained to Web Developers, Part 1: The Theory

The marmelab blog

The blockchain is the fresh hot technology. If you haven’t heard about it, you very likely know Bitcoin. Well, the blockchain is the underlying technology that powers Bitcoin. Experts say the blockchain will cause a revolution similar to what Internet provoked. But what is it indeed, and how can it be used to build apps today? This post is the very first in a series of three, explaining the blockchain phenomenon to web developers. We’ll discuss the theory, display actual code, and share our learnings, based on a real world project.

To begin, let’s attempt to understand what blockchains indeed are.

What Is A Blockchain, Take One

Albeit the blockchain was created to support Bitcoin, the blockchain concept can be defined regardless of the Bitcoin ecosystem. The literature usually defines a blockchain as goes after:

A blockchain is a ledger of facts, replicated across several computers assembled in a peer-to-peer network. Facts can be anything from monetary transactions to content signature. Members of the network are anonymous individuals called knots. All communication inwards the network takes advantage of cryptography to securely identify the sender and the receiver. When a knot wants to add a fact to the ledger, a consensus forms in the network to determine where this fact should emerge in the ledger; this consensus is called a block.

I don’t know about you, but after reading these definitions, I still had troubles figuring out what this is all about. Let’s get a bit deeper.

Ordering Facts

Decentralized peer-to-peer networks aren’t fresh. Napster and BitTorrent are P2P networks. Instead of exchanging movies, members of the blockchain network exchange facts. Then what’s the real deal about blockchains?

P2P networks, like other distributed systems, have to solve a very difficult computer science problem: the resolution of conflicts, or reconciliation. Relational databases suggest referential integrity, but there is no such thing in distributed system. If two incompatible facts arrive at the same time, the system must have rules to determine which fact is considered valid.

Take for example the dual spend problem: Alice has Ten$, and she sends twice Ten$ to Bob and Charlie. Who will have the Ten$ eventually? To reaction this question, the best way is to order the facts. If two incompatible facts arrive in the network, the very first one to be recorded wins.

In a P2P network, two facts sent toughly at the same time may arrive in different orders in distant knots. Then how can the entire network agree on the very first fact? To ensure integrity over a P2P network, you need a way to make everyone agree on the ordering of facts. You need a consensus system.

Consensus algorithms for distributed systems are a very active research field. You may have heard of Paxos or Raft algorithms. The blockchain implements another algorithm, the proof-of-work consensus, using blocks.

Blocks

Blocks are a clever trick to order facts in a network of non-trusted peers. The idea is ordinary: facts are grouped in blocks, and there is only a single chain of blocks, replicated in the entire network. Each block references the previous one. So if fact F is in block 21, and fact E is in block 22, then fact E is considered by the entire network to be posterior to fact F. Before being added to a block, facts are pending, i.e. unconfirmed.

Mining

Some knots in the chain create a fresh local block with pending facts. They challenge to see if their local block is going to become the next block in the chain for the entire network, by rolling dice. If a knot makes a dual six, then it earns the capability to publish their local block, and all facts in this block become confirmed. This block is sent to all other knots in the network. All knots check that the block is correct, add it to their copy of the chain, and attempt to build a fresh block with fresh pending facts.

But knots don’t just roll a duo dice. Blockchain challenges imply rolling a thick number of dice. Finding the random key to validate a block is very unlikely, by design. This prevents fraud, and makes the network safe (unless a malicious user wields more than half of the knots in the network). As a consequence, fresh blocks gets published to the chain at a immobile time interval. In Bitcoin, blocks are published every ten minutes on average.

In Bitcoin, the challenge involves a dual SHA-256 hash of a string made of the pending facts, the identifier of the previous block, and a random string. A knot wins if their hash contains at least n leading zeroes.

Number n is adjusted every once in a while to keep block duration immobile despite variations in the number of knots. This number is called the difficulty. Other blockchain implementations use special hashing technologies that discourage the usage of GPUs (e.g. by requiring large memory transfers).

The process of looking for blocks is called mining. This is because, just like gold mining, block mining brings an economical prize – some form of money. That’s the reason why people who run knots in a blockchain are also called miners.

Note: By default, a knot doesn’t mine – it just receives blocks mined by other knots. It’s a voluntary process to turn a knot into a miner knot.

Money and Cryptocurrencies

Every 2nd, each miner knot in a blockchain tests thousands of random strings to attempt and form a fresh block. So running a miner in the blockchain pumps a giant amount of computer resources (storage and CPU). That’s why you must pay to store facts in a blockchain. Reading facts, on the other forearm, is free: you just need to run your own knot, and you’ll recuperate the entire history of facts issued by all the other knots. So to summarize:

  • Reading data is free
  • Adding facts costs a puny fee
  • Mining a block brings in the money of all the fees of the facts included in the block

We’re not talking about real money here. In fact, each blockchain has its own (crypto-)currency. It’s called Bitcoin (BTC) in the Bitcoin network, Ether (ETH) on the Ethereum network, etc. To make a payment in the Bitcoin network, you must pay a puny fee in Bitcoins – just like you would pay a fee to a bank. But then, where do the very first coins come from?

Miners receive a gratification for keeping the network working and safe. Each time they successfully mine a block, they receive a immobile amount of cryptocurrency. In Bitcoin this gratification is twenty five BTC per block, in Ethereum it’s five ETH per block. That way, the blockchain generates its own money.

Lastly, cryptocurrencies rapidly became convertible to real money. Their facial value is only determined by suggest and request, so it’s subject to speculation. At the time of writing, mining Bitcoins still costs slightly less in energy and hardware than you can earn by selling the coins you discovered in the process. That’s why people add fresh miners every day, hoping to turn electro-therapy into money. But fluctuations in the BTC value make it less and less profitable.

Contracts

So far we’ve mostly mentioned facts storage, but a blockchain can also execute programs. Some blockchains permit each fact to contain a mini program. Such programs are replicated together with the facts, and every knot executes them when receiving the facts. In bitcoin, this can be used to make a transaction conditional: Bob will receive one hundred BTC from Alice if and only if today is February 29th.

Other blockchains permit for more sophisticated contracts. In Ethereum for example, each contract carries a mini-database, and exposes methods to modify the data. As contracts are replicated across all knots, so are their database. Each time a user calls a method on the contract and therefore updates the underlying data, this guideline is replicated and replayed by the entire network. This permits for a distributed consensus on the execution of a promise.

This idea of pre-programed conditions, interfaced with the real world, and broadcasted to everyone, is called a brainy contract. A contract is a promise that signing parties agree to make legally-enforceable. A brainy contract is the same, except with the word “technically-“ instead of “legally-“. This liquidates the need for a judge, or any authority acknowledged by both parties.

Imagine that you want to rent your house for a week and $1,000, with a 50% upfront payment. You and the loaner sign a contract, most likely written by a lawyer. You also need a bank to receive the payment. At the beginning of the week, you ask for a $Five,000 deposit; the loaner writes a check for it. At the end of the week, the loaner turns down to pay the remaining 50%. You also realize that they broke a window, and that the deposit check refers to an empty account. You’ll need a lawyer to help you enforce the rental contract in a court.

Clever contracts in a blockchain permit you to get rid of the bank, the lawyer, and the court. Just write a program that defines how much money should be transferred in response to certain conditions:

  • two weeks before beginning of rental: transfer $500 from loaner to proprietor
  • cancellation by the proprietor: transfer $500 from holder to loaner
  • end of the rental period: transfer $500 from loaner to holder
  • proof of physical degradation after the rental period: transfer $Five,000 from loaner to proprietor

Upload this clever contract to the blockchain, and you’re all set. At the time defined in the contract, the money transfers will occur. And if the holder can bring a predefined proof of physical degradation, they get the $Five,000 automatically (without any need for a deposit).

You might wonder how to build a proof of physical degradation. That’s where the Internet of Things (IoT) kicks in. In order to interact with the real world, blockchains need sensors and actuators. The Blockchain revolution won’t happen unless the IoT revolution comes very first.

Such applications relying on brainy contracts are called Decentralized Apps, or DApps.

Brainy contracts naturally extend to brainy property, and a lot more wise things. The thing to reminisce is that “smart” means “no intermediaries”, or “technically-enforced”. Blockchains are a fresh way to disintermediate businesses – just like the Internet disintermediated music distribution.

What Is A Blockchain, Take Two

In my opinion, the best way to understand the blockchain is to look at it from various angles.

What it does A blockchain permits to securely share and/or process data inbetween numerous parties over a network on non-trusted peers. Data can be anything, but most interesting uses concern information that presently require a trusted third-party to exchange. Examples include money (requires a bank), a proof or property (requires a lawyer), a loan certificate, etc. In essence, the blockchain eliminates the need for a trusted third party.

How it works From a technical point of view, the blockchain is an innovation relying on three concepts: peer-to-peer networks, public-key cryptography, and distributed consensus based on the resolution of a random mathematical challenge. None of there concepts are fresh. It’s their combination that permits a breakthrough in computing. If you don’t understand it all, don’t worry: very few people know enough to be able to develop a blockchain on their own (which is a problem). But not understanding the blockchain doesn’t prevent you from using it, just like you can build web apps without knowing about TCP slow embark and Certificate Authorities.

What it compares to See the blockchain as a database replicated as many times as there are knots and (loosely) synchronized, or as a supercomputer formed by the combination of the CPUs/GPUs of all its knots. You can use this supercomputer to store and process data, just like you would with a remote API. Except you don’t need to own the backend, and you can be sure the data is safe and processed decently by the network.

Practical Implications

Facts stored in the blockchain can’t be lost. They are there forever, replicated as many times as there are knots. Even more, the blockchain doesn’t simply store a final state, it stores the history of all passed states, so that everyone can check the correctness of the final state by replaying the facts from the beginning.

Facts in the blockchain can be trusted, as they are verified by a technically enforceable consensus. Even if the network contains black sheeps, you can trust its judgement as a entire.

Storing data in the blockchain isn’t prompt, as it requires a distributed consensus.

Peak: If you have twenty spare minutes to get a deeper understanding, witness this excellent introduction movie about Bitcoin, which also explains the blockchain:

Why It’s a Big deal

«The Blockchain is the most disruptive technology I have ever seen.» Salim Ismail

«The most interesting intellectual development on the Internet in the last five years.» Julian Assange

«I think the fact that within the Bitcoin universe an algorithm substitutes the functions of [the government] … is actually pretty cool.» Al Gore

These brainy people have seen a big potential in the blockchain. It concerns disintermediation. The blockchain can potentially substitute all the intermediaries required to build trust. Let’s see a few example applications, most of which are just proof-of-concepts for now:

  • Monegraph lets authors claim their work, and set their rules (and fares) for use
  • La Zooz is a decentralized Uber. Share your car, find a seat, without Uber taking a fee.
  • Augur is an online bookmaker. Bet on outcomes, and get paid.
  • Storj.io is a peer-to-peer storage system. Rent your unused disk space, or find ultra cheap online storage.
  • Muse is a distributed, open, and see-through database tailored for the music industry
  • Ripple enables low cost cross-border payments for banks

Many successful businesses on the Internet today are intermediaries. Think about Google for a minute: Google managed to become the intermediary inbetween you and the entire Internet. Think about Amazon: they became the intermediary inbetween sellers and buyers for any type of good. That’s why a technology that permits to eliminate intermediaries can potentially disrupt the entire Internet.

Will it benefit to end users, who won’t need third parties to exchange goods and services anymore? It’s far from certain. Internet had the same promise of intense disintermediation. Yet Google built the very first market capitalization worldwide as an intermediary. That’s why it’s crucial to invest in the blockchain quickly, because the winners and losers of the next decade are being born right now.

You Won’t Build Your Own Blockchain

The technology behind the blockchain uses advanced cryptography, custom-made network protocols, and spectacle optimizations. This is all too sophisticated to be redeveloped each time a project needs a blockchain. Fortunately, aside of Bitcoin, there are several open-source blockchain implementations. Here are the most advanced:

  • Ethereum: an open-source blockchain platform by the Ethereum Foundation
  • Hyperledger: another open-source implementation, this time by the Linux Foundation. The very first proposal was published very recently.
  • Eris Industries: Devices helping to manipulate Ethereum, Bitcoin or totally independent blockchains, mostly to build private networks. Their tutorials and explainers are a superb commencing point for an overview of the blockchain technology.

The maturity of these implementations varies a lot. If you have to build an application now, we’d advise:

  • Eris for a closed Blockchain, or to detect and play with the technology
  • Ethereum for a collective Blockchain

Also, Bitcoin isn’t a good choice to build an application upon. It was designed for money transactions and nothing else, albeit you can program pseudo-smart contracts (but you have to love assembly). The network presently suffers a serious growth crisis, transactions wait in line for up to one hour to get inserted in a block. Miners often select transactions with the highest fees, so money transfers in Bitcoin become more expensive than they are in a Bank. The developer community is at war, and the speculation on the cryptocurrency makes the face value stir too much.

Numbers

How big are blockchains today? Let’s see some numbers.

Conclusion

The blockchain technology is both intriguing and arousing. Could it be the revolution that gurus predict? Or is it just a speculative bubble based on an impractical idea? After reading a lot on the matter, we couldn’t form a definitive opinion.

When we face uncertainty, we know a superb way to lift it: attempting. That’s what we determined to do. Read the next post in this series to see what we’ve learned by building a real world app running on the blockchain.

Related video:

Leave a Reply

Your email address will not be published. Required fields are marked *