Blockchain Transactions
Tags: solidity
Published: 2022-11-25 16:12:40




**Blockchain technology** represents a new generation of software that improves business processes. The financial industry is beginning to realize its potential after decades of investing in in-house software.
This technology makes transactions more reliable and should therefore offer multiple applications in banking, with a very good return on investment.
But implementing this technology is a challenge: companies cannot implement it alone. They must collaborate differently and more actively with their consumers, suppliers, and competitors.  In this article I’m going to talk about transactions flow between parties in blockchain.

**Definition**

Blockchain is a **peer-to-peer**, distributed ledger that
is cryptographically secure, append-only, immutable extremely hard to change), and updateable only via consensus or agreement among peers.



```
Transactions steps
```
**Step 1: Operation Initiated**
Let's follow the step with a basic Ether transaction. If Alicia wants to send Billy some bitcoin, she would go to a Ether wallet application either on her phone or computer where she has some Ether stored. Wallet applications are usually free downloads that create a digital wallet to purchase and/or store your cryptocurrency.
 
It is worth mentioning here that cryptocurrencies are a function of a particular blockchain, the Etherreum blockchain only transacts bitcoin and the Ethereum blockchain can only exchange Ether. To initiate the transaction, Alicia would make a request of the system to send Ether to Billy’s wallet by specifying the amount and Billy’s Ether address.

 **<u> Step 2: Smart Contract Triggered</u>**
When Alicia sends her transaction to the network, it triggers a smart contract that checks with the nodes on the network to make sure Alicia has the currency to spend, and that she hasn't already spent it. Once checked, the transaction is added to a proposed block.  

**<u>step 3 :Operators Spread Transaction</u> :**
Proposed block is communicated to the network through the peer-to-peer protocols.

**Step 4: Consensus**
In order for the Etherreum  network to validate a block, nodes or miners must validate the correctness of a block by completing a math problem first. The node that completes consensus algorithm equation first is rewarded with some newly minted Ether. Once a solution for the equation is reached, the other nodes can easily check its accuracy, thereby accepting the new block onto the blockchain.

**Step 5: Spread The New Block**
This block is spread throughout the network through the same peer-to-peer communications we used for the transaction. When block operators receive a copy of the new block, they add it to their copy of the distributed ledger. This guarantees that all members of the peer network agree on the current state of the blockchain’s distributed ledger.

**Step 6: Transaction Completed**
The user’s wallet monitors for the creation of new blocks that include transactions associated with the user. When a block containing the completed code from the user’s operation is received, an event is created to notify the user that the operation is complete. When the block containing Alicia’s Ether transfer to Billy is added to the blockchain, an alert will be sent to the affected wallets that the transaction was accepted and completed.



```
Consensus in blockchain
```
Consensus is a distributed computing concept that has been used in blockchain in order to provide a means of agreeing to a single version of the truth by all peers on the blockchain
network. 


**Consensus Categories**

Roughly, the following describes the two main categories of consensus mechanisms:

**1. Proof-based, leader-election lottery-based :** , or the Nakamoto consensus whereby a leader is elected at random (using an algorithm) and proposes a final value. This
category is also referred to as the fully decentralized or permissionless type of consensus  mechanism. This type is well used in the Bitcoin and Ethereum blockchain in the form of  a PoW mechanism.

**2. Byzantine fault tolerance (BFT)-based** is a more traditional approach based on rounds of votes. This class of consensus is also known as the consortium or permissioned type of consensus mechanism. BFT-based consensus mechanisms perform well when there are a limited number of nodes, but they do not scale well. On the other hand, leader-election lottery-based (PoW) consensus  mechanisms scale very well but perform very slowly. As there is significant research being
conducted in this area, new types of consensus mechanisms are also emerging, such as the  semi-decentralized type, which is used in the Ripple network. 


```
Consensus Algorithms
```

The consensus algorithms available today, or that are being researched in the context of blockchain, are presented as follows. The following is not an exhaustive list, but it includes all notable algorithms:

• **Proof of Work (PoW):** This type of consensus mechanism relies on proof that adequate computational resources have been spent before proposing a value for acceptance by the
network. This scheme is used in Bitcoin, Litecoin, and other cryptocurrency blockchains. Currently, it is the only algorithm that has proven to be astonishingly successful against any collusion attacks on a blockchain network, such as the Sybil attack. 

**• Proof of Stake (PoS)**: This algorithm works on the idea that a node or user has an adequate stake in the system; that is, the user has invested enough in the system so that any malicious attempt by that user would outweigh the benefits of performing such an attack on the network. This idea was first introduced by Peercoin, and it is going to be used in the Ethereum blockchain version called Serenity. Another important concept in PoS is coin age, which is a criterion derived from the amount of time and number of coins that have not been spent. In this model, the chances of proposing and signing the 
next block increase with the coin age.


**• Delegated Proof of Stake (DPoS)**: This is an innovation over standard PoS, whereby
each node that has a stake in the system can delegate the validation of a transaction to
other nodes by voting. It is used in the BitShares blockchain.
• **Proof of Elapsed Time (PoET):** Introduced by Intel in 2016, PoET uses a Trusted Execution Environment (TEE) to provide randomness and safety in the leader- election process via a guaranteed wait time. It requires the Intel SGX (Software Guard Extensions) processor to provide the security guarantee for it to be secure. 

•** Proof of Deposit (PoD):** In this case, nodes that wish to participate in the network have to make a security deposit before they can mine and propose blocks. This mechanism is used in the Tendermint blockchain.

•** Proof of Importance (PoI): **This idea is significant and different from PoS. PoI not only
relies on how large a stake a user has in the system, but it also monitors the usage and movement of tokens by the user in order to establish a level of trust and importance. It is used in the NEM coin blockchain. 

 •** Federated consensus or federated Byzantine consensus:** This mechanism is used in the stellar consensus protocol. Nodes in this protocol retain a group of publicly-trusted peers and propagate only those transactions that have been validated by the majority of trusted nodes.

• **Reputation-based mechanisms:** As the name suggests, a leader is elected by the reputation it has built over time on the network. It is based on the votes of other members.

• **Practical Byzantine Fault Tolerance (PBFT):** This mechanism achieves SMR, which  provides tolerance against Byzantine nodes. Various other protocols, including PBFT,
PAXOS, RAFT, and Federated Byzantine Agreement (FBA), are also being used or have  been proposed for use in many different implementations of distributed systems and
blockchains.
• **Proof of Activity (PoA):** This scheme is a combination of PoS and PoW, which ensures
that a stakeholder is selected in a pseudorandom but uniform fashion. This is a comparatively more energy-efficient mechanism as compared to PoW. It utilizes a new concept called "Follow the Satoshi." In this scheme, PoW and PoS are combined together  to achieve consensus and a good level of security. 

**• Proof of Capacity (PoC):** This scheme uses hard disk space as a resource to mine the blocks. This is different from PoW, where CPU resources are used. In PoC, hard disk
space is utilized for mining and, as such, is also known as hard drive mining. 

**• Proof of Storage:** This scheme allows for the outsourcing of storage capacity. This scheme is based on the concept that a particular piece of data is probably stored by
a node, which serves as a means to participate in the consensus mechanism. Several variations of this scheme have been proposed, such as Proof of Replication, Proof of Data Possession, Proof of Space, and Proof of Space-time.


• **Proof of Authority (PoA):** This scheme utilizes the identity of the participants called validators as a stake on the network. Validators are known and have the authority
to propose new blocks.  Validators propose the new blocks and validate them as per blockchain rules. Commonly used PoA algorithms are Clique and Aura.  


```
Smart Contracts

```

**<u> Definition </u>**
A smart contract is a secure and unstoppable computer program representing an agreement that is
automatically executable and enforceable.

**<u>Smart Contract  explained in details </u> :** They are computer programs that execute an action based on terms and conditions.
Can also be known as chain code.
**Smart contracts** have terms recorded in a computer language instead of legal language. Smart contracts are not necessarily legally binding and do not need multiple participants.
Each step of a smart contract can only be implemented after the execution of the immediate former step.
Smart contracts are written in Solidity, a programming language designed for developing smart contracts that run on the Ethereum Virtual Machine.
The smart contracts act as a foundation to build decentralized applications (DApps).
Once executed, the information in the smart contract is stored on a blockchain which cannot be altered.

```

Smart contracts  features 
```
**Accuracy**
Replacing human intermediaries with executable code ensures the process will always be performed the same. 
**Cost savings**
Replacing intermediaries often provides significant cost reduction.
**Efficiency**
Removing process intermediaries often results in significant process efficiency gains.
**Backup**
A blockchain and smart contract deployed to it can provide a permanent record, allowing for auditing, insight, and traceability, even if the creator is no longer in business.
**Autonomy**
Smart contracts can be developed by anyone, no need for intermediaries such as lawyers, brokers, or auditors. 

```
 
Smart Contracts properties
```
In summary, a smart contract has the following properties:
Automatically executable: It is self-executable on a blockchain without requiring any intervention.

**Enforceable: **This means that all contract conditions are enforced automatically.
**Secure:** This means that smart contracts are tamper-proof (or tamper-resistant) and run  with security guarantees. The underlying blockchain usually provides these security  guarantees; however, the smart contract programing language and the smart contract code themselves must be correct, valid, and verified.

**Deterministic:** The deterministic feature ensures that smart contracts always produce the same output for a specific input. Even though it can be considered to be part of the
secure property, defining it here separately ensures that the deterministic property is considered one of the important properties. 

**Semantically sound:** This means that they are complete and meaningful to both people and computers.
** Unstoppable:** This means that adversaries or unfavorable conditions cannot negatively affect the execution of a smart contract. When the smart contracts execute, they complete
their performance deterministically in a finite amount of time.


@Aya