Blockchain Basics
Tags: web3, blockchain, webdev, smartcontract
Published: 2024-02-02 06:49:02


## Blockchain Overview:

- Blockchain is a type of digital ledger technology that makes it possible to build decentralized, transparent, and safe networks. A blockchain is a distributed database that is not controlled by a single entity but rather by a network of computers called nodes. A copy of the database, which holds a history of every transaction made on the blockchain, is kept on every node in the network.

- Numerous nodes inside the network use complex cryptographic methods to verify and confirm every transaction on the blockchain. A new block is added to the blockchain when a transaction is approved and verified, completing the chain. All nodes inside the network get this block and update their respective copies of the blockchain accordingly.

- The reason the blockchain is regarded as safe is that each block in the chain is connected to the one before it, forming an unbreakable transaction chain. A block is a tamper-proof record of every transaction that has ever taken place on the blockchain since once it is added, it cannot be removed or changed.

- Applications for blockchain technology are numerous and include voting systems, healthcare, supply chain management, finance, and more. Its potential is found in its capacity to foster security, trust, and openness across a range of industries, do away with the need for middlemen, and open the door to new business models.

## Why do we need blockchain?

1. **_Decentralization_**: Establishing decentralized systems is one of the main goals of employing blockchain technology. A decentralized network is more transparent, safe, and resistant to censorship and corruption since it lacks a central authority or middleman to exert control over it.

2. **_Security_**: Cryptographic algorithms are used by blockchain technology to protect data and transactions. Multiple parties validate and verify each transaction on the blockchain, making it more difficult for an unauthorized person to change the data or steal information.

3. **_Transparency_**: By generating an immutable ledger of every transaction, blockchain technology promotes transparency. As a result, trust and accountability are encouraged because every member of the network can view every transaction that has occurred and confirm its legitimacy.

4. **_Efficiency_**: Through the removal of middlemen and the automation of procedures, blockchain technology can lower transaction costs and boost efficiency. Businesses can cut expenses and boost revenues by expediting and streamlining transactions by doing away with middlemen.

## Types of Blockchain:
There are generally three types of blockchain: public, private, and hybrid.

1. **_Public Blockchain_**: Anyone can access and participate in a public blockchain, which is a decentralized blockchain network. Anyone can read and write data on the network and join it. The public blockchains of _Ethereum, Litecoin, and Bitcoin_ are examples.

2. **_Private Blockchain_**: A permissioned blockchain network is one in which only individuals with permission are able to access and engage with the network. Private blockchains are usually utilized by businesses or by a select group of reliable and well-known individuals. The _Quorum, Corda, and Hyperledger Fabric_ private blockchains are a few examples.

3. _**Hybrid Blockchain**_: A hybrid blockchain is made up of elements from both private and public blockchains. Because it enables authorized users to access and engage with both the public blockchain network and the private network, it provides the best of both worlds. _Aion, Dragonchain_ and other hybrid blockchains are examples of it.

Apart from the aforementioned trio of blockchain styles, there exist additional varieties or adjustments to the three main types of blockchains. A type of private blockchain known as a _consortium blockchain_, for instance, is one in which a number of businesses band together to cooperatively run and maintain the network.

## Blockchain Applications:
Blockchain technology has a wide range of applications across various industries. Here are four examples of how blockchain is being used:

1. _**Cryptocurrencies**_: The development and utilization of cryptocurrencies such as _Bitcoin, Ethereum, and Litecoin_ is the most well-known application of blockchain technology. These digital currencies employ blockchain technology to enable safe, peer-to-peer transactions. They are decentralized, which means they are not governed by any financial organization or government.

2. **_Supply Chain Management_**: By generating a safe, transparent record of each transaction that takes place in the supply chain, blockchain technology is being utilized to enhance supply chain management. This promotes efficiency, lowers fraud, and strengthens confidence between all supply chain participants.

3. **_Identity Verification_**: People can establish safe, immutable digital identities for themselves using blockchain technology. This can lessen fraud and identity theft and make it simpler for people to authenticate themselves in a range of situations.

4. **_Smart Contracts_**: Smart contracts are self-executing agreements that automatically carry out their terms by utilizing blockchain technology. This can improve contract execution efficiency and speed while also lessening the need for middlemen like banks and lawyers. Financial services, insurance, and real estate are just a few of the businesses using smart contracts.

## Ethereum Vs Bitcoin:
Ethereum and Bitcoin are both decentralized blockchain platforms that have some similarities but also some
important differences. Here are some key differences between Ethereum and Bitcoin:

1. _Ethereum_ was intended to serve as a platform for smart contracts and decentralized applications (Dapps), whereas _Bitcoin_ was intended to serve as a decentralized digital currency.

2. _Bitcoin_ uses a Proof of Work (PoW) mining method, which, in order to validate transactions and add new blocks to the blockchain, consumes a significant amount of processing power and energy. Nowadays, _Ethereum_ employs the more energy-efficient PoS algorithm.

3. While _Bitcoin_ has a limited scripting language for transactions, _Ethereum_ allows developers to create custom smart contracts and decentralized applications using a variety of programming languages, such as _Solidity, Vyper , and Rust._

4. The processing speed of _Ethereum_ transactions (15-20 tps) is generally faster than that of _Bitcoin_ (7/8 tps), with an average block time of approximately 15 seconds, as opposed to 10 minutes for Bitcoin. This is achieved through scalability. The network congestion that causes high fees and delayed transaction times during peak demand is one of Ethereum's scalability problems.

5. _Ethereum_ does not have a fixed supply; instead, new Ethereum tokens are created through mining and transaction fees. _Bitcoin_ has a finite quantity of 21 million coins.

6. In Bitcon, miners will get 6.25BTC(halving in every 4 years) and in Ethereum, they will get 2 ETH.

## Cryptocurrency VS Token:
- Cryptocurrency is native to a Blockchain network. A Blockchain can have only one cryptocurrency but a million tokens. For example, Ethereum has its native currency, ether, but regulates multiple tokens such as USDC, AVAX, UNI, USDT, etc.

- Tokens are backed by a smart contract and can contain various functionalities depending upon different use cases. For example, security tokens, utility tokens, etc.

- Tokens can represent any asset on a blockchain network. For example, art, equity, insurance, identity, tickets, etc.

### _Broadly, there are three basic token standards and more will be added over time. Let’s understand them one by one._
**ERC20** :
- This standard is used to implement the functionality behind Fungible tokens. Fungible Tokens of a type are all alike and can be exchanged for the same value. For example, USDC, UNI, AVAX, DAI, etc.

_Ex: When you ride a metro/subway train, the ticket you buy is the same as everyone else for the same destination. Even if you exchange the ticket with someone, it would still work for you as there’s no differentiator between those tickets. Such items are called ‘fungible’, meaning that they can be mutually exchanged. Other examples of fungible items are currency notes, shares of a company etc._

**ERC721** :
- This standard is for Non-Fungible Tokens (NFTs). Tokens of this type are meant to be unique and cannot be exchanged for the same value given that none of them are alike. For example, Bored Apes, CryptoKitties, etc.  we usually call the image itself as an NFT and ultimately this is the thing that we bought it for. But technically, an NFT is a serial ID on the blockchain i.e. 1, 2, 3 etc. Against this serial ID, there’s a wallet address, and this mapping of address against the serial ID proves that a particular serial ID is owned by a particular address. In IPFS/Pinata, you can upload the images and metadata for your NFT that can then be connected to your ERC-721 smart contract. With this, we’ll now have two mappings on the blockchain:
- Token ID –> User Address
- Token ID –> Token URI 
(This mapping is actually done through a function that returns a URI for each token ID as we’ll see later in this lesson) i.e. one mapping will contain which user address owns a particular token ID. The second mapping maps the token URI to each token ID. The token URI is the hash of metadata stored on IPFS that contains the details and properties of the image associated with the token ID.

Thus, we establish the ownership of NFTs on the blockchain by storing the token IDs, wallet addresses and token URI function. Whereas the images and their details & properties are stored on the IPFS and connected to the smart contract via token URI.

_Ex: When you take a flight, you can’t exchange your boarding pass with another person even if you both are going to the same destination. That’s because your boarding pass has your name and your seat number, both of which are unique. Hence each boarding pass is different from others. Such items are called ‘non-fungible’, meaning they can’t be exchanged with other items. Other examples of non-fungible items are your driving licence, your college degree, a piece of art etc._

**_ERC1155_** :
- This standard is used to implement functionalities of both fungible and non-fungible tokens. It can also be called a standard for semi-fungible tokens. For example, multiple editions of a song or photographs.

_Ex: When you attend a concert, you can buy a General pass, VIP pass, Multi-day pass and so on. If you hold a general pass, you can exchange your pass with someone holding a general pass but not with someone holding a VIP pass. Hence, such items are a mixture of fungible and non-fungible. Different categories of passes are non-fungible, but the passes within the same category are fungible. Other examples being shares of different companies, metro tickets for different destinations etc._