The cloud is used for storing the data that is collected by IoT devices. It also has the capability of analyzing the data and extracting some useful information from it [7]. Fog computing is much the same as cloud computing. The major difference is the response time. If the data from the device goes to the cloud, the cloud first stores the data, and after that it calculates information from that data and sends back the response. However, if the data is sent to the fog, the fog immediately fetches the information and gives back a quick response [8].

Blockchain is the concept of decentralization in which data is not stored in a centralized place. Cloud computing is based on a central server storing the data. Blockchain is integrated with IoT. w'hich is a more secure network than the cloud with IoT. Table 20.2 discusses parameters such as security, privacy, flexibility, cost, etc., and explains how blockchain is more beneficial than the cloud.

TABLE 20.2

Comparison between Cloud and Blockchain


Cloud with loT

Blockchain with IoT


Privacy of data is very important, and cloud computing has many solutions for this, but after having these solutions it can’t fulfil the privacy criteria as data can leak.

The concept of immutability helps in the privacy of data as no one can alter it.


The cloud seems to be secure, but many insecure issues are found in IoT using the cloud.

Blockchain is very secure compared to the cloud because the attack happens only when more than 51 % of the users allow the change.


Already discussed above that the cloud requires more response time.

Latency is also a challenge in blockchain as mining is a timeintensive process.


There are many factors that increase the cost: bandwidth, updating hardware/ software, etc.

Blockchain’s execution cost is high, but the overall cost in terms of bandwidth and updating blockchain is more feasible.


The centralized system is easier.

It is difficult to deal with decentralization.

Losses and Risks

There are more attacks in this process.

There is no history' of attacks in blockchain.


The method of payment is very limited and often used.

There are many payment methods in blockchain. and the popular example of digital currency is Bitcoin.


A blockchain is a combination of blocks that store data publicly and in sequential order. The entire information is stored and transferred among the other nodes using cryptography. Cryptography ensures that the user’s privacy is maintained and data cannot be altered. Information in the blockchain is not controlled by a central authority. Unlike modern financial institutions, nobody controls the data within a block- chain. A typical blockchain network is a public blockchain in which, as long as the user has access to the network, they have access to the data within the blockchain [7]. Everyone in the network has a copy of the blockchain, which is used for ensuring that the data remains untampered with.

Building a Blockchain

A block is based on three things: data, a hash of a particular block and the previous block hash, which is shown in Figure 20.3. Data is what that block contains, and it is dependent on the type of blockchain. A Bitcoin cryptocurrency transaction is based on a technology called blockchain, and blockchain holds the information about the

Blocks connected in blockchain

FIGURE 20.3 Blocks connected in blockchain.

sender, receiver and the amount of currency exchanged between them. A block also contains a hash value in hexadecimal which is generated by hash cryptography SHA 256. SHA 256 means the secure hash algorithm and 256 bits mean 64 hexadecimal characters. There are five requirements of a hash algorithm: one-way, deterministic, fast computation, the avalanche effect, and starting with a collision. Once a block is created, the first thing is to calculate the hash of a block. If there is some alteration inside the block, it will cause the hash to change. Hash is the only thing that tells the user about the change in that particular block. The third element of the block is used to make the chain as it contains the unique hash value of the previous block. The first block is known as the Genesis block. The previous hash attribute of first block is zero. Blocks are cryptographically linked together.

The basic structure of a blockchain with blocks linked together is shown in Figure 20.3.

Basic Terminology of Blockchain

a. Hyper ledger: Ledger is a kind of database where transactions that have been confirmed are recorded. Blockchain platforms do not use a centralized database. Instead, each node has a copy of the ledger [9]. Cryptocurrency such as Bitcoin stores only balance information in the distributed ledger. Blockchain platforms such as Ethereum can store any kind of information, such as identity information, patient information, real estate information, etc. in the distributed ledger.

b. Miners: Miners are nodes that collect all the transactions which people send to each other over the network, and it’s the job of the miner to transfer only valid transactions. Each miner takes a number of these collected transactions and puts them in a newly formed block. These transactions are numbered txO, txl, tx2, .... txn. The first transaction, txO, is called the coinbase transaction.

How mining Works: The objective of the miner is to find some nonce that generates some random number that meets some criteria. Hash should

TABLE 20.3 Structure of a Block

Block #5

This tells the index of a block in a blockchain.

Nonce 10

Used in mining for meeting the condition of hash calculation.


Contains the actual data.

Prev ious Hash

Hash of the previous block.


Hash of the current block.

be less than the specific target. Any hash above the target is valid. The miner is going to get information about three fields in a block: block number, data and previous hash. The nonce is going to try all possible values in order to produce a hash that meets the criteria. The structure of a block is given in Table 20.3, which contains block number, the hash of the previous block, the hash of the block, nonce value and data content in that block. The hash number is the unique identifier of a block, and every block has particular criteria for hash numbers. Changing the value of nonce of a block changes the value of hash. The structure of a block is given below, and nonce value is a random value and it is added before the hashed value of current block.

c. Ethereum: Ethereum came up with the idea that blockchain could be used for no purposes beyond financial transactions. It maximizes the usage of the blockchain application. Ethereum is an open-source distribution platform that allows decentralized applications to be built on it with the help of smart contracts functionality. Ether is a cryptocurrency token of the Ethereum network which is used to pay for transaction fees [9].

d. Smart contracts: Smart contracts are immutable pieces of code that run on the Ethereum network to perform a certain transaction or task, and when these contracts are running, or the blockchain acts like a self-operating programme, execution happens automatically when specific conditions are met. Codes in this smart contract are written in a special contract language called Solidity [10]. Solidity language is preferable to the other languages because the cost is low compared to others. The syntax of Solidity is the same as the JavaScript.

< Prev   CONTENTS   Source   Next >