Create your Blockchain DApp with Ethereum and VueJS – Part 1

In this first part of the tutorial we are going to create the smart contract that handles the registration of users; then we are going to deploy the smart contract to the blockchain using Truffle.

If you missed the introduction and you want to know what this tutorial is about, please read the intro.

This part of tutorial is divided into three sections:

  1. Set up of the truffle environment.
  2. Smart contract development.
  3. Deploy the smart contract to the blockchain.

Note before you start: if you are using Windows you must use Power Shell as terminal.

Set up of the truffle environment

First let’s create the project folder called ethereum-vuejs-dapp, then open the terminal in the folder just created and run the following command:

$ truffle init

This command initializes the truffle project and creates the following items:

  • contracts: folder containing the smart contracts written in Solidity.
  • migrations: folder containing the files that take care of the deployment.
  • test: folder containing the files for testing the smart contracts.
  • truffle.js: file that contains the list of blockchain networks where you can deploy your contracts.

Let’s add the details of our blockchain network to the file truffle.js. So first start Ganache and, once it runs, check the host and the port as shown below.

Ethereum Vue - Ganache host and port settings

Now paste the following code in truffle.js:

module.exports = {
  networks: {
    ganache: {
      host: "127.0.0.1",
      port: 7545,
      network_id: "*"
    }
  }
};

IMPORTANT: make sure that the host and the port of the code pasted in truffle.js match with the settings displayed in Ganache.

Smart contract development

As described in the introduction, the main features of our dApp are:

  • Let users resister their profiles.
  • The owner of a profile is the only person who can edit his own information.

The following information of a user’s profile is going to be stored in the blockchain:

  • Name of the owner.
  • Status.
  • When the profile has been created and updated.

What we need is to store the list of the users and associate each user with an account address (or wallet address).

The smart contract must provide a set of functions that:

  • Let the user register his profile.
  • Let the owner of a profile update his details.
  • Get the list of users and their details.
  • Check if the user is already registered.

Below is the code of the smart contract (you can find it on GitHub as well).

Deploy the smart contract to the blockchain

It’s time to deploy the smart contract to the blockchain! Make sure that your blockchain is running and the file truffle.js is properly set as explained before.

Go to the folder migration and create a file called 2_migrate_users.js.
The migration filename has a number as prefix and a description as suffix. The numbered prefix is required in order to record whether the migration ran successfully and the suffix just describes what the file is about.

Copy and paste the following code inside the file 2_migrate_users.js:

var Users = artifacts.require("./Users.sol");

  deployer.deploy(Users);
};

Now let’s open the terminal in the project folder ethereum-vuejs-dapp and run the command:

$ truffle console ––network ganache

Once the truffle console is running, type the following command:

>> migrate ––reset ––compile-all

This command compiles all smart contracts and deploys the smart contracts to the blockchain.

If everything went fine, on the console you should see a message as follows:

Compiling .\contracts\Migrations.sol...
Compiling .\contracts\Users.sol...
Writing artifacts to .\build\contracts

Using network 'ganache'.

Running migration: 1_initial_migration.js
  Replacing Migrations...
  ... 0x18edd24941e9b7edfae4966af544d5413e31622da90cecae2d3153635a7ffba2
  Migrations: 0xcac26201ab3b38d2f0f9b56f81a8897dfe036da6
Saving successful migration to network...
  ... 0x125c70f37e143b13acb4827dda16e8571758402db81c08a3a2ae27573910105f
Saving artifacts...
Running migration: 2_migrate_users.js
  Replacing Users...
  ... 0x043c2cf363da321b8a1ec06672f12fd794bf894342fa51100250bc6975806385
  Users: 0x782b9ce19fe792ed3c4ccbfb439ab59ddc5369f2
Saving successful migration to network...
  ... 0x9e56386f94093c4f56f6b84190503376363f15a6d16661e7bfaa8fefe1b4be1f
Saving artifacts...
truffle(ganache)>

After the deployment you will see on Ganache some new transactions in the transaction list.

Ethereum Vue - Ganache transactions

In the second part of the tutorial we will build the dApp interface using Vue JS and interact with the smart contracts through the interface.

The second part of the tutorial is on the way… see you soon!

___________

Read the original article at www.danielefavi.com

___________

Create your Blockchain DApp with Ethereum and VueJS – Intro

This is a simple decentralized application built using Ethereum blockchain and VueJS for the front-end. This DApp example lets the users store their name and status on the blockchain.

Ethereum Vue JS DApp Screenshot - User list
Ethereum Vue JS DApp Screenshot - User Profile

Brief description

The DApp allows users to register their name and status on the blockchain. The user’s profile is associated with an account address (or wallet address).

The owner of the profile is the only person who can modify his own data. This will give you a technical explanation of what it means when the user is in control of his own data (just like Facebook… sarcasm!).
The smart contract is designed to give the user control of his own information and not even the creator of the smart contract can control any data.

This tutorial is split in two parts:

  • PART 1 (coming soon): set up of the truffle environment, brief explanation of the smart contract and deploy the smart contract to the blockchain.
  • PART 2 (coming soon): set up Vue JS and explanation of the project structure.

Prerequisite

Quick Start

  1. Download the project and decompress it into the folder ~/ethereum-vuejs-dapp (or wherever you want).
  2. Start Ganache (or your private blockchain).
  3. Open the terminal (if you are using Windows you must use the Power Shell) in the folder ~/ethereum-vuejs-dapp and run the command:
    $ truffle console ––network ganache
  4. If ganache is running you should be inside the truffle console; now run the following command in the truffle console:
    > migrate ––reset ––compile-all
  5. If the migration was successful, copy the content of the file ~/ethereum-vuejs-dapp/build/contracts/Users.json into ~/ethereum-vuejs-dapp/app-users/src/assets/UsersContract.json
  6. Open another terminal in the folder ~/ethereum-vuejs-dapp/app-users and run the command:
    $ npm install
  7. Once all the dependencies are installed run the command:
    $ npm run dev

    If everything went fine you should see this message:

    Your application is running here: http://localhost:8080
  8. Open the browser and go to URL above to try the DApp!

NOTE: if you want to try to add more profiles you have to install metamask in your browser, then import the accounts into metamask and finally change account on metamask in order to register a new profile.

___________

Read the original article at www.danielefavi.com

___________

What is a fork? Why is it dangerous?

Often a blockchain can have some flaws, bugs or it just needs improvements. To fix those vulnerabilities the blockchain has to be forked.
A fork rewrites the rules which a full node must follow in order to consider a block valid. A full node can decide either to accept the new rule (updating its software) or reject it.

If some nodes choose to support the fork while others choose not to do so, then a blockchain fork might happen: in this case the blockchain splits up in two different branches.
The two blockchains share the same chunk of chain from the genesis block to a certain block before the divergence.

There are two kinds of fork: hard fork and soft fork. Both hard and soft forks can cause a blockchain fork.

When a fork happens, the choice made by the community is crucial because it can weaken the blockchain. When the community of the full nodes split then each branch of the blockchain created by the split will have less hashpower: so both blockchains become weak to a 51% attack.
If the community cannot make a strong decision about the fork, then also the community itself can become weak; this could lead to bad consequences regarding the trust on the platform: the reliability of the platform will decrease and the interest of investors and developers will move away.

Let’s take some real examples.
Before August 2017, the bitcoin community was discussing how to improve the bitcoin transaction performance (aka scalability). The community had two different opinions:

  • to increase the block size to 8MB
  • to store the data within a block with a method called SegWit [1]

In August 2017 the bitcoin blockchain split up in two branches: Bitcoin Cash [2] with an increased block size to 8M and Bitcoin that uses SegWit.

Another example.
In 2016 an attacker managed to use the vulnerability of ethereum security for his own good and many people lost their investments [3]. Within the ethereum community there were two ways to solve this problem:

  • to revert the transactions due to the flaw
  • not to make any changes, keeping the original protocol

In July 2016 the ethereum blockchain forked into Ethereum (with the flaw fixed) and Ethereum Classic (original protocol) [3].

What is the difference between hard fork and soft fork?

Soft fork: a block created with a new rule is considered valid also by the old rule; this means a soft fork is forward compatible (in other words the blocks created with the new rule are compatible with the blocks created with the old rule but not the other way around).
Example: you have a blockchain where each block has a maximum size of 2MB; then you apply a soft fork to reduce the maximum size of the block to 1MB. The old rule will consider the blocks created with the new rule valid since they do not exceed the 2MB maximum size.

Hard fork: blocks created with the new rule are not considered valid by the old rule; this means that a hard fork is not forward compatible (the blocks created with the new rule are not compatible with the blocks created with the old rule).
Example: a blockchain has the block size limit of 1MB; then a hard fork is applied in order to increase the block size limit to 3MB. The blocks created with the hard fork rule are not compatible with the old rule since the 3MB limit exceeded the 1MB limit but the old blocks are still compatible with the new rule.

SOFT FORK: how does the blockchain fork happen?

If the hashpower of the full nodes that accepted the soft fork is 51% or more, then there will be no blockchain fork.

If less than 51% of the hashpower comes from the full nodes which do not support the soft fork then the blockchain will split: a branch of blocks will be created by the nodes following the old rule (since the old rule is not compatible with the new rule) and another branch of blocks by the nodes following the new rule.

If the full nodes start upgrading their software to the soft fork and the hashing power supporting the soft fork is more than 51%, then all the network (both supporting and not supporting the fork) will consider the blockchain branch created with the soft fork rule as true.
This is possible because the branch created with the soft fork became longer than the other branch; since the soft fork branch is compatible with the old rule, all the network will consider the longer branch valid and there will be one single branch.

HARD FORK: how does the blockchain fork happen?

Here we have to consider two cases.

Case 1: 51% of the hashpower of the network do not update their software to the hard fork.
Since the blocks created with the old rule are compatible with the hard fork and the blockchain branch supported by the old rule grow faster (because it has more hashpower), then the blockchain branch supported by the old rule is considered valid and there is no blockchain split.

Case 2: 51% of the full nodes update their software to the hard fork but a smaller percentage is still using the old rule.
In this case the blockchain will split: since the blocks created with the hard fork rule are not compatible with the old rule then there will be a branch supported by the nodes following the old rule and a branch supported by the nodes following the hard fork.

Obviously in case when 100% of the community supports or does not support the hard fork there will be no blockchain split.
 

References

[1] Bitcoin Cash – Wikipedia

[2] SegWit Protocol – CoinDesk

[3] The stolen ether and the birth of Ethereum Classic:

[4] 51% Attack

 

Sources

Blockchain Fork – Wikipedia

Guide to Forks: Everything You Need to Know About Forks, Hard Fork and Soft Fork

What is a soft fork?

The differences between a hard fork, a soft fork, and a chain split, and what they mean for the future of bitcoin

___________

Read the original article at www.danielefavi.com

Where is the blockchain revolution?

A friend of mine asked me: bitcoin was invented 10 years ago, why has not anyone come up with a real product yet? Has anything been disrupted by blockchain?

His disappointment is quite understandable.
Everyone is talking about blockchain as a revolutionary technology, they say it will change how we approach the life, make transactions cheaper and free us from the middle man.
Many times I heard how Air B&B and Amazon will be wiped out by blockchain technology and how blockchain will protect our privacy from Facebook and Google.

Nowadays there are many products based on blockchain but none of them have been revolutionary, none of them changed our approach to life like the first PC, the first iPhone or Facebook.

Where is the claimed disruption?

Enthusiasts are claiming that blockchain will disrupt many industries in the future, but what about now?
No revolution happened yet, lots of good words, speculation and euphoria; even Bitcoin is failing its purpose as a means of payment [1].

The blinding light of making easy money on bitcoin hooked many people; it seduced not just investors and cyber-nerds but also normal people, everyone is hunting for a new business opportunity. If this euphoria does not match with a real solution it will soon turn into disappointment (as I am already reading around).

And the euphoria is a close friend of speculation, not just on bitcoin’s economy but also on the blockchain as term itself; for instance a tea company changed its name from Long Island Iced Tea to Long Blockchain and it got +500% increase on its shares [2]. Isn’t it crazy?

So what’s the state of work right now?

Let’s be realistic: blockchain is a new technology and it is still in development, experimentation and testing. Bitcoin blockchain is still fighting on performance (like transaction speed and fees).
Perhaps in 10 years blockchain will revolutionize our life, or it may fail as well.

Internet was invented in the 1950s but it boomed forty years later in the 1990s [3]. The artificial intelligence was invented in the 1950s but it boomed in 2015 [4].
Bitcoin’s white paper came out in 2008 [5] and now, ten years later, what has been accomplished by blockchain technology?

A lot.

No revolutionary products have been invented yet but many new blockchain platforms were born (like Ripple, Ethereum, Hyperledger or Iota): remember that blockchain is a new world to discover and it is still in development. When the foundation is ready new blockchain products will come out.

Many big tech corporations (like IBM or Microsoft) as well as banks are investing a lot in it.
I’m investing my free time in studying blockchain development and I personally think blockchain will help the humankind technology evolution.
Now it is the right time to invest in this technology if you want to be in the forefront in a close future. Be aware that blockchain might fail as well but no investment comes without risk.

The history of blockchain just started. Don’t let the mass euphoria, disappointment or skepticism blind you, stay calm and keep yourself informed instead.

___________

References

[1] Why bitcoin is failing its purpose as a means of payment:

[2] Tea company that chaged its name: https://techcrunch.com/2017/12/21/long-island-iced-tea-shares-went-gangbusters-after-changing-its-name-to-long-blockchain/

[3] History of the internet: https://en.wikipedia.org/wiki/History_of_the_Internet

[4] History of AI: https://en.wikipedia.org/wiki/History_of_artificial_intelligence

[5] History of Bitcoin: https://en.wikipedia.org/wiki/History_of_bitcoin

___________

Read the original article at www.danielefavi.com

How a blockchain works – the Proof of Work

When we were talking about mining, we mentioned a difficult puzzle that a miner has to solve. What is this puzzle and what is it for?
Before reading this article, I suggest you read these two articles

So what is the puzzle that has to be solved by a miner?

The puzzle that a miner has to solve during the block creation is called proof-of-work. The proof-of-work is a piece of data which requires computational power to be created but it can be verified quickly. Thanks to the proof-of-work the blockchain’s data becomes immutable.

In the previous article we created a simple blockchain and we saw that tampering a block causes the invalidation of the following blocks.
In that example recalculating the hash of invalid blocks is simple, but if we add complexity in the calculation we will make the bad guys’ life difficult.

What is the proof-of-work for? Why do miners spend so much effort on mining?

The proof-of-work is a mechanism for reaching global consensus on the valid blockchain: since all nodes have a copy of the blockchain, each node must agree on the conditions that prove how much effort a node has spent on verifying transactions.
In other words: if the content of the blockchain is easy to change then everyone can tamper with it; instead, if each block is calculated with complex mathematical functions then it takes a lot of effort to tamper with the blockchain.

Let’s check the proof-of-work more in depth.

Let’s create a blockchain where the blocks are linked to each other through an identification code; a block contains the following data:

    • identification code of the previous block (PREV)
    • name of the sender (SENDER)
    • name of the receiver (RECEIVER)
    • bitcoin amount (AMOUNT)

To make the calculation difficult, every identification code must start with 0000 (four zeros). To do this we have to add a new field called NONCE.

For a better understanding let’s take an example.

The first block of our blockchain includes the following data (please note that the identification code of the previous block is 0 because this is the first block):

PREV:0
SENDER:john
RECEIVER:jenny
AMOUNT:100
NONCE:1

Now let’s copy this block content, then paste it in the hash calculator and press the button Calculate SHA-256 Hash (be careful with spaces and new lines). The hash is as follows:
07b01b0f4672f2bc58ef11132df4bc74a4e0dc9f2e07ee5d9a0428d3836bc6cb

As you can see the code starts with b273 and not with 0000; so you must increase the NONCE and repeat the calculation again (note that increasing the NONCE from 1 to 2 leads to the change of the content and consequently the hash changes too).
Now our block is:

PREV:0
SENDER:john
RECEIVER:jenny
AMOUNT:100
NONCE:2

and its hash is:
263172553403d3182866ed4d2e7b588a6932e58d0acaa1fa92958a1f70dfabc5

The code still does not start with 0000! You must repeat the calculation all over again until the code starts with 0000. OK, I will give you the solution: you have to repeat this process 22683 times!

PREV:0
SENDER:john
RECEIVER:jenny
AMOUNT:100
NONCE:22683

Hash code: 00000d7d33ebf71c24c15119c925acf9d9d45f8f9972034e2c8b1aabe29163a7

As it was said in the previous article, the hash is a one way function, so the only way to find the block’s identification code that starts with 0000 is making random attempts (the method is called brute force).

Let’s create a blockchain that we made in the previous article but this time we will apply the proof-of-work to it; this is what we get:

If you tamper the first block, you will break all the blockchain and for every block you will have to calculate the hashes that start with 0000 again! So, when a certain block has many blocks after it, this block becomes secure.

In the bitcoins world a block becomes secure when it has at least 6 following blocks; keep in mind that the difficulty of the hash calculation is much higher than our example.
If you want to tamper the bitcoin’s blockchain, remember that every fake block must comply with the calculation difficulty criteria and moreover you have to create fake blocks faster than the other miners in the network… to achieve this you need 51% of the computational power of the whole network!

Nowadays the blockchain technology is pushing to find other ways to reach the network consensus because the proof-of-work is not energy-efficient at all. Some of these new ways are proof of stake, proof of burn or casper.

___________

More Info

Bitcoin hash rate: https://blockchain.info/it/charts/hash-rate?timespan=all

More info about proof-of-work: https://en.bitcoin.it/wiki/Proof_of_work

HASH calculator: https://www.danielefavi.com/sha256-hash-calculator/

PHP code that I used to create the blockchain example: https://github.com/danielefavi/blockchain-hash-block-calculator

___________

Read the original at www.danielefavi.com

How a blockchain works… Let’s make one!

Have you ever wondered why the blocks on the blockchain are stored one after another?
In this article we are going to talk about the basic blockchain concepts; these concepts will be fundamental to grasp how the proof-of-work works, why the mining requires lots of computational power and how the blocks become immutable.

The blockchain technology uses a mathematical function called Hash which turns data into a 64 character long code. The hash code identifies the block in the blockchain and protects its content.

What is the hash?

The hash is a mathematical function that turns every type of data (like text or file) into a string of 64 characters. The output code never changes for the same input. The hash is a one way function: it is easy to generate a code but starting from a hash code it is impossible to get the original data.

Let’s take an example: this is the link to my website where you can find the hash calculator https://www.danielefavi.com/sha256-hash-calculator/.
Let’s type “test” in the text field and then press the button Calculate SHA256 hash. The generated code is:
9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08

Now let’s type “test.” (add only a full stop) in the text field Data and press again the button Calculate SHA256 hash. The generated hash is:
4ee3df88f682d376531d8803f2ccbee56d075cd248fc300f55dfe8596a7354b7

Adding a full stop makes a difference, the code of “test” is totally different from the code of “test.” Even the addition of a space or a blank line or change a letter to the capital letter can change completely the hash of the output code.

It is easy to calculate the hash, but it is very difficult to get back the starting data from the hash. For example try to find the word that matches with the following hash:
3866daf66ad5f7e6dbf8c983b06287d7ad254336a172d8f34eb1cb4f25f12b70
You can search for a starting word doing lots of random attempts until you will find the corresponding word (this method is called brute-force).

Let’s create a simple blockchain to understand what the hash is for.

Our blockchain contains simple information: a list of people with their names and ages; the name and the age are separated by a dash:

  • Block 1: Natalia-28
  • Block 2: John-45
  • Block 3: Paul-21
  • Block 4: Claire-67

Every block must have an identification code: this code will be calculated with the hash.
In order to build a chain of blocks you must link each block to its previous one: so a block must contains the identification code of the previous block.

For a better understanding let’s build our blockchain.

Let’s start with the first block: since the block 1 has no previous blocks we can choose zero: 0-natalia-28.
Now go to the hash calculator and calculate the hash of 0-natalia-28; the hash is:
51831cdd6acfaee6c7402cea12c58f514bc014d495e185610ee6cc664452d23d

Let’s take only the first 5 digits of this code (to make our life easy) and put them at the beginning of the second block: 51831-john-45.
Go back to the hash calculator and calculate the hash of 51831-john-45; the generated hash is:
4e942233bba491ab530669fa78c03b3e72c4e3940834e3e960d9ca32ed959429

Again, take only the first 5 digits and put them at the beginning of the third block, obtaining 4e942-paul-21.
Repeat the same process for the blocks #3 and #4; the chain that you have built is:

Let’s tamper with the blockchain!

For our friend Natalia, from the first block, let’s change the age from 28 to 25. So, changing the content of the block will result in the change of the hash of the block too.
The new content of the first block is 0-natalia-25 and the first 5 digits of the new hash are 07698.

Since the identification code of the first block changed (before it was 51831 and now it is 07698) we must update the hash code inside the second block that refers to the first block. With this update the content of the second block changes (now it is 07698-john-45) so we have to calculate again the hash of the second block: the first 5 digits of the hash code of 07698-john-45 are 43339.

The hash code of the block #2 is changed, as well as the content of the block #3. The content of the block #3 is 77e83-paul-21.
As you have already guessed, since the content of the block #3 is changed, we must calculate again its hash, which will cause the change of the content and the hash of the block #4.

The change of the content of the block not only invalidates the block itself but causes the invalidation of all the following blocks.

This article showed us how a blockchain is structured. In the next article we will see how to prevent a blockchain from being tampered.

___________

Read the original article at www.danielefavi.com

What is the mining? Who is the miner?

The mining is the process where the data is collected in a block and then the block is appended to the blockchain. This process is done by the miner.

Before digging into the process of mining, I suggest you read the following articles:

Who is the miner? Why does a person decide to start mining?

The miner is a special node in the network that gives its computational power to the network. You could be a miner too, all you need to do is to download a free software and run it.
The miner earns 12.5 bitcoins for each block created (called coinbase) as well as the transaction fee.

If it’s so easy I’ll quit my job and I’m going to be a miner!

Wait! It’s not so easy! In order to secure the data on the blockchain, it has been made intentionally difficult to create a block.
During the mining process, the miner calculates a code which will identify the block within the blockchain. This calculation must comply with the criteria of complexity that increases with the hashing power of the network. This difficult puzzle is called proof-of-work (I will talk about it in the next article).
The miners are racing with each other to solve the puzzle and the winner will earn the coinbase and the transaction fees.
Nowadays, there are miners with warehouses full of special computers that are working 24/7 only for mining; so if you want to start the career as a miner, your nerd computer is not enough!

What is the proof-of-work for? Why do miners spend so much effort on mining?

The proof-of-work is a mechanism for reaching global consensus on the valid blockchain: since all nodes have a copy of the blockchain, each node must agree on the conditions that prove how much effort a node has spent on verifying transactions.
In other words: if the content of the blockchain is easy to change then everyone can tamper with it; instead, if each block is calculated with complex mathematical functions then it takes a lot of effort to tamper with the blockchain.

If everyone can be a miner, is there any risk that someone can create a fake block?

Of course. A bad miner can create an invalid block; but remember that before appending a block to the blockchain, a miner must check if the block is valid. Hence if the block received by the miner is not valid, it will be rejected.
Moreover, the identifier hash code links each block together in a chain (that’s why the name is the blockchain); if I tamper with a block, I will invalidate not only that block, but also all the following blocks!

References

Coinbase value: https://blockchain.info/stats (you can calculate it dividing Bitcoins Mined by Blocks Mined)

Hash: wikipedia or you can wait for the next article!

Difficulty of proof-of-work: https://blockchain.info/it/charts/hash-rate?timespan=all

___________

Read the original article at www.danielefavi.com

Bitcoin transaction: how does it work?

In the previous article we had a quick introduction to the blockchain technology. In this article we are going to see what’s happening behind a bitcoin transaction.

Let’s take a simple example: Robert and his friends went to the Bit&Beer pub where bitcoin payments are accepted. After the whole night of drinking and having fun it’s time to pay the bill!
The waiter takes out a smartphone and shows the QR code to Robert for the payment of the bill. Robert takes out his smartphone as well, opens his bitcon app, scans the QR code, checks if the payment details are correct and presses the PAY button.

The QR code is a kind of a bar code but more complex, it contains several types of information, like:

  • the ewallet of the receiver (in our case Bit&Beer)
  • bitcoin amount to transfer
  • general information (like the name of the receiver)

When Robert presses the PAY button he creates a new transaction which contains the sender’s ewallet (Robert) and the receiver’s ewallet (Bit&Beer) details, the amount of bitcoins and a small fee. The fee however is not mandatory: the sender can decide whether or not to include the fee (transactions with a higher fee have a higher priority).

What is happening behind the scene?

The transaction is propagated in the bitcoin network (phase #1 of the scheme); the waiter of Bit&Beer can see Robert’s payment on his phone almost instantly, the status however is NOT CONFIRMED.

Who decides whether a transaction is valid or not?

The transaction is considered valid when special nodes in the network (called Miner) will append this transaction into a block in the blockchain.
This process is called Mining (phase #2 of the chart) and it has the following purposes:

  • to validate the transaction (referring to consensus protocol) or to reject an invalid transaction.
  • to create new bitcoins.

The process of Mining is the essential phase where the transactions are stored in the blockchain. In this step the transaction is being included inside a new block and this block is appended to the blockchain.
It is not simple at all to create a new block. Mining a block requires complex operations using a lot of computational power; this operation is called proof-of-work and it verifies the data on the blockchain and makes it immutable.

Miners are racing with each other to create a block: the first one that creates a block which satisfies the requirements earns some bitcoins and the fee within the transactions (phase #3 of the chart).

A new block is propagated on the network (phase #4 of the chart); other miners which received a new block, are going to check if the block is valid first and then include the new block in the blockchain.
Finally, the waiter of Bit&Beer can see in his ewallet that the payment has been confirmed. All this process is about 10 minutes long.

___________

Read the original at www.danielefavi.com

Blockchain for Dummies! A gentle introduction.

This article is one of several articles in which I explain in a very simple way what a blockchain is.

What is the difference between Bitcoin and Blockchain?

Blockchain is the technology behind bitcoin: bitcoin cannot exist without a blockchain. It is like Internet and Facebook: Facebook cannot exist without Internet.

What is a blockchain?

A Blockchain is a kind of database: while a normal database is located on a server, a blockchain is distributed among the software users.
For example, the Facebook’s database is located on a protected server and no one can access the information. The Bitcoin’s blockchain instead is located on servers and computers (called nodes) of all the Bitcoin users.

All the transactions that occur between ewallets are stored on the bitcoin’s blockchain. All the servers and the computers that are using bitcoin have the same copy of the blockchain stored on their hard disk.

There are many kinds of blockchain with different features, like Ethereum, Hyperledger, Ripple. Some of them are more suitable to handle currency, others are used to transfer the ownership of assets (eg supply chain).

You don’t need to download all the blockchain to your computer in order to use Bitcoin (or any other blockchain technology) as the current size of Bitcoin’s blockchain is over 160 GB and it can easily drain the resources of your computer. To avoid this issue there are different types of e-wallets (we will talk about them later).

If the bitcoin’s blockchain is on my computer, can I add 1 million of bitcoins in my ewallet?

The blockchain is famous for its security: once the data is there it is impossible to modify it.

The blockchain consists of a chain of blocks, where every block contains data (for instance a money transactions, documents or personal data).
When a new block is to be added to the chain, it has to be verified by the network of nodes first, and once this is done, the transaction can be inserted in the blockchain. There are mining and a consensus protocol standing behind this phase (click here to read more).
The blocks are connected with each other in a way that if I edit the content of one block I must edit all the following blocks, moreover to edit a block you need the consensus of other nodes.
Hence the more people are using a blockchain, the longer it is and the more secure the system is.

At present there are over 9000 nodes in the Bitcoin system.

Are you telling me that the blockchain has no flaws?

Technically it is possible to break into the blockchain but you will need more than half of the computational power of the whole world (so basically it is impossible).

Experts are worried that blockchain cannot resists a quantum attack. A quantum computer is a next generation computer with a huge computational power, it is being developed in Google’s laboratory. It can come out in 10 or 20 years but by that time also the blockchain technology will evolve. For instance Iota is a new kind of blockchain with a different structure and it can resists a quantum attack.

Why don’t we continue using a normal database as we did so far?

The blockchain is shaking many industries but it cannot be used everywhere. For example there is no sense in using blockchain to store the data of this website. But it makes a big difference when the third party is involved.
If you have to transfer money, the bank is the third party that takes the money from you and transfers it to the recipient.

In the Bitcoin system there is no one between you and the recipient, the transfer is direct, and it takes around 10 minutes.

The blockchain technology is applied in many industries such as music, real estate and energy. The company where I work uses the blockchain technology in the notary industry.

Thanks! You convinced me! Now I’ll buy 1000000€ in Bitcoin!!!

Wait a moment! The blockchain world is wonderful but risky. There are legal and technical details that you have to understand.

In several countries Bitcoin is not regulated.
For instance if I steal from you 10000€ you can sue me. If I steal from you 100 bitcoins and you go to the police, the policemen will tell you that the Bitcoin has no value. From the legal point of view, to steal the bitcoins is like to steal the air! You cannot sue me for stealing something without value.
Keep yourself updated with regards to the cryptocurrency laws of the country you live in.

The blockchain is a technology that is still evolving, some technical problems can arise with its development as well. For example in 2016 a bug in the Ethereum cryptocurrency system resulted into a loss of 50 million dollars suffered by many users.

On the other hand, many investors took the risks and became rich. It’s important to be updated, rely on tested technology, use safe systems for money deposits and not to search for easy ways to make money.

___________

Read the original at www.danielefavi.com